Dynamic SQL query returning (problem with list of value)

Hi, I have problems with my request. I want to do where statement based on my selectlist, but the problem is that I could not write the correct string in my where condition.

: P61_STATUS has this following display, return value

Bewerber Bewerber
PRA_Kandidat PRA_Kandidat
abgelehnt abgelehnt
angenommen angenommen
Thema-Thema
join online
Staaten Staaten
Sky sky
our our
DECLARE
  q varchar2(4000);
  list_betreuer htmldb_application_global.vc_arr2;
  list_semester htmldb_application_global.vc_arr2;
  list_status htmldb_application_global.vc_arr2;

BEGIN

 -- variable to store the list
 list_betreuer := HTMLDB_UTIL.STRING_TO_TABLE(:P61_BETREUER);
 list_semester := HTMLDB_UTIL.STRING_TO_TABLE(:P61_SEMESTER);
 list_status := HTMLDB_UTIL.STRING_TO_TABLE(:P61_STATUS);

 -- Query begins
 q:= 'select p1.name, p1.vorname , a1.tel, a2.tel, '; 
 q:= q||'ab.thema, ab.status, ab.typ, s.bezeichnung, p2.name ';
 
 q:= q||'from person p1, person p2, adresse a1, adresse a2, ';
 q:= q||'zuordnungp_a zpa1,zuordnungp_a zpa2, ';
 q:= q||'abschlussarbeit ab, semester s ';

 q:= q||'WHERE ab.SEMESTER = s.OBJECTID (+) ';
 q:= q||'AND ab.STUDENT = p1.OBJECTID (+) ';
 q:= q||'AND ab.BETREUER = p2.OBJECTID (+) ';

 q:= q||'and p1.objectid = zpa1.person (+) ';
 q:= q||'and zpa1.adresse  = a1.objectid (+) ';
 q:= q||'and zpa1.art (+)= ''Privat'' ';

 q:= q||'and p1.objectid = zpa2.person (+) ';
 q:= q||'and zpa2.adresse  = a2.objectid (+) ';
 q:= q||'and zpa2.art (+)= ''Geschäft'' ';


 -- Loop for betreuer list
 FOR i in 1..list_betreuer.count
 LOOP
    IF i = 1 THEN
    q:= q||'AND (ab.betreuer = '||list_betreuer(i);
    ELSE
    q:= q||' OR ab.betreuer  = '||list_betreuer(i);
    END IF;
 END LOOP; if (list_betreuer.count>0)THEN q:= q||')'; END IF;

  -- Loop for semester list
 FOR i in 1..list_semester.count
 LOOP
    IF i = 1 THEN
    q:= q||'AND (ab.semester = '||list_semester(i);
    ELSE
    q:= q||'OR ab.semester = '||list_semester(i);
    END IF;
 END LOOP; if (list_semester.count>0)THEN q:= q||')'; END IF;
 
 -- Loop for status list
 FOR i in 1..list_status.count
 LOOP
    IF i = 1 THEN
    q:= q||'AND (ab.status = '||list_status(i)||'';
    ELSE
    q:= q||'OR ab.status = '||list_status(i)||'';
    END IF;
 END LOOP; if (list_status.count>0)THEN q:= q||')'; END IF;
 
  htp.p(q);
 return q;
 
END;
result
select p1.name, p1.vorname , a1.tel, a2.tel, ab.thema, ab.status, ab.typ, s.bezeichnung, p2.name from person p1, person p2, adresse a1, adresse a2, zuordnungp_a zpa1,zuordnungp_a zpa2, abschlussarbeit ab, semester s WHERE ab.SEMESTER = s.OBJECTID (+) AND ab.STUDENT = p1.OBJECTID (+) AND ab.BETREUER = p2.OBJECTID (+) and p1.objectid = zpa1.person (+) and zpa1.adresse = a1.objectid (+) and zpa1.art (+)= 'Privat' and p1.objectid = zpa2.person (+) and zpa2.adresse = a2.objectid (+) and zpa2.art (+)= 'Geschäft' AND (ab.status = abgegeben) 
the problem is in this summary
q:= q||'AND (ab.status = '||list_status(i)||'';
This statement produce this following statement
ab.status = abgegeben
But what I need, is this statement
ab.status = 'abgegeben';
How can I get this statement?

Thank you very much

To use double quotes:

