Get multiple values in a select statement in a variable to a procedure

Hello

I'm trying to craete a procedure where the entry of the procedure will be a similar string "a, b, c, d" and output the values of a table that matches the value separated by commas of in sting.

For this.

create table test (varchar2 (10)) nm;

Insert test values ('a');

Insert test values ('b');

Insert test values ('c');

Insert test values (');

Select * from test;

NM

------

one

b

c

d

Now I'm doing a procedure where the parameter will be the column values NM of TEST table in a string separated by commas like "a, b, c, d, x, l" there could be false values also.

The procedure will return only the values that are adapted with column NM from the TEST table for this I created this procedure.

create or replace procedure p_test (p_nm IN varchar2 / *, THE sys_refcursor p_out * /)

is

number of l_len;

l_val varchar2 (10);

l_val1 varchar2 (10);

Start

l_len: = length (p_nm);

-dbms_output.put_line (l_len);

Start

because me in 1.l_len

loop

Select REGEXP_SUBSTR (p_nm, ' ([^,] *)(,|$)', 1, I, NULL, 1) in double l_val;

-dbms_output.put_line (l_val);

-Open p_out for

Select * into l_val1 of test where nm = l_val;

dbms_output.put_line (l_val1);

output when l_len is null;

end loop;

exception

When no_data_found then

null;

end;

exception

while others then

dbms_output.put_line (' error reason :'||) SQLERRM |' :'|| error code SQLCODE);

end;

EXECUTE p_test ('a, b, c, d, q, w');

OUTPUT-

one

b

c

d

This procedure gives me out as I need, but I need to get this in a variable which should be OUT the parameter of this procedure will be called by the JAVA for our application.

As I already tried to use the refcursor (see the commented part), but it gives me no output during a call there.

Its a call to this procedure when I use the refcursor (removing comments).

declare

l_out sys_refcursor;

l_val varchar2 (20);

l_str varchar2 (20): = 'a, b, c, d;

Start

p_test (l_str, l_out);

loop

extract the l_out in l_val;

dbms_output.put_line (l_val);

dbms_output.put_line ('a');

When the output l_out % notfound;

end loop;

end;

So here I am stuck with that, how to get the result of multiple or I'm missing something here and if there is a better approach to this requirement as I come with that so I'm sharing it here.

OR if someone can tell me what is the problem with this package-

create or replace package p_test_api

is

type t_rec is rendered (name varchar2 (200));

type t_tab is table of index by pls_integer t_rec;

procedure p_pest_proc (p_nm in varchar2, p_out to t_tab);

end p_test_api;

/

create or replace package body p_test_api

is

procedure p_pest_proc (p_nm in varchar2, p_out to t_tab)

is

number of l_len;

l_val varchar2 (10);

l_val1 varchar2 (10);

Start

l_len: = length (p_nm);

Start

because me in 1.l_len

loop

Select REGEXP_SUBSTR (p_nm, ' ([^,] *)(,|$)', 1, I, NULL, 1) in double l_val;

dbms_output.put_line (l_val);

Select * bulk collect into p_out test where nm = l_val;

output when l_len is null;

end loop;

exception

When no_data_found then

null;

end;

exception

while others then

dbms_output.put_line (' error reason :'||) SQLERRM |' :'|| error code SQLCODE);

end p_pest_proc;

end p_test_api;

CALL THIS PACKAGE-

declare

l_out p_test_api.t_tab;

l_str varchar2 (20): = 'a, b, c, d;

Start

P_TEST_API. P_PEST_PROC (l_str, l_out);

dbms_output.put_line ('b');

because me in 1.l_out.count

loop

dbms_output.put_line ('a');

dbms_output.put_line (l_out (i). (Name)

dbms_output.put_line ('a');

When the output l_out.count = 0;

end loop;

dbms_output.put_line ('a');

end;

It won't loop

I am using-

Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

Thank you

First of all, get rid of it WHEN OTHERS like William already noted. If you do not want to use the collections:

SQL > create or replace
function f_test () 2
3 p_nm varchar2
4                  )
5 return varchar2
6 is
v_result 7 varchar2 (4000);
Start 8
9. Select listagg (nm, ',') within the Group (nm control)
10 in v_result
11 test
where the 12 «,» | p_nm | ',' like '%', | NM | ',%';
13 return v_result;
14 end;
15.