q:= q||'AND (ab.status = '''||list_status(i)||'''';

Tags: Database

Similar Questions

  • 'Function SQL Query return' using with Flash graphics

    I created a pl/sql function that returns a SQL query in a varchar2 of this form:

    Select the null link
    -value > < x value
    < value y of Series1 > series 1 label
    < value Series2 y > 2 series label
    < value of y Series3 > series 3 Label
    ...
    ...
    from tablea a
    Join tableb b
    On a.col = b.col
    order of < x value >

    If I call the function of a graphic Flash box series SQL with the Type of Source query "SQL query" value that returns the function like this:

    return functionname (to_date ('30-sep-2010, ' mon-dd-yyyy ""))

    It parses correctly and the page is saved; However, when I run the page I get no output - error messages or another indication of a problem.

    Now, if I call the function in a SQL client, capture the result of the query SQL using the dbms_output and paste that into the box graphic Flash series SQL - change the Source Type of SQL query query - and save the page it works fine when I run it and returns a chart series flash.

    Can anyone suggest either;

    1. what I might have missed or done wrong?
    2. a way to effectively diagnose the problem...

    I tried to use the debugger Apex - what is very nice, indeed - but it provides no information on what might be my problem. I tried to write my own my function debug messages using the apex_debug_message package - nothing...

    Thank you
    Eric

    Hi Eric,.

    Try to pull the source like this:

    begin
       return functionname(to_date('30-sep-2010', 'dd-mon-yyyy'));
    end;
    

    This works very well for me, and if I take the begin-end and the final semicolon from the return statement I get the same behavior as you.

    He doesn't mention in aid of the source (only during the wizard if) this source type must be expressed in this way, but I agree, it would be useful that the tool would validate to this format meets it "Query SQL that returns the function" or give some sort of indication of the sentence. In any case, this should help you will again.

    Hope this helps,
    John

    If you find this information useful, please do not forget to mark the 'useful' or 'correct' post so that others benefit as well.

  • problem with list of value (LOV) in the BI Publisher.

    I've created a report in the BI publisher with two parameters (level, accnum) and two list of value (LOV) for the menu to select from a drop-down list.
    While crateing the settings I selected options: * 1) can select all and any value passed *.
    but in the view when I select the option "ALL" in the list, its shows the following error message:
    ORA-00933: SQL not correctly completed command.

    But if I select a particular level and accnum is fine worikg.

    I used the following query in the dataset;

    Select ACCOUNT. ACCOUNT_NUM as ACCOUNT_NUM,
    ACCOUNT. LAST_BILL_DTM as LAST_BILL_DTM,
    ACCOUNT. Account_name as ACCOUNT_NAME,
    ACCOUNTATTRIBUTES. DISTRICT_ID as DISTRICT_ID,
    ACCOUNTATTRIBUTES. TIER as the LEVEL of
    of GEN_OWNER. ACCOUNTATTRIBUTES ACCOUNTATTRIBUTES,
    GEN_OWNER. ACCOUNT ACCOUNT
    where to REPRESENT them. ACCOUNT_NUM = ACCOUNTATTRIBUTES. ACCOUNT_NUM
    and ACCOUNTATTRIBUTES. LEVEL =: level
    and ACCOUNTATTRIBUTES. ACCOUNT_NUM =: accnum
    and ACCOUNTATTRIBUTES.ACCOUNT_NUM in (:accnum)
    

    use in the clause

  • Problem with list-of-values while using Oracle ATS

    All by registering a fact oracle application using Oracle ATS, whenever I click on a button LOV and select a value from the list, I am being disconnected from the application. Is this a common occurrence? Let me mention here that LOV works very well, it's only when recording with the ATS that I find this question.

    Could someone give me a solution to workaround with LOVs in ATS?

    --
    Thank you
    Yacoub

    Hello

    The LOV works very well in OATMEAL, I use EBS form it works fine, maybe there an installation problem. Alternatively, you can manually include LOV by action forms are trying.

    Kind regards
    Srinivas

  • Dynamic SQL query to get the unique value of list in a column

    I have two tables: tblWorkers and tblSkills. tblWorkers has a column, skills, which is populated by a field of multiple-checkbox with one or more skill_IDs of tblSkills, so each tblWorkers.Skills consists of a list of one or more comma-delimited values. For any Skill_ID, I need to generate a list of all workers with the appropriate skills, so I tried to do something in the direction of SELECT WorkerName FROM tblWorkers WHERE IN of skills (skills, #FORM. Skill_ID #)... or WHERE skills (ListFind (skills, #FORM. Skill_ID #))... etc.? My results (once I have had data type mismatches of the road) return all workers, not just those with the desired skills. There must be an easy way to do... How people with a little more experience CF/SQL I do this?

    > each tblWorkers.Skills consists of a list of one or more comma-delimited values

    This is your problem. You store a list of values that you want to access power/query separately in a single column. You will have to burst in a separate table.
    TblWorkers

    TblSkills

    TblWorkerSkills
    mapping table of many workers with skills.

    If you do not change your data model now, you will constantly be butting your head against that.

  • A difficult dynamic SQL query problem

    Hi all

    I have a very interesting problem to work:

    We have this special table defined as follows:

    CREATE TABLE sales_data)
    sales_id NUMBER,
    NUMBER of sales_m01
    NUMBER of sales_m02
    NUMBER of sales_m03
    NUMBER of sales_m04
    NUMBER of sales_m05
    NUMBER of sales_m06
    NUMBER of sales_m07
    NUMBER of sales_m08
    NUMBER of sales_m09
    NUMBER of sales_m10
    NUMBER of sales_m11
    NUMBER of sales_m12
    sales_prior_yr NUMBER);
    /

    Columns ' sales_m01... sales_m12' represents aggregated monthly sales, what "sales_m01" is translated by "sales for the month of January, January is the first month,"sales_m02"in sales for the month of February and so on.»

    The problem I encounter is that we have a project that requires that a parameter is passed to a stored procedure that represents the number of months which is then used to create a SQL query with aggregations of next mandatory field, which depends on the parameter passed:

    Example 1: entry of parameter: 4
    Should be built dynamically to SQL query:

    SELECT
    Sum (sales_m04) as CURRENT_SALES,
    Sum (sales_m01 + sales_m02 + sales_m03 + sales_m04) SALES_YTD
    Of
    sales_data
    WHERE
    sales_id = '0599768';

    Example 2: input parameter: 8
    Should be built dynamically to SQL query:

    SELECT
    Sum (sales_m08) as CURRENT_SALES,
    SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04 +)
    sales_m05 + sales_m06 + sales_m07 + sales_m08) SALES_YTD
    Of
    sales_data
    WHERE
    sales_id = '0599768';


    So in a sense, the contents of SUM(sales_m01...n) would vary according to the parameter, which must be a number between 1... 12 what is a month, which in turn corresponds to a range of real field on the table itself. The resulting dynamic query should include only those columns/fields in the table that is within the range given by the input parameter and does not account for all the other columns/fields.

    Any solution is greatly appreciated.

    Thank you.
    SQL> declare
      cols long;
      param integer := 6;
      sales_id integer := 0599768;
    begin
      for i in 1..param loop
        cols := cols || 'sales_m' || to_char(i, 'fm00') || '+';
      end loop;
    
      dbms_output.put_line('select sum(sales_m'||to_char(param,'fm00')||') current_sales, sum(' || rtrim(cols,'+') || ') sales_ytd from sales_data WHERE sales_id = :1');
    end;
    /
    select sum(sales_m06) current_sales, sum(sales_m01+sales_m02+sales_m03+sales_m04+sales_m05+sales_m06) sales_ytd from sales_data WHERE sales_id = :1
    PL/SQL procedure successfully completed.
    

    Now it should be obvious:
    Instead of dbms_output OPEN a refcursor:

    SQL> declare
      cols long;
      param integer := 6;
      sales_id integer := 0599768;
      cur sys_refcursor;
    begin
      for i in 1..param loop
        cols := cols || 'sales_m' || to_char(i, 'fm00') || ',';
      end loop;
    
      open cur for 'select sum(sales_m'||to_char(param,'fm00')||') current_sales, sum(' || rtrim(cols,',') || ') sales_ytd from sales_data WHERE sales_id = :1' using sales_id;
      .....
    end;
    /
    

    Published by: michaels2 on July 26, 2009 09:49

    replaced ',' with ' + '.

  • Problem creating list of values query

    Hi all

    I am facing some problem with a simple list of Apex selection list item values query which is:

    RETURN 'select distinct dd_type as d, dd_type as r
    from portal_02.WAVE_'||:P86_WAVE_ID||' @ DATABASE_LINK1 
    order by 1';
    

    And I get this error during the execution of the page:

    ORA-06550: line 2, column 99: PL/SQL: ORA-00942: there is no ORA-00942 table or view: table or view is no ORA-02063: preceding the line of DATABASE_LINK1 ORA-06550: line 1, column 13: PL/SQL: SQL statement ignored ORA-00942: table or view is no ORA-02063: preceding the line of DATABASE_LINK1


    I placed also p86_wave_id cascading of parent elements.

    Anyone has an idea why this is happening and how can I fix this problem?

    Use: Apex 4.2.6 & Database 11g.

    Concerning

    Nabila

    I was wrong.

    You are positive that a value exists in the session state for P86_WAVE_ID? For your first attempt, one might think it was empty when loading the page, when he made everything that uses the list?

    Ahh, there you get this when you try to save the definition of LOV, it is probably just trying to validate the request, made with a null value.

    Not sure if you can get it to analyze at run time, but you could workaround with a wave_ object definition?

  • Dynamic SQL query in the DB adapter

    Hello
    I want to use the following custom SQL query in the DB adapter:

    SELECT EMP_ID, EMP_NAME, EMP_LOCATION FROM EMP WHERE EMP_ID IN (#iNPUT_PARAMETER)

    the problem I'm facing is that I don't know at the time of the development that EMP_ID how much will be passed to the process so that I can not use the input parameter specific number. I cannot use it IN the query within which statement I concatenate all the EMP_ID separated by comma and passed under INPUT_PARAMETER, but when running, he read the full concatenated string as a single string rather than identify them as a list of different: with comma separation. could someone help me in this case

    Thank you
    Sunil

    Use the following query with two parameters. Build the string with delimiter when running and pass this string and delimiter to query... (in this example, the input value would be the same for both Delimiter1 and Delimiter2.)

    Select * from EMP WHERE deptno IN (SELECT SUBSTR (STRING_TO_TOKENIZE, DECODE (LEVEL, 1, 1, INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL-1) + 1), INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL)-DECODE (LEVEL, 1, 1, INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL-1) + 1)) FROM (SELECT #StringToTokenizer | #Delimiter1 AS STRING_TO_TOKENIZE, #Delimiter2 AS DELIMITER FROM DUAL) CONNECT BY INSTR (STRING_TO_TOKENIZE SEPARATOR) ((, 1, LEVEL) > 0)

    Thank you
    -Sreeny

  • PL/SQL Query return function, adding the column links

    Hi all

    I'm working on a SQL report with the area type = function from PL/SQL Query to return
    All columns are generated dynamically based on my mapping table and a column of ID.
    So whenever the page is loaded, according to the ID mapping table returns a set of columns in a particular order.
    So not only the columns are dynamic, but the order of the columns varies also.
    But the first 1 column is standard (it doesn't come from the mapping table) and is coded in my pl/sql block hard.

    I'm fighting with the addition of a link to this column. The link must be a Javascript function which takes the parameters in the form of 2 columns in the mapping table.
    My pl/sql block is something like that...
    v_select := 'SELECT <g href=javascript:f_report1(#map_id#,#comments#)><img src=""></a> as report1, ';  // g=a
    v_cols := 'contains all columns from the mapping table based on a ID(hidden item)';
    v_from := 'FROM table';
    v_where := 'where condition is put in here';
    v_query := v_select||v_from||v_where;
    return v_query;
    Now, I'm not able to transmit the values of this #map_id # and #comments # correctly. I tried so many different combinations of channels, but could not make it work.

    I'm not sure that the order of this map_id and commentscolumn and therefore cannot connect through the report attributes.
    How can I go to a column value to the function?



    Thank you
    Dippy

    This should work if all goes well:

    v_select := q'[ SELECT '' as chart, ]';
    

    Published by: Dimitri Gielis on May 20, 2010 20:10

  • reload the page when SQL query returns a value

    Hello world

    the title of this discussion may seem strange, but I'll try to explain why I need this:

    A user has the ability to connect on my APEX application. There are several tabs in my application that are visible only if a certain SQL statement returns a value which is not the case by default. The user has also the ability to download a file that is transferred to an external system that analyzes the file and writes the data in the database. During this writing process - which may take several minutes - conditions for some of the tabs to show the will becomes real (-> the query will return a value). When the user refreshes the page manually, the tabs will be displayed. However, I want the tabs will appear automatically when the condition is met.

    Is it possible to refresh the page as soon as the query returns a value? It is perhaps possible to check it on the client side and trigger a refresh of the page when the condition is met. It would be even better if only the tabset has been updated, but refreshing the full page is fine as well.

    Thank you!

    Here is an overview of how it can be done

    This is possible thanks to a dynamic action being performed on a timer.

    View default tabs and dynamic action hide them on loading the page if they are not to be considered

    Create a dynamic action that will execute your query every 5 seconds or more

    If the query returns data, you can use the dynamic action to show your tabs using javascript

  • pl/sql - sql query return

    Hi all... I hope someone can help.
    Worked a lot to solve this problem, but I can't find a solution.
     
    DECLARE
         lv_sql VARCHAR(32767);
         lv_pivot_cols VARCHAR2(1000);
    BEGIN
         FOR i IN (SELECT DISTINCT comp_name, pro_name FROM  cat_attributes order by comp_name)
         LOOP
              lv_pivot_cols := lv_pivot_cols ||'('||''''||i.comp_name||''''||','|| '''' || i.pro_name ||''''||')'||',';
         END LOOP;
         lv_pivot_cols := RTRIM(lv_pivot_cols,',');
    
         lv_sql := 'SELECT * FROM
         (SELECT position,cat_id, att_name as ATTRIBUTE, pro_name, value,comp_name
         FROM   cat_attributes )
    PIVOT (
                        max (value)
                        FOR (comp_name,pro_name) IN (' ||lv_pivot_cols||')) where cat_id=:P1100_CHOOSE_CATEGORY order by position';
            
         RETURN lv_sql;                    
         --DBMS_OUTPUT.PUT_LINE(lv_sql);
    END;
    the code above works well, but I want to add a where condition in the separate statement, which depends on an element of the apex.
    as:
    SELECT DISTINCT comp_name, pro_name FROM  cat_attributes where  cat_id=:P1100_CHOOSE_CATEGORY order by comp_name 
    But if an add this condition got
    error report: ORA-01403: no data found
    any suggestions?


    I would also like to change the size of characters max column header. now, it may be only * 30 * characters for the column header. is there a possibility to raise it?

    Thanks for all your suggestions

    Hello

    Hmm. Is the value of ': P1100_CHOOSE_CATEGORY ' in Session State?

    In this case, would be the usual suspect: ": P1100_CHOOSE_CATEGORY" has no value in Session State. You said if she had a value in Session State?

    Now, someone might say, "well, the other query work it must have a value in Session State! Well, maybe. But might work work with null query ': P1100_CHOOSE_CATEGORY '?? If it is null, then get the value stored in the Session State.

    Howard

  • SQL query returns no row vs. multiple lines

    Hello

    I am trying to get the result of a simple sql query,
    If there is no row returned, he would have "No. ROWS" in the result set.
    Other wise all the rows containing data is necessary.

    Let me know how this could be achieved. Under query works for the latter and not first case as mentioned below

    OUTPUT

    + (box 1) when we use B_ID = 123456 +.

    IDS
    -----
    'NO LINE '.

    + (box 2) when we use B_ID = 12345 +.
    IDS
    -----
    1 11112345
    2 22212345
    create table TEMP_AAA
    (
      A_ID VARCHAR2(10),
      B_ID VARCHAR2(10)
    )
    
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('111','12345');
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('222','12345');
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('333','12000');
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('444','10000');
    WITH 
    MATCH_ROWS AS
    (
           SELECT A_ID||B_ID IDS FROM TEMP_AAA WHERE B_ID=12345
    ),
    
    MATCH_ROW_COUNT AS
    (
           SELECT COUNT(1) AS COUNTS FROM MATCH_ROWS
    ),
    
    PROCESSED_ROWS AS
    (
           SELECT
                 CASE WHEN COUNTS = 0
                      THEN 
                       (SELECT NVL((SELECT IDS FROM TEMP_AAA WHERE B_ID=12345),'NO ROWS') IDS FROM DUAL)
                      ELSE
                       MATCH_ROWS.IDS
                 END IDS     
            FROM MATCH_ROWS,MATCH_ROW_COUNT
    )
    
    SELECT * FROM PROCESSED_ROWS;

    Hello

    I think you want to put this on a report or something. I have what would be easier to do this logic there. But if you want that this is possible.
    Like this

    with
    temp_aaa as
    (select '111' a_id ,'12345' b_id from dual union all
    select '222'      ,'12345'  from dual union all
    select '333'      ,'12000'  from dual union all
    select '444'      ,'10000'  from dual
    )
    , wanted_rows as
    ( select  '123456' B_ID from dual)
    select
      temp_aaa.A_ID || temp_aaa.B_ID IDS 
    
    from
      temp_aaa
      ,wanted_rows
    where
      temp_aaa.b_id = wanted_rows.b_id
    union all
    select
      'NO ROWS'
    FROM
      DUAL
    WHERE
      (SELECT COUNT(*) FROM TEMP_AAA, wanted_rows WHERE TEMP_AAA.B_ID = wanted_rows.B_ID) = 0
    

    In addition, you mix var and number of always use the same type or convert explicitly (to_number or to_char)

    WITH
    MATCH_ROWS AS
    (
           SELECT A_ID||B_ID IDS FROM TEMP_AAA WHERE      B_ID           =12345
    --                                                    varchar2(10)   number
    ),
    ...
    

    And again in the

                      THEN
                       (SELECT NVL((SELECT IDS FROM TEMP_AAA WHERE B_ID           =12345),'NO ROWS') IDS FROM DUAL)
    --                                                             varchar2(10)   number
    

    Kind regards

    Peter

  • Problem with list of customers after 1.02.11 WRT160N wireless firmware update

    I have just updated the firmware on my WRT160N to 1.02.11

    When I go to wireless-> Wireless MAC Filter, click list of wireless clients, I get a blank screen for the most part, and then my Internet access to the router no longer works. for example, I can no longer connect to the router via a browser.

    The router continues to work for cable customers and wireless, but the router web access does not work.

    I need to display the wireless clients because I'm having intermittent problems with my new Ipad to connect.

    Someone saw what is wrong?

    You have already updated the firmware of the router.

    After upgrading the firmware on the router, it is recommended to reset and reconfigure the router.

    Connect computer with the Ethernet cable to the Ethernet port on the router.

    Hold down the button for 30 seconds rest.

    Release the reset button wait 30 seconds.

    Cycle power to the router.

    Open the page of the router and configure your router settings manually.

  • BBM BBM groups - problem with lists and complete / incomplete

    Was wondering if anyone else has this problem with BBM group lists.
    The two 10.2.1.3175 OS running on a Z10 (MTS) and 10.2.1.3247 (Rogers)
    BBM version 10.3.33.18

    BES 10.2.0.33

    Create a new group and add a list to the group. Add a number of items and when you hit the audit to complete / incomplete, it often checks / unchecks a 2nd independent element.

    I tested on 3 different devices / users so don't think it's my BB ID.

    Can anyone else duplicate?

    This problem makes it absolutely useless lists for me now because I use mainly for shopping lists, and if I check the items that I acquired and the fact, I obviously Miss things on my list.

    (Note: I have an ID for test on an iPhone with BBM for iOS and it does not seem to meet this problem)

    Probably a bug in BBM. We cannot do that until they update nothing BBM. There are other bugs in there also we expect on patches for.

  • Dynamic SQL query

    Hi all

    I have a procedure that takes as an input parameter v_emp_id which is of type varchar.

    emp_id are sent separated by commas to v_emp_id. Ex: v_emp_id = 7,2,1

    In my code I use a cursor for loop recover data from the table emp like this

    I'm in (select * from emp where emp_id in v_emp_id) loop
    -----
    end loop;

    It does not work. How do I use dynamic sql statements to retrieve data by using the CURSOR LOOP FOR only?

    Thanks in advance

    MR Marie wrote:

    How do I use dynamic sql statements to retrieve data by using the CURSOR LOOP FOR only?

    Not with dynamic sql statements. I suggest you use collections:

    SQL> create or replace
      2    procedure p1(
      3                 p_empno sys.OdciNumberList
      4                )
      5      is
      6      begin
      7          for v_rec in (select ename from emp where empno in (select * from table(p_empno))) loop
      8            dbms_output.put_line(v_rec.ename);
      9          end loop;
     10  end;
     11  /
    
    Procedure created.
    
    SQL> set serveroutput on
    SQL> exec p1(sys.OdciNumberList(7566,7844,7900));
    JONES
    TURNER
    JAMES
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

Maybe you are looking for