The function is created.

SQL > start
2 dbms_output.put_line (f_test ('a, b, c, d, x, w'));
3 end;
4.
a, b, c and d

PL/SQL procedure successfully completed.

SQL >

SY.

Tags: Database

Similar Questions

  • get the values of the selected items to RichSelectManyChoice

    Hi all

    I have a RichSelectManyChoice

    When the user clicks on the "submit" button I want to get the values of the selected items...


    ----------------------------------------------------------page.jspx-----------------------------------------------------------------------------

    <? XML version = "1.0" encoding = "UTF - 8"? >

    " < = xmlns:jsp jsp:root ' http://Java.Sun.com/JSP/page "version ="2.1"xmlns:f =" " http://Java.Sun.com/JSF/core "

    ' xmlns:af = ' http://xmlns.Oracle.com/ADF/faces/rich "> "

    < jsp:directive.page contentType = text/html"; Charset = UTF - 8 "/ >

    < f: view >

    < af:document title = "untitled1.jspx" id = "d1" > "

    < af:messages id = "m1" / >

    < af:form id = "f1" >

    < af:panelGridLayout id = "pgl1" >

    < af:gridRow height = "100%" id = "gr1" >

    < af:gridCell width = '100% ' halign = "stretch" valign = "stretch" id = "gc1" >

    <! - content - >

    < af:selectManyChoice value = "#{bindings." CountriesView1.inputValue}.

    label = "#{bindings." CountriesView1.label}"id ="smc1.

    valuePassThru Binding = "#{suspect." Country}"="true">

    < f: selectItems value = "#{bindings." CountriesView1.items}"id ="si1"/ >

    < f: validator binding = "#{bindings." CountriesView1.validator} "/ >"

    < / af:selectManyChoice >

    < / af:gridCell >

    < / af:gridRow >

    < / af:panelGridLayout >

    < text af:button = "Button 1" id = "b1" action = "#{suspect.valide}" / >

    < / af:form >

    < / af:document >

    < / f: view >

    < / jsp:root >

    ---------------------------------------------------------------------------------------------------------------------------------------

    --------------------------------------------------------------------suspect.java-------------------------------------------------------------------

    package test.view;

    import com.sun.org.apache.xpath.internal.operations.String;

    Import oracle.adf.view.rich.component.rich.input.RichSelectManyChoice;

    public class suspect {}

    RichSelectManyChoice campaign private;

    String string = null;

    public suspect() {}

    ????????????????????????????????????????

    }

    public void valide() {}

    }

    {} public void setCountry (RichSelectManyChoice country)

    This.Country = country;

    }

    public RichSelectManyChoice {} getCountry()

    back country;

    }

    }

    ---------------------------------------------------------------------------------------------------------------------------------------------------------


    Anyone has an idea please?

    Hello

    You can use

    JUCtrlListBinding listBindings = (JUCtrlListBinding) getBindings () .get ("CountriesView1");

    Object [] str = listBindings.getSelectedValues ();

    for (int i = 0; i)< str.length;="" i++)="">

    System.out.println (STR [i]);

    }

    in this loop, you will get all the values of selectManyChoice, for details see Ashish Awasthi (Jdev/ADF) Blog: using the selection Multiple (component selectManyListbox & selectManyCheckbox) in ADF

    hope it helps

  • How to use Ajax get multiple values in an array?

    Hi All-

    I am using AJAX to get multiple values in a table using example of Denes Kubicek in the following link-

    http://apex.oracle.com/pls/otn/f?p=31517:239:9172467565606:NO:

    Basically, I want to use the drop-down list to fill the rest of the values in the form.

    I created the example (Ajax get several values, 54522 application) on the Oracle site.

    http://apex.oracle.com/pls/apex/f?p=4550:1:0:

    Workspace: iConnect

    Login: demo

    password: demo

    I was able to reproduce his example on page 1 (homepage).

    However, I want to use system generate a table to complete this example and was not able to complete the data correctly.

    Page 2 (method 2) is that I'm struggling to fill the column values. When I checked the item application values in the Session, and values seems to be filled properly.

    That's what I did on this page:

    1 create an Application process on-demand - Set_Multi_Items_Tabular2:

    DECLARE
      v_subject my_book_store.subject%TYPE;
      v_price my_book_store.price%TYPE;
      v_author my_book_store.author%TYPE;
      v_qty NUMBER;
    
      CURSOR cur_c
      IS
      SELECT subject, price, author, 1 qty
      FROM my_book_store
      WHERE book_id = :temporary_application_item2;
    BEGIN
      FOR c IN cur_c
      LOOP
      v_subject := c.subject;
      v_price := c.price;
      v_author := c.author;
      v_qty := c.qty;
      END LOOP;
    
      OWA_UTIL.mime_header ('text/xml', FALSE);
      HTP.p ('Cache-Control: no-cache');
      HTP.p ('Pragma: no-cache');
      OWA_UTIL.http_header_close;
      HTP.prn ('<body>');
      HTP.prn ('<desc>this xml genericly sets multiple items</desc>');
      HTP.prn ('<item id="f04_' || :t_rownum || '">' || v_subject || '</item>');
      HTP.prn ('<item id="f05_' || :t_rownum || '">' || v_price || '</item>');
      HTP.prn ('<item id="f06_' || :t_rownum || '">' || v_author || '</item>');
      HTP.prn ('<item id="f07_' || :t_rownum || '">' || v_qty || '</item>');
      HTP.prn ('</body>');
    END;
    
    
    
    
    
    

    2. create two objects application - TEMPORARY_APPLICATION_ITEM2, T_ROWNUM2

    3. put the following text in the Page header:

    <script language="JavaScript" type="text/javascript">
    function f_set_multi_items_tabular2(pValue, pRow){
        var get = new htmldb_Get(null,html_GetElement('pFlowId').value,
    'APPLICATION_PROCESS=Set_Multi_Items_Tabular2',0);
    if(pValue){
    get.add('TEMPORARY_APPLICATION_ITEM2',pValue)
    get.add('T_ROWNUM2',pRow)
    }else{
    get.add('TEMPORARY_APPLICATION_ITEM2','null')
    }
        gReturn = get.get('XML');
        if(gReturn){
            var l_Count = gReturn.getElementsByTagName("item").length;
            for(var i = 0;i<l_Count;i++){
                var l_Opt_Xml = gReturn.getElementsByTagName("item")[i];
                var l_ID = l_Opt_Xml.getAttribute('id');
                var l_El = html_GetElement(l_ID);    
                if(l_Opt_Xml.firstChild){
                    var l_Value = l_Opt_Xml.firstChild.nodeValue;
                }else{
                    var l_Value = '';
                }
                if(l_El){
                    if(l_El.tagName == 'INPUT'){
                        l_El.value = l_Value;
                    }else if(l_El.tagName == 'SPAN' && l_El.className == 'grabber'){
                        l_El.parentNode.innerHTML = l_Value;
                        l_El.parentNode.id = l_ID;
                    }else{
                        l_El.innerHTML = l_Value;
                    }
                }
            }
        }
        get = null;
    }
    </script>
    
    
    Add the follwing to the end of the above JavaScript:
    
    <script language="JavaScript" type="text/javascript">
    function setLOV(filter, list2)
    {
     var s = filter.id;
     var item = s.substring(3,8);
     var field2 = list2 + item;
     
     f_set_multi_items_tabular2(filter, field2);
    }
    
    
    
    
     
    
    
    

    4 query in the form:

    select
    "BOOK_ID",
    "BOOK",
    "SUBJECT",
    "PRICE",
    "AUTHOR",
    "QTY",
    "BOOK_ID" BOOK_ID_DISPLAY
    from "#OWNER#"."MY_BOOK_STORE"
    
    
    
    
    
    

    5. in the column of Book_ID_DISPLAY attribute:

    Add the following code to the attributes of the element: onchange = "javascript:f_set_multi_items_tabular2(this.value,'#ROWNUM#'); »

    Changed-> onchange = "javascript:setLOV(this,'f03'); »

    Now, T_ROWNUM2 returns the value as f03_0001. But TEMPORARY_APPLICATION_ITEM2 returns in the form [object HTMLSelectElement]...

    Please help me to see how I can fill the data in the tabular presentation format. Thank you in advance!

    Ling

    Updating code in red...

    Ling

    LC says:

    Application Item Value Item Name
    54522 3 TEMPORARY_APPLICATION_ITEM2
    54522 f03_0003 T_ROWNUM2

    No T_ROWNUM2 should be 0003.

    I made a copy of your page to make corrections.

    There are several problems.

    First you where submiting T_ROWNUM2 whereas you would use: t_rownum in the pl/sql code.

    I changed the name of the element in the f_set_multi_items_tabular2.

    Secondly you where now affecting the rownumber f03_0001 for the first line.

    Resulting XML returned as follows.

    this xml genericly sets multiple items
    CSS Mastery
    22
    Andy Budd
    1
    
    

    I changed the following text in the show_lov.

    var point = s.substring (4.8);

    var Field2 = item;

    I also had a compilation of pl/sql code error, there was a); missing the end of the last item. Fixed that too.

    But why do you think lpad won't work for lines 10 and more.

    LPAD ('10', 4, '0') will give "0010"

    LPAD ('100 ', 4,'0 ') will give "0100"

    LPAD ('1000 ', 4,'0 ') will give '1000'

    So unless you have more than 9999 lines you would have no problem.

    Nicolette

  • How to use the Type of Oracle Table values in the Select statement.

    Hello

    I get the initial set of values in the Table of Type Records of the Oracle and want to use the list of values in the Select statement.

    For example, try something like the following:

    TYPE t_record () IS RENDERING
    ID TABLEA.ID%type,
    NO TABLEA.NO%type

    );
    v_record t_record;
    T_table TYPE IS the v_record TABLE % TYPE;
    v_table t_table;

    -Code to fill the values of v_table here.

    SELECT ID, NO, COLLECT in BULK IN < some other table variabes here > FROM TABLEA
    WHERE ID IN (i) v_table USER.USER;

    I want to know how to use the Type of Oracle Table values in the Select statement.

    Something like this:

    create or replace type t_record as  object (
    id number,
    no number
    )
    /
    
    CREATE or replace type t_table AS TABLE OF t_record;
    /
    
    set serveroutput on
    declare
    
      v_table t_table := t_table();
      v_t1 t_table := t_table();
    
    begin
    
      v_table.extend(1);
      v_table(1).ID := 1;
      v_table(1).No := 10;
    
      v_table.extend(1);
      v_table(2).ID := 2;
      v_table(2).ID := 20;
    
      SELEC t_record (ID,NO) BULK COLLECT INTO v_t1
      from TableA
      FROM TABLEA
      WHERE ID IN (select t.ID from table(v_Table) t);
    
      for i in 1..v_t1.count loop
        dbms_output.put_line(v_t1(i).ID);
        dbms_output.put_line(v_t1(i).No);
      end loop;
    end;
    /
    

    No test!

    P;

    Published by: bluefrog on March 5, 2010 17:08

  • ListView MAF 2.1 how to get the value of line selection

    Hi all

    I'm trying to get the select line of a page with a listview amx

    to pass values of line as a parameter to the detail page

    which to get data from web service, but with links

    I always get the first value in the line of my list view.

    How can I refresh the values?

    Is - this java is better than the binding for this case?

    Can you help me please?

    Thanks for your help

    You can set the value of the selected line in a variable pageFlowScope and pass it to the method on the next page.

    Something similar to this:

    https://blogs.Oracle.com/Shay/entry/adf_mobile_update_through_web

  • Cannot get the value of the selection of OAMessageChoiceBean

    Hello

    Of our 11i to R12 upgrade, in the customer's advanced search page, we are unable to get the handle suitable for OAMessageChoiceBean (in extendedCO).

    The snippet for the bean handling is as follows:

    OAMessageChoiceBean PartyStatusFilter = (OAMessageChoiceBean) vOAPageContext.getRootWebBean () .findChildRecursive ("xxfeF426PartySearchStatus");
    String xxTest = PartyStatusFilter.getSelectionValue (vOAPageContext);

    The value of the above xxTest (in R12 approx.) is coming with a null value. Considering that the same code works in 11i environment and the xxTest output = "A".

    So we cannot get the value of the selection of the messagechoicebean in our environment of R12. I already looked in previous similar positions in this forum, also tried to use getSelectionText (vOAPageContext) or getSelectedValue(), however, it did not work.

    Pointers please?

    Thank you very much
    Zahid

    Hi Zahid,

    Try with this ID = HzPuiPartyStatus

    -Had

  • How to get the value of a selected character unicode?

    Hi all

    How to get the value of a selected character unicode?

    The content property of a 'Character' InDesign object is a simple Unicode string. For access to the various characters is a basic javascript operation, and a google gives this as a good first result: http://www.w3schools.com/jsref/jsref_charCodeAt.asp

    Therefore, the value of a selected character unicode is

    App.Selection [0]. Characters [0].contents.charCodeAt (0)

  • get the value of a selection list

    I made a request and on a page, I have a selection list filled from a list of values (made with a sql statement select).
    on the same page, I have a report made after a select statement.

    How can I did... when I select an item in the selection list in the report show me the item that is selected in the select list

    example:
    Select list: select name of EMP

    List of reports:
    Select * from emp;

    When I click on the selection list and chose a name of the employee in the report show me the first name, middle name, address and everything in emp.

    I tried to use emp.name = 'selectlist.value' and it gives me the invalid number.
    tried with the selection list with submit but still without work.

    can someone give me an ideea? How the current value of the selection list can be put in select condition of a statement or something to do all this?

    Thank you

    E-mail: [email protected]
    name: Andrei


    a quick description

    Page rendering
    Regions
    Point of view: Page (1) template body

    * Report: emp (10)

    Display: Position of the region 01

    * HTML: EMP1 (20)
    * Report: search (30)

    Elements
    Region: research

    * 10: P4_X select list


    Lists of values

    * EMP_name



    is an element of the region of report research.
    search source report is select name, address from emp;
    and the list of values is select name from emp;

    Andrei,

    Change your selection of P4_X list and make a list of selection with Submit. Now edit the report in the form query

    SELECT name, first name, address of the emp, whose name is nvl(:P4_X,name);

    I hope this helps.

    Thank you
    Manish

  • Get the value in the selection of message

    I need to read a value from a choice of message and when a button is clicked an event is triggered.

    I've coded this way but I can't get the value of the choice of the message.

    If (("ApplyBTN".equals (source)) & & (!)) » ». {Equals (source)))}

    OAMessageChoiceBean = dropDownAction

    WebBean.findChildRecursive ("DropDownList") (OAMessageChoiceBean);

    String valueSelected = dropDownAction.getSelectionText (pageContext);

    String valueSelected1 = (String) dropDownAction.getValue (pageContext);

    System.out.println ("valueSelected" + valueSelected);

    System.out.println ("valueSelected1" + valueSelected1);

    }

    Varun,

    In addition, for the choice of message, you can try the options below:

    1 try this code:

    String selValue = (String)pageContext.getParameter("DropDownList");
    

    2. for a choice of message, you need not specify pickListViewDef and pickListViewName. So just delete the pickListViewName.

    
    

    3. is there a particular reason that you have associated with the View object for this? If you do not need this to eliminate viewName and viewAttr also.

    
    

    See you soon

    AJ

  • How to get the value of the selection of the text box list

    Hello

    I have a selection list that I want to retrieve the value of the selection of the text box list.

    How can I do this?


    Kind regards
    Santini.

    Hi Sarah,.

    Yo can use Java script for this...

    Dynamically the value will enter in the text box.

    Use the script below.

    
    

    See you soon,.
    Shan

  • How to add an imaginary line in the result of the value of a SELECT statement.

    Hello all-

    I have requirment to add an imaginary line in the result set of a SELECT statement.

    For example lets say it is a pay table having the following columns:

    Number of Payment_id
    status varchar2 (10)
    number amount
    date of payment_date

    so here's the data: -.

    Payment_id status amount payment_date
    applied 1 100 12/07/2008
    2 Reversed 200 01 / 06/2009
    Applied 3 300 01 / 07/2009


    Here is my SQL

    Select * form payment where payment_date > = 01/01/2009

    The output will be

    2 Reversed 200 01 / 06/2009
    Applied 3 300 01 / 07/2009

    My desired output is less than

    2 Reversed 200 01 / 06/2009
    Applied 3 300 01 / 07/2009
    reversed-200 2, 01 / 06/2009-(Dummy Row)

    Third line here is the imaginary line that I add when the status is "reversed".

    I would be very grateful for any help on this...

    Thank you
    Gerard

    Cartesion join against a shadow table is a useful method to create a fictitious line:

    with my_tab as (select 1 cust_id, 1 Payment_id, 'Applied' Status, 100 Amount, to_date('12/07/2008', 'mm/dd/yyyy') payment_date from dual union all
                    select 1 cust_id, 2 Payment_id, 'Reversed' Status, 200 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 1 cust_id, 3 Payment_id, 'Applied' Status, 300 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 1 Payment_id, 'Applied' Status, 100 Amount, to_date('12/07/2008', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 2 Payment_id, 'Reversed' Status, 200 Amount, to_date('01/05/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 3 Payment_id, 'Applied' Status, 300 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 4 Payment_id, 'Reversed' Status, -400 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 5 Payment_id, 'Applied' Status, 500 Amount, to_date('01/07/2009', 'mm/dd/yyyy') payment_date from dual),
                    --- end of mimicking your table
          dummy as (select 'Reversed' col1, 1 rn from dual union all
                    select 'Reversed' col1, 2 rn from dual)
    select mt.cust_id,
           mt.payment_id,
           mt.status,
           decode(dummy.rn, 2, -1*mt.amount, mt.amount) amount,
           mt.payment_date
    from   my_tab mt,
           dummy
    where  mt.status = dummy.col1 (+)
    order by mt.cust_id, mt.payment_id, dummy.rn nulls first;
    
    CUST_ID     PAYMENT_ID     STATUS     AMOUNT     PAYMENT_DATE
    1     1     Applied     100     07/12/2008
    1     2     Reversed     200     06/01/2009
    1     2     Reversed     -200     06/01/2009
    1     3     Applied     300     06/01/2009
    2     1     Applied     100     07/12/2008
    2     2     Reversed     200     05/01/2009
    2     2     Reversed     -200     05/01/2009
    2     3     Applied     300     06/01/2009
    2     4     Reversed     -400     06/01/2009
    2     4     Reversed     400     06/01/2009
    2     5     Applied     500     07/01/2009
    

    Published by: Boneist on January 7, 2009 23:10
    NB. You may need to mess around with the order if that is not in the order you want. You did not mention what the rules were for all orders expected, so I composed my own * {;-)

    Also, I added a (cust_id) identifier to differentiate different types of payments, as is usually the case. Remove unless it is not applicable to your case.

  • SQL SELECT statement as a parameter in the procedure of string

    Hi all

    I'm new to PL/SQL and I must get a procedure as parameter select SQL select statement as a VARCHAR and the production output the result of the statement with a few changes. Can someone help me solve this problem?

    A possibility I thought at was to use a REF CURSOR. The following example works but binds me to a specific table (in the example of the "customers" table). However, I need the ability to specify arbitrary tables in the select statement parameter.
    SET SERVEROUTPUT ON
    DECLARE
      TYPE my_cur IS REF CURSOR;
      query_cursor my_cur;
    BEGIN
      OPEN query_cursor FOR 'SELECT * FROM customers';
      DECLARE
        record_type customers%ROWTYPE;
      BEGIN
         LOOP
            FETCH query_cursor INTO record_type;
            EXIT WHEN query_cursor%NOTFOUND;
            DBMS_OUTPUT.PUT_LINE('some output ... ');
         END LOOP;
      END;
      CLOSE query_cursor;
    END;
    /
    My idea was to modify this example to work in the following code, but it does not work (I get a compile error):
    SET SERVEROUTPUT ON
    DECLARE
      TYPE my_cur IS REF CURSOR;
      query_cursor my_cur;
    BEGIN
    
      OPEN query_cursor FOR 'SELECT * FROM customers';
    
      DECLARE
        record_type query_cursor%ROWTYPE;
      BEGIN
         LOOP
            FETCH query_cursor INTO record_type;
            EXIT WHEN query_cursor%NOTFOUND;
            DBMS_OUTPUT.PUT_LINE('some output ... ');
         END LOOP;
      END;
      
      CLOSE query_cursor;
    
    END;
    /
    Does anyone has an idea how can I solve my problem?

    Thank you very much!
    (I'm using Oracle 11 g)

    This can help.
    Re: Dynamic Extraction on dynamic Sql

  • provide multiple values to the select query IN

    Hello

    I just wanted to know if there is a more effective way to provide values for my statement SELECT. Is what we do, gives us an excel file that contains a single column of serial numbers then we format the content so that it can be read by pl sql. By format, I mean put single quotes on the serial numbers, then separate then by comma.

    Like, we are sent

    8181818181818
    2323123525241
    1231231231234

    Then we have to get in shape to look like this (using formulas in excel)

    '8181818181818',
    '2323123525241',
    '1231231231234'

    in the process, I have to do a lot of copy and pasting that seems to take a long time.

    So, is there a way to make the process of sql pl serial passed to me as an excel file or is there any other alternative methods can I use?

    TABLE EXTERNAL research

  • To parse a string value in a Select statement by using features of characters

    I need to put a single space between the last number and the first character in a string. These channels will always begin with a number. For example, the string can be:
    555B11#1A MAIN ST.
    I have to return the following:
    555 B11#1A MAIN ST.
    Note the space after the 555 and before the B. The rest of the chain must remain the same. Is it possible is a Select SQL statement, using the features of character?

    Any help would be greatly appreciated.

    Sharpe says:
    Indeed, it works. Thank you!

    1  SELECT REGEXP_REPLACE ('555B11#1A MAIN ST.', '([[:digit:]])([[:alpha:]])', '\1 \2', 1, 1)     AS
    2* FROM    dual
    SQL> /
    
    NEW_ADDR
    -------------------
    555 B11#1A MAIN ST.
    
    SQL>
    {code)
    
    Can you help me understand what the pattern parameter '([[:digit:]])([[:alpha:]])' means and what it is doing exactly?  
    

    Sure. I was waiting to see if that expression really worked on your complete data before explaining. An explanation of the code that works is more generally more instructive than an explanation of the code that does not work, and you will only need to maintain code that works.

    [[: digit:]] means just that: all the digits ' 0 'to 9'. I could have used \d, as Solomon has done.
    [[: alpha:]] means any alphabetical character. You want to just insert a space, when a digit is immmdiately letter, followed by one on the right? In other words, if there is already a space after the first group of numbers, I guess that you do not want to add another space.

    And that means parameter replacement '\1 \2' and what he does exactly?

    Put the expressions inside parentheses above allows to refer to the exact substring match using Backreferences . The backreference \1 refers to the part of the pattern that starts with 1 ' ('. left \2 backreference refers to the alternative ground that begins with the 2nd '('. gauche Dans l'exemple, vous avez donné, le patron de (digit) (letter) which was first a '5 b', then '\1' means '5' and '\2' is 'B'.))
    Thus, the 2nd argument says "seek a model made up molasses maximum figure, followed immediately by a letter".
    The 3rd argument says 'replace this template with the same number you found, then a space, then the same letter you have found'.
    The 5th argument said only change the 1st occurrence of the pattern. The default is to change each of them, but that would have changed 1 'a' to ' 1' later in the string, and you said that you didn't want that.
    The 4th argument is the default value; We do not have ' really need, except that we cannot pass the 5th argument without passing the argument 4th in front of her (at least not in the versions of Oracle that I use).

  • Set the first value after the select statement

    Hello

    I have a problem here.

    After you run the statement select, it'll come to me:

    COM
    DLY
    EXC
    NRD
    RDY



    My question: How can I set the first value instead of 'COM' in "EXC"?

    Thank you.

    Hello
    Where you use this instead:

    select *
    from
    (
    select col_name
    ,case when col_name='EXC' then 1 else 0 end as "id"
    from table_name
    )
    order by "id" desc
    

Maybe you are looking for