Procedure w/o cursor

Hello all,
I am beginer and struggling to write a procedure.
there are three tables
Student, dept, course
I have to look for students name, deptid and if this dept id exists in course table and if so what all course id comes under this dept id.
In a simple sql : select name from student , dept where student.deptid = id.dept;
select courseid from course where course.dptid = dept.id
I have to club these two to get all the results.
I should not use cursors.
Your help is appreciated.

Try doing this
(select name from student , dept where student.deptid = id.dept)
(select courseid,dept from course where course.dptid = dept.id)
Then JOIN both those result sets and select student, dept and courseid

Similar Messages

  • SSRS 2008 Using Stored Procedure with SysRef Cursor Oracle

    Hi,
    I am new to SSRS.
    I have a ssrs procedure which runs to Return Result of Select Query. ( In form of SYS REF Cursor in Oracle ).
    When I am trying to see the Value in Test Window. It is showing Output. But when I m Running the Report in the environment it is giving me error.
    Please help me if there is a better way of handling it.
    As I read in some forum as SSRS has issue handling SYS Ref Cursor...
    Thanks
    Priyank
    Thanks Priyank Piyush

    Hi Priyank,
    According to your description, you are use a Stored Procedure from SysRef Cursor Oracle as the report dataset. The query works well in Dataset Query Designer, while an error occurs when you render the report.
    As per my understanding, the problem is that there are something wrong with the report design. Please double-check the design of the report. In order to trouble shoot the problem more efficiently, could you please post the detail error message? Then we can
    make further analysis.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Procedure within a cursor

    I have a procedure within a cursor.
    How do I assign the "termination_date" calculated in the cursor to the "v_end_date" and pass it into the procedure?
    declare
    cursor x is  select      a.store_no || '-' || b.store_name name,
                              a.store_no,
                           landlord_turnover_date execution_date,
                   open_date commencement_date,
                   decode(
                    decode(sign(round(months_between(nvl(option1_end_date,open_date), open_date)/12,0) - 10), 1, option1_end_date,
                    decode(sign(round(months_between(nvl(option2_end_date,open_date), open_date)/12,0) - 10), 1, option2_end_date,
                     decode(sign(round(months_between(nvl(option3_end_date,open_date), open_date)/12,0) - 10), 1, option3_end_date,
                      decode(sign(round(months_between(nvl(option4_end_date,open_date), open_date)/12,0) - 10), 1, option4_end_date,
                       decode(sign(round(months_between(nvl(option5_end_date,open_date), open_date)/12,0) - 10), 1, option5_end_date,
                         decode(sign(round(months_between(nvl(option6_end_date,open_date), open_date)/12,0) - 10), 1, option6_end_date)))))),null,
                           nvl(option6_end_date,nvl(option5_end_date,nvl(option5_end_date,nvl(option4_end_date,nvl(option3_end_date,nvl(option2_end_date,option1_end_date)))))),
                             decode(sign(round(months_between(nvl(option1_end_date,open_date), open_date)/12,0) - 10), 1, option1_end_date,
                              decode(sign(round(months_between(nvl(option2_end_date,open_date), open_date)/12,0) - 10), 1, option2_end_date,
                               decode(sign(round(months_between(nvl(option3_end_date,open_date), open_date)/12,0) - 10), 1, option3_end_date,
                                decode(sign(round(months_between(nvl(option4_end_date,open_date), open_date)/12,0) - 10), 1, option4_end_date,
                                 decode(sign(round(months_between(nvl(option5_end_date,open_date), open_date)/12,0) - 10), 1, option5_end_date,
                                   decode(sign(round(months_between(nvl(option6_end_date,open_date), open_date)/12,0) - 10), 1, option6_end_date))))))) termination_date,
                   option1_base_rent,
                   option1_end_date,
                   option2_base_rent,
                   option2_end_date,
                   option3_base_rent,
                   option3_end_date,
                   option4_base_rent,
                   option4_end_date,
                   option5_base_rent,
                   option5_end_date,
                   option6_base_rent,
                   option6_end_date,
                   c.vendor_number,
                   d.vendor_id,
                   e.vendor_site_id,
                            cost_center                                                                                                                        
                   from lease_terms a, store b, workrent c, po_vendors d, po_vendor_sites_all e
                  where flag = 'Y'
              and a.store_no = b.store
              and a.store_no = c.store_no
              and c.rent_amt_5301 > 0
              and c.vendor_number = d.segment1
              and d.vendor_id = e.vendor_id
              and c.pay_site_name = e.vendor_site_code;
       v_loc_id number;          
       v_norm   varchar2(1);
       v_term_id number;
       v_lease_id number;
       v_change_id number;
       v_div     varchar2(2);
       v_exp_id  number;
       v_acc_id  number;
       PROCEDURE insert_payment ( v_term_id        IN number,
                                  v_lease_id       IN number,
                            v_change_id      IN number,
                            v_start_date     IN date,
                            v_end_date       IN date,
                            v_vendor_id      IN number,
                            v_vendor_site_id IN number,
                            v_amt            IN number,
                         v_normalize      IN varchar2,
                                  v_expense_id     IN NUMBER,
                                  v_lia_id         IN NUMBER)
       IS
       BEGIN
           insert into pn_payment_terms_all (
                   payment_term_id,           
                   last_update_date,
                last_updated_by,
                creation_date,
                created_by,
                last_update_login,
                payment_purpose_code,
                payment_term_type_code,
                frequency_code,
                lease_id,
                lease_change_id,
                start_date,
                end_date,
                vendor_id     ,
                vendor_site_id,
                actual_amount,
                set_of_books_id,
                currency_code,
                rate,
                org_id,
                normalize,
                schedule_day,
                lease_status)
           values
             (     v_term_id,
                SYSDATE,
                -1,
                SYSDATE,
                -1,
                0,
                'RENT',
                'BASER',
                'MON',
                v_lease_id,
                v_change_id,
                v_start_date,
                v_end_date,
                v_vendor_id,
                v_vendor_site_id,
                v_amt,
                1,
                'USD',
                1,
                101,
                v_normalize,
                1,
                'ACT');

    btw the nested DECODEs could be simplified greatly using CASE, or if this is 8i you might still be able to unnest them with something like:
    decode(1,
           sign(round(months_between(nvl(option1_end_date,open_date), open_date)/12,0) - 10), option1_end_date,
           sign(round(months_between(nvl(option2_end_date,open_date), open_date)/12,0) - 10), option2_end_date,
           sign(round(months_between(nvl(option3_end_date,open_date), open_date)/12,0) - 10), option3_end_date,
           sign(round(months_between(nvl(option4_end_date,open_date), open_date)/12,0) - 10), option4_end_date,
           sign(round(months_between(nvl(option5_end_date,open_date), open_date)/12,0) - 10), option5_end_date,
           sign(round(months_between(nvl(option6_end_date,open_date), open_date)/12,0) - 10), option6_end_date,
           NVL(...) )Unfortunately I rather lost track of it after that. You may also be able to simplify the nested NVLs using COALESCE, e.g.
    coalesce
    ( option6_end_date,
      option5_end_date,
      option5_end_date,
      option4_end_date,
      option3_end_date,
      option2_end_date,
      option1_end_date ), ...although if this is 8i COALESCE may not be available.
    Why they couldn't just have added more optional arguments to NVL I will never understand.

  • Testing procedure that returns cursor.

    Please
    How Can I test a procedure that returns a cursor? I need to execute it on sqlplus.
    Thank you very much

    Hi,
    Example using HR schema:
    The proc_cursor procedure returns a cursor and the block below test it
    SET SERVEROUTPUT ON
    DECLARE
        TYPE t_ref_cur IS REF CURSOR;
        v_cursor   t_ref_cur;
        v_employee employees%ROWTYPE;
        PROCEDURE proc_cursor(p_cursor OUT t_ref_cur) IS
            v_sql VARCHAR2(4000);
        BEGIN
            v_sql := 'SELECT * FROM EMPLOYEES';
            OPEN p_cursor FOR v_sql;
        END;
    BEGIN
        proc_cursor(p_cursor => v_cursor);
        LOOP
            FETCH v_cursor
                INTO v_employee;
            EXIT WHEN v_cursor%NOTFOUND;
            dbms_output.put_line(v_employee.employee_id);
        END LOOP;
        CLOSE v_cursor;
    END;
    /Regards,

  • Ora-01001 in procedures with ref cursor parameter after upgrade to 11.1.0.7

    Hi,
    after upgrading from 11.1.0.6.0 to 11.1.0.7.0, I get ora-01001 in procedure calls which have a ref cursor as an out parameter.
    Even a new 11.1.0.7 instance throws this error. My OS is Linux SLES10SP2.
    Please see atched sample code:
    CREATE OR REPLACE PACKAGE test1_pck
    IS
    PROCEDURE run1; -- OK on 11.1.0.6; fails on 11.1.0.7
    PROCEDURE run2; -- OK on 11.1.0.6; OK on 11.1.0.7
    END test1_pck;
    CREATE OR REPLACE PACKAGE BODY test1_pck
    IS
    TYPE t_rec IS RECORD(col dual.dummy%TYPE);
    TYPE t_cur IS REF CURSOR RETURN t_rec;
    PROCEDURE foo1(p_cur OUT t_cur)
    IS
    v_sql VARCHAR2(255) := 'BEGIN OPEN :1 FOR SELECT dummy FROM dual; END;';
    BEGIN
    EXECUTE IMMEDIATE v_sql USING p_cur;
    END foo1;
    PROCEDURE foo2
    IS
    v_sql VARCHAR2(255) := 'BEGIN OPEN :1 FOR SELECT dummy FROM dual; END;';
    v_cur t_cur;
    v_rec t_rec;
    BEGIN
    EXECUTE IMMEDIATE v_sql USING v_cur;
    LOOP
    FETCH v_cur INTO v_rec;
    EXIT WHEN v_cur%NOTFOUND;
    CASE v_rec.col
    WHEN 'X' THEN dbms_output.put_line('success');
    ELSE dbms_output.put_line('error');
    END CASE;
    END LOOP;
    END foo2;
    PROCEDURE run1
    IS
    v_cur t_cur;
    v_rec t_rec;
    BEGIN
    foo1(v_cur);
    LOOP
    FETCH v_cur INTO v_rec;
    EXIT WHEN v_cur%NOTFOUND;
    CASE v_rec.col
    WHEN 'X' THEN dbms_output.put_line('success');
    ELSE dbms_output.put_line('error');
    END CASE;
    END LOOP;
    END run1;
    PROCEDURE run2
    IS
    BEGIN
    foo2;
    END run2;
    END test1_pck;
    Thanks for any hints.
    Regards Frank

    Hi Max,
    the referenced thread discusses a .Net problem. A lot of layers are involved their. My problem is a very basic problem. You get this error even if you run the test in a sql session on the server.
    It would be a great help for me
    a) if someone could test this package on a 11.1.0.7 database
    b) if someone could test this package on a 11.2 database (is it fixed in Release2?)
    c) if someone could give me hints how I could modify the procedure to make it usable for 11.1.0.7
    (I already tried a lot e.g. EXECUTE IMMEDIATE v_sql USING OUT p_cur;
    Thank you
    Frank

  • How to create a LOV based on a stored procedure returning a cursor

    Hello,
    I've tried to search the forum, but did not find much. We are facing a problem of large LOVs and creating large TMP files on the app server. Our whole application is drived by store procedures. LOVs are built manually by fetching data from cursors returned from stored procedures. That creates the issue when whole LOV needs to be stored in the memory and thus the TMP files.
    Is there anyway how to create LOV based on a procedure returning cursor ?
    Thank you,
    Radovan

    Hello,
    As of now we populate the record group by looping through the ref cursor and adding rows into it. Is there a better way? That forces the whole record group to be stored in a memory on the app server.
    Thank you,
    Radovan

  • Unable to create plsql procedure, fails at cursor

    This was a working procedure which would take ID and then copy data from source parameter to destination parameter. Now I would like to have NAME as parameter, I have changed the code to accommodate the new parameters. But I am not able to create the procedure. I am getting 3 error at CURSOR (in bold red). I would like really appreciate if someone can take a look and let me know what is wrong.
    Thanks in advance
    3 ERRORs
    1. PLS-00103: Encountered the symbol "CUR_V_HSP_COLUMN_DETAIL" when expecting one of the following:
       := . ( @ % ;
    The symbol ":=" was substituted for "CUR_V_HSP_COLUMN_DETAIL" to continue.
    2. PLS-00103: Encountered the symbol "NUMBER" when expecting one of the following:
    The symbol "(" was substituted for "NUMBER" to continue.
    3. PLS-00103: Encountered the symbol "NUMBER" when expecting one of the following:
    CREATE OR REPLACE procedure EPM_PLAN_PLANSAMP.Copy_Details_test1 --Arguments
    ( in_From_Version_Name IN VARCHAR2, --HSP_object.OBJECT_NAME - Version From
    in_From_Scenario_Name IN VARCHAR2 , --HSP_object.OBJECT_NAME - Scenarios From
    in_From_Year_Name IN VARCHAR2 , --HSP_object.OBJECT_NAME - Year From
    in_To_Version_Name IN VARCHAR2, --HSP_object.OBJECT_NAME - Version To
    in_To_Scenario_name IN VARCHAR2, --HSP_object.OBJECT_NAME - Scenarios To
    in_To_Year_Name IN VARCHAR2 --HSP_object.OBJECT_NAME - Year To
    IS
    v_From_Object_Id number; --  Version From
    s_From_Object_Id number; -- Scenarios From
    y_From_Object_Id number; -- Year From
    v_To_Object_Id number; -- Version To
    s_To_Object_Id number; -- Scenarios To
    y_To_Object_Id number; -- Year To
    BEGIN
    Select object_id into v_From_Object_Id
    from hsp_object
    where object_type = 35
    and object_name = in_from_version_name;
    Select object_id into s_From_Object_Id
    from hsp_object
    where object_type = 31
    and object_name = in_from_scenario_name;
    Select object_id into y_From_Object_Id
    from hsp_object
    where object_type = 38
    and object_name = in_from_year_name;
    Select object_id into v_To_Object_Id
    from hsp_object
    where object_type = 35
    and object_name = in_to_version_name;
    Select object_id into s_To_Object_Id
    from hsp_object
    where object_type = 31
    and object_name = in_to_scenario_name;
    Select object_id into y_To_Object_Id
    from hsp_object
    where object_type = 38
    and object_name = in_to_year_name;
    --Select Supporting Details for the current Version
    CURSOR Cur_V_HSP_COLUMN_DETAIL (cV_From_Object_Id IN NUMBER, cS_From_Object_Id IN NUMBER) IS
    Select DETAIL_ID From EPM_PLAN_PLANSAMP.HSP_COLUMN_DETAIL Where DIM5 = cV_From_Object_Id AND DIM1 = cS_From_Object_Id;
    li_DETAIL_ID NUMBER;
    Li_Next_DETAIL_ID NUMBER;
    FETCH_STATUS NUMBER := 0;
    v_step_name varchar2(200);
    v_rec_cnt number := 0;
    v_cnt number;
    v_err varchar2(2000);
    -----------------------------------------Begin Copy Version ---------------------------
    BEGIN
    -- Delete Next version if already exists
    v_step_name := 'Delete on HSP_COLUMN_DETAIL_ITEM';
    Delete from HSP_COLUMN_DETAIL_ITEM
    Where DETAIL_ID in (Select DETAIL_ID from HSP_COLUMN_DETAIL
    Where DIM5 = v_To_Object_Id AND DIM1 = s_To_Object_Id);
    v_cnt := sql%rowcount;
    insert into t_copy_supporting_dtls_log values (v_step_name, v_cnt,1,'Success',sysdate);
    v_step_name := 'Delete on HSP_COLUMN_DETAIL';
    Delete from HSP_COLUMN_DETAIL
    where DIM5 = v_To_Object_Id AND DIM1 = s_To_Object_Id;
    v_cnt := sql%rowcount;
    insert into t_copy_supporting_dtls_log values (v_step_name, v_cnt,1,'Success',sysdate);
    Open Cur_V_HSP_COLUMN_DETAIL(v_From_Object_Id, s_From_Object_Id);
    v_step_name := 'Inserts ';
    LOOP
    FETCH Cur_V_HSP_COLUMN_DETAIL INTO li_DETAIL_ID;
    EXIT WHEN Cur_V_HSP_COLUMN_DETAIL%NOTFOUND;
    -- Find next detail_id
    Select Max(DETAIL_ID) + 1 INTO Li_Next_DETAIL_ID From HSP_COLUMN_DETAIL;
    -- Insert Into HSP_COLUMN_DETAIL Table
    Insert Into HSP_COLUMN_DETAIL ( DETAIL_ID , PLAN_TYPE , DIM1 , DIM2 , DIM3 , DIM4 , DIM5 , DIM6 ,
    DIM7 , DIM8 , DIM9 , DIM10 , DIM11 , DIM12 , DIM13 , DIM14 , DIM15 ,
    DIM16 , DIM17 , DIM18 , DIM19 , DIM20 )
    Select Li_Next_DETAIL_ID , PLAN_TYPE , S_To_Object_Id , DIM2 , DIM3 , DIM4 , V_To_Object_Id , DIM6 ,
    DIM7 , DIM8 , DIM9 , DIM10 , DIM11 , DIM12 , DIM13 , DIM14 , DIM15 ,
    DIM16 , DIM17 , DIM18 , DIM19 , DIM20
    From HSP_COLUMN_DETAIL
    Where DETAIL_ID = li_DETAIL_ID;
    v_rec_cnt := v_rec_cnt + sql%rowcount;
    -- Insert Into HSP_COLUMN_DETAIL_ITEM Table
    Insert Into HSP_COLUMN_DETAIL_ITEM ( DETAIL_ID , VALUE , POSITION , GENERATION , OPERATOR , LABEL)
    Select Li_Next_DETAIL_ID , VALUE , POSITION , GENERATION , OPERATOR , LABEL
    From HSP_COLUMN_DETAIL_ITEM Where DETAIL_ID = li_DETAIL_ID;
    v_rec_cnt := v_rec_cnt + sql%rowcount;
    END LOOP;
    Close Cur_V_HSP_COLUMN_DETAIL;
    insert into t_copy_supporting_dtls_log values (v_step_name, v_rec_cnt,1,'Success',sysdate);
    commit;
    exception when others then
    rollback;
    v_err := substr(sqlerrm,1,2000);
    insert into t_copy_supporting_dtls_log values (v_step_name, 0,-1,v_err,sysdate);
    commit;
    END;
    END;

    All the following statements should go into the declaration section (i.e. before the first begin)
    CURSOR Cur_V_HSP_COLUMN_DETAIL (cV_From_Object_Id IN NUMBER, cS_From_Object_Id IN NUMBER) IS
    Select DETAIL_ID From EPM_PLAN_PLANSAMP.HSP_COLUMN_DETAIL Where DIM5 = cV_From_Object_Id AND DIM1 = cS_From_Object_Id;
    li_DETAIL_ID NUMBER;
    Li_Next_DETAIL_ID NUMBER;
    FETCH_STATUS NUMBER := 0;
    v_step_name varchar2(200);
    v_rec_cnt number := 0;
    v_cnt number;
    v_err varchar2(2000);

  • 64bit OraOLEDB failed when calling stored procedure with Ref Cursor

    Hi everyone,
    I used the ADO VB sample provided with the Oracle 10g provider installation.
    But I compiled it in 64bit Visual Studio 2005 and ran on Windows 2003 x64 server.
    The function call "cmd.Execute" when it is trying to call a stored procedure which has an Out Ref Cursor parameter. The exception is
    "PLS-00306: wrong number or types arguments in call"
    I already set the property "PLSQLRSet" to true. But it doesn't help.
    The same code works if I compiled in 32 bit.
    It also works if the stored procedure does not have Ref Cursor parameter.
    I am guessing this is a bug in the 64bit Oracle provider. Anyone can confirm this please? or am I missing anything?
    Wilson

    It appears to work with 11.1.0.6.20 OLEDB provider but only for ExecuteNonQuery, I'm not able to work with Fill, and yes... in x86 works perfectly, but in x64 we are still having the ORA-06550 and PLS-00306 error.
    Our Connection string is as follows:
    "Provider=OraOLEDB.Oracle.1;OLEDB.NET=true;Password=xxxxx;Persist Security Info=True;User ID=exxxxx;Data Source=ECOR; PLSQLRSet=True"
    We are not using ODP.NET.
    Can you confirm that Fill method works with such update?

  • How to return a resultset in a stored procedure without using Cursor

    Dear all,
    I need to return a resultset in a stored procedure.
    I know I can return a Cursor.
    But because there are many complicate logics I need to carry out,
    so I can finish all the logic in a SINGLE SQL select statement, so I think it can't
    use Cursor as return value.
    Does anybody know other approaches? Please help.
    Thanks!

    Some basic techniques that one can use in SQL. These are merely to illustrate (simplistically) different approaches.
    > field3 = select count(*) from table2,table1 where table2.id = table1.id
    This can be done via an analytical function (refer to the SQL Reference) or very simply, as an in-line select as follows:
    SQL> select
    2 o.object_name,
    3 (select count(*) from user_objects u where u.object_type = o.object_type) as "ONE OF",
    4 o.object_type
    5 from user_objects o
    6 where o.object_name = 'LISTFILES';
    OBJECT_NAME ONE OF OBJECT_TYPE
    LISTFILES 8 PROCEDURE
    So LISTFILE is "one of 8" procedures. I would however rather so this via an analytic function as these are a lot more flexible. Note the WITH clause that allows "modularisation" of SQL - kind of like creating "sub-SQL results" in a single SQL statement:
    SQL> with DATASET1 as(
    2 select
    3 object_name,
    4 count(distinct object_name) over (partition by object_type) as TOTAL_TYPES,
    5 object_type
    6 from user_objects
    7 ),
    8 DATASET2 as(
    9 select
    10 name,
    11 text as SOURCE_LINE,
    12 line as LINE_NO,
    13 count(line) over (partition by name) as TOTAL_LINES
    14 from user_source
    15 )
    16 select
    17 object_name,
    18 '1 of '||total_types||' '||object_type as "TYPE",
    19 source_line as "1st LINE",
    20 total_lines as "TOTAL LINES"
    21 from DATASET1 ds1,
    22 DATASET2 ds2
    23 where ds1.object_name = ds2.name
    24 and ds1.object_name = 'LISTFILES'
    25* and ds2.line_no = 1
    SQL> /
    OBJECT_NAME TYPE 1st LINE TOTAL LINES
    LISTFILES 1 of 8 PROCEDURE procedure ListFiles( cDirectory in varchar2 ) 3
    SQL>
    SQL is quite powerful and analytical functions allows all kinds of aggregation processing per row, accessing the leading or lagging rows' data, etc.
    You need to play around with this to get to grips with it and how to apply it.

  • Procedure Problem - Open Cursor for SQL

    in my form I added a procedure. this is working fine in SQL but when I try to run through form it gives error.
    Code of Procedure:-
    PROCEDURE Proc_Purchase_all IS
    BEGIN
      declare
         v_sql varchar2(4000);
         v_user varchar2(30);
         v_sep varchar2(20);
         v_cur SYS_REFCURSOR;
       pur_rec    purchase%ROWTYPE;
       begin
         for u in (SELECT * FROM ALL_TABLES WHERE OWNER LIKE 'BMP%' and table_name ='PURCHASE') loop
           v_sql := v_sql || v_sep || 'SELECT * from '||u.owner||'.purchase';
          v_sep := ' UNION ALL ';
        end loop;
        open v_cur for v_sql;
      Loop
      Fetch v_cur into pur_rec;
      Exit when v_cur%NOTFOUND;
      --DBMS_OUTPUT.PUT_LINE (PUR_REC.S_CODE||' '||Pur_rec.s_name);
      End Loop;
        close v_cur;
    end;
    END;Error Line
    * open v_cur for v_sql;*
    Error is :-
    Encountered the symbol 'V_SQL' when expecting one of the following.
    select
    Encountered the symbol END when expecting one of the following.
    Begin function package pragma procedure external

    I changed my code ALSO Showing SAME error .
    SQL> Declare 
      2    v_sql varchar2(4000);
      3       v_user varchar2(30);
      4       v_sep varchar2(20);
      5    TYPE R_CURSOR IS REF CURSOR RETURN purchase%ROWTYPE;
      6       C_Pur R_CURSOR;
      7       ER C_pur%ROWTYPE;
      8       BEGIN
      9    for u in (SELECT * FROM ALL_TABLES WHERE OWNER LIKE 'BMP%' and table_name ='PURCHASE') loop
    10         v_sql := v_sql || v_sep || 'SELECT * from '||u.owner||'.purchase';
    11        v_sep := ' UNION ALL ';
    12      end loop;
    13   OPEN C_Pur FOR V_sql;
    14       LOOP
    15       FETCH C_Pur INTO ER;
    16      EXIT WHEN C_Pur%NOTFOUND;
    17    
    18      END LOOP;
    19      CLOSE C_Pur;
    20     END; 
    21  /
    OPEN C_Pur FOR V_sql;
    ERROR at line 13:
    ORA-06550: line 13, column 7:
    PLS-00455: cursor 'C_PUR' cannot be used in dynamic SQL OPEN statement
    ORA-06550: line 13, column 2:
    PL/SQL: Statement ignoredEdited by: Ahmed on Jan 13, 2011 1:58 AM

  • Executing a Function in a Stored Procedure to Return Cursor

    I have a function named f_CPCRBPBR who base on the following types
    CREATE Or Replace TYPE RecType_fAC
    AS OBJECT ( << Structure >>);
    CREATE Or Replace TYPE Tbl_fAC
    AS TABLE OF RecType_fAC;
    Create Or Replace
    Function f_CPCRBPBR (
    i_Vtp Varchar2,
    i_Mnth Varchar2,
    i_Location Varchar2,
    i_vno integer,
    i_vnoTo integer,
    St_Date Varchar2,
    En_Date Varchar2
    Return TBL_fAC
    Pipelined
    Is
    RetVal RecType_fAC;
    Begin
    Now the problem is that I want to Call this Function from Within a Procedure who would return the Recordset..
    can any body suggest..
    I want to use the Record Type used for the Said Function..
    Please Help..

    This is Excellent .. This is great.. actually this is marvellous.. can u please defined a bit about Sys_RefCursor...
    this is an excellent thing..
    I finally Concluded the procedure as follows who not only called but also returned the cursor..
    Create Or Replace Procedure p_CPCRBPBR (TstCrsr In Out Sys_RefCursor,
    i_Vtp Varchar2,
    i_Mnth Varchar2,
    i_Location Varchar2,
    i_vno integer,
    i_vnoTo integer,
    St_Date Varchar2,
    En_Date Varchar2
    as
    Begin
    Open TstCrsr FOr
    Select * from Table(f_CPCRBPBR (i_VTP, i_Mnth, i_Location, i_VNo, i_VNoTo, '', ''));
    End;
    Can u please help me what will be the exact syntax to call / test this procedure in SQL Developer..
    as if i try this procedure as
    Execute p_CPCRBPBR null, 'CP', '01', 'L', 1, 1, null, null
    it give error Invalid SQL Statement ..
    2. Can u please check this code and refer me a solution for Calling this function
    create or replace function NewTest (iEN Integer)
    return sys_refcursor
    as
    rc sys_refcursor;
    begin
    open rc for select * from Scott.Emp Where EmpNo=iEN;
    return rc;
    end;
    This function easily created but when i tried to execute this with the following statement
    Select * from Table(NewTest (7369))
    It gives error
    Cannot Access Rows From a Non-Nested Table Item..
    .. Thanx for ur patience...

  • Generating Data for INSERT using a Stored Procedure, Function and Cursor

    I've written a function that I finally got to compile, but was not successful in importing and inserting the data needed to populate a table with at least 1800 rows. Here's what I needed to do:
    -- Generate a random test score ranging from 20 to 100 (already done)
    -- Generate a random final grade for the course ranging from 4 to 0 (representing A to F) (already done, but question below.
    -- Use conditional statements based on the counter to assign three courses (already done -- see SQL statements)
    -- Process no more than 95% of the students (300) for test 1.
    -- For test 2, process no more than 80% of the students who took test 1. Student cannot take test 2 unless the student takes test 1 (does this require a trigger? If so, how would I go about doing this?)
    -- Use a function or another subprocedure to process the grade using IF-ELSIF statements
    For example, I've tried the following statements:
    For procedures
    IF birth_date BETWEEN to_date('01-Jan-89 AND to_date('31-Dec-89','dd-Mon-yy') THEN
    school_grade := 6;
    AND for functions:
    IF birth_date BETWEEN to_date('01-Jan-89 AND to_date('31-Dec-89','dd-Mon-yy') THEN
    RETURN (6);
    RETURN;
    - or -
    IF birth_date BETWEEN to_date('01-Jan-89','dd-Mon-yy') AND to_date('31-Dec-89','dd-Mon-yy') THEN
    school_grade := 9
    RETURN school_grade;
    -- Read the birth_date into the main procedure so that the value returned from the subprocedure or function can populate the birth_date column.
    To give you an idea of what I've already done:
    SQL>
    SQL> CREATE OR REPLACE PROCEDURE add_tests (v_school_grade IN NUMBER) AS
    2
    3 v_counter NUMBER(3) := 0;
    4 v_num_students CONSTANT NUMBER(3) := 300;
    5 v_students_test1 NUMBER := 0;
    6 v_students_test2 NUMBER := 0;
    7 v_student_id VARCHAR2(5);
    8 v_course1 VARCHAR2(2);
    9 v_course2 VARCHAR2(2);
    10 v_course3 VARCHAR2(2);
    11 v_course4 VARCHAR2(2);
    12 v_student_grade NUMBER(1) := 0;
    13 v_test_score NUMBER(3) := 0;
    14 v_course_final_grade NUMBER(1) := 0;
    15 v_birth_date DATE;
    16
    17 FUNCTION pkg_get_grade RETURN NUMBER
    18 IS
    19
    20 v_birth_date DATE;
    21 v_school_grade NUMBER(1) :=0;
    22
    23 CURSOR grade_cur IS
    24 SELECT birth_date FROM students;
    25
    26 BEGIN
    27 OPEN grade_cur;
    28 LOOP
    29 FETCH grade_cur INTO v_birth_date;
    30
    31 EXIT WHEN grade_cur%NOTFOUND;
    32
    33 -- Assign student grade
    34
    35 -- 9th Grade
    36
    37 IF v_birth_date < TO_DATE('01-Jan-87','DD-Mon-YY') THEN
    38 v_school_grade := 9;
    39
    40 -- 8th grade
    41
    42 ELSIF v_birth_date BETWEEN
    43 TO_DATE('01-Jan-87','DD-Mon-YY') AND
    44 TO_DATE('31-Dec-87','DD-Mon-YY') THEN
    45
    46 v_school_grade := 8;
    47
    48 -- 7th grade
    49
    50 ELSIF v_birth_date BETWEEN
    51 TO_DATE('01-Jan-88','DD-Mon-YY') AND
    52 TO_DATE('31-Dec-88','DD-Mon-YY') THEN
    53
    54 v_school_grade := 7;
    55
    56 -- 6th grade
    57
    58 ELSIF v_birth_date BETWEEN
    59 TO_DATE('01-Jan-89','DD-Mon-YY') AND
    60 TO_DATE('31-Dec-89','DD-Mon-YY') THEN
    61
    62 v_school_grade := 6;
    63
    64 -- 5th grade
    65
    66 ELSIF v_birth_date > TO_DATE('31-Dec-89','DD-Mon-YY') THEN
    67
    68 v_school_grade := 5;
    69
    70 END IF; -- end if loop for student's grade
    71 END LOOP; -- end loop for grade_cur
    72 CLOSE grade_cur; -- close cursor for assigning grade
    73 RETURN v_school_grade;
    74
    75 END pkg_get_grade;
    76
    77 PROCEDURE delete_test_info AS
    78
    79 BEGIN
    80
    81 DELETE FROM student_facts;
    82
    83 END delete_test_info;
    84
    85 BEGIN
    86
    87 -- Process student for tests
    88
    89 WHILE (v_counter <= v_num_students) LOOP
    90 v_counter := v_counter + 1; -- initialize counter
    91
    92 -- Set student id
    93
    94 v_student_id := 'S'&#0124; &#0124;v_counter;
    95
    96 -- portion of students taking beginning of year tests
    97
    98 v_students_test1 := v_num_students * .95;
    99
    100
    101 -- Portion of students taking end of year tests
    102
    103 v_students_test2 := v_students_test1 * .80;
    104
    105
    106 -- Est. test scores between 20 and 100
    107
    108 v_test_score := random.rand_max(80) + 20;
    109
    110
    111 -- Est. final grade for course between 0 and 4
    112
    113 v_course_final_grade := random.rand_max(4);
    114
    115
    116 -- Process tests for courses
    117
    118 IF v_counter < ROUND(v_num_students * .20) THEN
    119 v_course1 := 'C1';
    120 v_course2 := 'C2';
    121 v_course3 := 'C3';
    122
    123 ELSIF v_counter BETWEEN ROUND(v_num_students * .20)
    124 AND ROUND(v_num_students * .40) THEN
    125
    126 v_course1 := 'C2';
    127 v_course2 := 'C1';
    128 v_course3 := 'C3';
    129
    130 ELSE IF v_counter BETWEEN ROUND(v_num_students * .40)
    131 AND ROUND(v_num_students * .60) THEN
    132
    133 v_course1 := 'C3';
    134 v_course2 := 'C1';
    135 v_course3 := 'C2';
    136
    137 ELSE IF v_counter BETWEEN (v_num_students * .60)
    138 AND ROUND(v_num_students * .80) THEN
    139
    140 v_course1 := 'C3';
    141 v_course2 := 'C1';
    142 v_course3 := 'C2';
    143
    144 ELSE
    145 v_course1 := 'C4';
    146 v_course2 := 'C2';
    147 v_course3 := 'C3';
    148
    149 END IF;
    150 END IF;
    151 END IF;
    152
    153 -- Input test information for students
    154
    155 -- Beginning of year test for Course 1
    156
    157 IF v_counter <= v_students_test1 THEN
    158 INSERT INTO studentfacts
    159 VALUES(v_student_id, v_course1, 'ACH1999',
    160 TO_DATE('01-SEP-1999','DD-MON-YYYY'),
    161 v_student_grade, v_course_final_grade, v_test_score);
    162 ELSE
    163 INSERT INTO studentfacts
    164 VALUES(v_student_id, v_course1, 'ACH1999',
    165 TO_DATE('01-SEP-1999','DD-MON-YYYY'),
    166 v_student_grade, v_course_final_grade, NULL);
    167 END IF;
    168
    169
    170 -- End of year test for Course 1
    171
    172 IF v_counter <= v_students_test2 THEN
    173 INSERT INTO studentfacts
    174 VALUES(v_student_id, v_course1,'ACH2000',
    175 TO_DATE('01-JUN-2001','DD-MON-YYYY'),
    176 v_student_grade, v_course_final_grade, v_test_score);
    177 ELSE
    178 INSERT INTO studentfacts
    179 VALUES(v_student_id, v_course1, 'ACH2000',
    180 TO_DATE('01-JUN-2001','DD-MON-YYYY'),
    181 v_student_grade, v_course_final_grade, NULL);
    182 END IF;
    183
    184
    185 -- Beginning of year test for Course 2
    186
    187 IF v_counter <= v_students_test1 THEN
    188 INSERT INTO studentfacts
    189 VALUES(v_student_id, v_course2, 'ACH1999',
    190 TO_DATE('01-SEP-1999','DD-MON-YYYY'),
    191 v_student_grade, v_course_final_grade,
    192 v_test_score);
    193 ELSE
    194 INSERT INTO studentfacts
    195 VALUES(v_student_id, v_course2, 'ACH1999',
    196 TO_DATE('01-SEP-1999','DD-MON-YYYY'),
    197 v_student_grade, v_course_final_grade, NULL);
    198 END IF;
    199
    200
    201 -- End of year test for Course 2
    202
    203 IF v_counter <= v_students_test2 THEN
    204 INSERT INTO studentfacts
    205 VALUES(v_student_id, v_course2,'ACH2000',
    206 TO_DATE('01-JUN-2001''DD-MON-YYYY'),
    207 v_student_grade, v_course_final_grade,
    208 v_test_score);
    209 ELSE
    210 INSERT INTO studentfacts
    211 VALUES(v_student_id, v_course2, 'ACH2000',
    212 TO_DATE('01-JUN-2001','DD-MON-YYYY'),
    213 v_student_grade, v_course_final_grade, NULL);
    214 END IF;
    215
    216
    217 -- Beginning of year test for Course 3
    218
    219 IF v_counter <= v_students_test1 THEN
    220 INSERT INTO studentfacts
    221 VALUES(v_student_id, v_course3, 'ACH1999',
    222 TO_DATE('01-SEP-1999','DD-MON-YYYY'),
    223 v_student_grade, v_course_final_grade,
    224 v_test_score);
    225 ELSE
    226 INSERT INTO studentfacts
    227 VALUES(v_student_id, v_course3, 'ACH1999',
    228 TO_DATE('01-SEP-1999','DD-MON-YYYY'),
    229 v_student_grade, v_course_final_grade, NULL);
    230 END IF;
    231
    232
    233 -- End of year test for Course 3
    234
    235 IF v_counter <= v_students_test2 THEN
    236 INSERT INTO studentfacts
    237 VALUES(v_student_id, v_course3,'ACH2000',
    238 TO_DATE('01-JUN-2001','DD-MON-YYYY'),
    239 v_student_grade, v_course_final_grade,
    240 v_test_score);
    241 ELSE
    242 INSERT INTO studentfacts
    243 VALUES(v_student_id, v_course3, 'ACH2000',
    244 TO_DATE('01-JUN-2001','DD-MON-YYYY'),
    245 v_student_grade, v_course_final_grade, NULL);
    246 END IF;
    247
    248
    249 -- Beginning of year test for Course 4
    250
    251 IF v_counter <= v_students_test1 THEN
    252 INSERT INTO studentfacts
    253 VALUES(v_student_id, v_course4, 'ACH1999',
    254 TO_DATE('01-SEP-1999','DD-MON-Y YYY'),
    255 v_student_grade, v_course_final_grade,
    256 v_test_score);
    257 ELSE
    258 INSERT INTO studentfacts
    259 VALUES(v_student_id, v_course4, 'ACH1999',
    260 TO_DATE('01-SEP-1999','DD-MON-YYYY'),
    261 v_student_grade, v_course_final_grade, NULL);
    262 END IF;
    263
    264
    265 -- End of year test for Course 4
    266
    267 IF v_counter <= v_students_test2 THEN
    268 INSERT INTO studentfacts
    269 VALUES(v_student_id, v_course4,'ACH2000',
    270 TO_DATE('01-JUN-2001', 'DD-MON-YYYY'),
    271 v_student_grade, v_course_final_grade, v_test_score);
    272 ELSE
    273 INSERT INTO studentfacts
    274 VALUES(v_student_id, v_course4, 'ACH2000',
    275 TO_DATE('01-JUN-2001','DD-MON-YYYY'),
    276 v_student_grade, v_course_final_grade, NULL);
    277
    278 END IF;
    279 END LOOP;
    280 END add_tests;
    281 /
    Procedure created.
    SQL>
    SQL> show errors
    No errors.
    SQL>
    SQL> Input truncated to 9 characters
    spool off
    When I executed the main procedure, no data populated the student_table. I've tried several things, but I was not still able to populate the student_fact table (I've been at this for more than a week now, but haven't figured a way to populate the student_facts table with at least 1800 rows). Can you tell me what I need to change (if anything) whether if I need to structure things differently? I'm thinking that I missed something in calling the birth_date into the main procedure or returning the value from either a function or subprocedure. Related to the random final grade -- is there a way to sum the totals of the test scores (each student will have three), and generate a final grade from these values.
    I also compiled successfully a package containing this same information, but don't know how to execute it to see whether this approach works.
    Many thanks to anyone who can help.
    null

    ldsw,
    I am not sure if I totally understand everything that you are trying to do, but I tried to clean up your code and what is listed below is what I came up with. Please see if you can make use of any of it.
    SQL> EDIT ldsw
    CREATE OR REPLACE PACKAGE ldsw
    AS
    CURSOR grade_cur
    IS
    SELECT birth_date
    FROM students;
    PROCEDURE delete_test_info;
    FUNCTION get_grade
    (v_birth_date IN DATE)
    RETURN NUMBER;
    PRAGMA RESTRICT_REFERENCES (get_grade, WNDS, WNPS, RNDS, RNPS);
    PROCEDURE add_tests;
    END ldsw;
    CREATE OR REPLACE PACKAGE BODY ldsw
    AS
    v_student_grade NUMBER (1) := 0;
    PROCEDURE delete_test_info
    IS
    BEGIN
    DELETE FROM studentfacts;
    END delete_test_info;
    FUNCTION get_grade
    (v_birth_date IN DATE)
    RETURN NUMBER
    IS
    v_school_grade NUMBER (1) := 0;
    BEGIN
    IF v_birth_date < TO_DATE ('01-Jan-1987', 'DD-Mon-YYYY')
    THEN
    v_school_grade := 9;
    ELSIF v_birth_date BETWEEN TO_DATE ('01-Jan-1987', 'DD-Mon-YYYY') AND TO_DATE ('31-Dec-1987', 'DD-Mon-YYYY')
    THEN
    v_school_grade := 8;
    ELSIF v_birth_date BETWEEN TO_DATE ('01-Jan-1988', 'DD-Mon-YYYY') AND TO_DATE ('31-Dec-1988', 'DD-Mon-YYYY')
    THEN
    v_school_grade := 7;
    ELSIF v_birth_date BETWEEN TO_DATE ('01-Jan-1989', 'DD-Mon-YYYY') AND TO_DATE ('31-Dec-1989', 'DD-Mon-YYYY')
    THEN
    v_school_grade := 6;
    ELSIF v_birth_date > TO_DATE ('31-Dec-1989', 'DD-Mon-YYYY')
    THEN
    v_school_grade := 5;
    END IF;
    RETURN v_school_grade;
    END get_grade;
    PROCEDURE add_tests
    IS
    v_num_students CONSTANT NUMBER (3) := 300;
    v_students_test1 NUMBER := 0;
    v_students_test2 NUMBER := 0;
    v_counter NUMBER (3) := 0;
    v_student_id VARCHAR2 (5);
    v_test_score NUMBER (3) := 0;
    v_course_final_grade NUMBER (1) := 0;
    v_course1 VARCHAR2 (2) := NULL;
    v_course2 VARCHAR2 (2) := NULL;
    v_course3 VARCHAR2 (2) := NULL;
    v_course4 VARCHAR2 (2) := NULL;
    BEGIN
    ldsw.delete_test_info;
    v_students_test1 := v_num_students * .95;
    v_students_test2 := v_students_test1 * .80;
    FOR rec IN grade_cur
    LOOP
    v_counter := v_counter + 1;
    IF v_counter <= v_num_students
    THEN
    v_student_id := 'S' &#0124; &#0124; TO_CHAR (v_counter);
    v_test_score := random.rand_max (80) + 20;
    v_course_final_grade := random.rand_max (4);
    IF v_counter < ROUND (v_num_students * .20)
    THEN
    v_course1 := 'C1';
    v_course2 := 'C2';
    v_course3 := 'C3';
    ELSIF v_counter BETWEEN ROUND (v_num_students * .20) AND ROUND (v_num_students * .40)
    THEN
    v_course1 := 'C2';
    v_course2 := 'C1';
    v_course3 := 'C3';
    ELSIF v_counter BETWEEN ROUND (v_num_students * .40) AND ROUND (v_num_students * .60)
    THEN
    v_course1 := 'C3';
    v_course2 := 'C1';
    v_course3 := 'C2';
    ELSIF v_counter BETWEEN ROUND (v_num_students * .60) AND ROUND (v_num_students * .80)
    THEN
    v_course1 := 'C3';
    v_course2 := 'C1';
    v_course3 := 'C2';
    ELSE
    v_course1 := 'C4';
    v_course2 := 'C2';
    v_course3 := 'C3';
    END IF;
    SELECT ldsw.get_grade (rec.birth_date)
    INTO v_student_grade
    FROM DUAL;
    IF v_counter <= v_students_test1
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course1,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course1,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    IF v_counter <= v_students_test2
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course1,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course1,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    IF v_counter <= v_students_test1
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course2,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course2,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    IF v_counter <= v_students_test2
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course2,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course2,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    IF v_counter <= v_students_test1
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course3,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course3,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    IF v_counter <= v_students_test2
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course3,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course3,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    IF v_counter <= v_students_test1
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course4,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course4,
    'ACH1999',
    TO_DATE ('01-SEP-1999', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    IF v_counter <= v_students_test2
    THEN
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course4,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    v_test_score);
    ELSE
    INSERT INTO studentfacts
    VALUES (v_student_id,
    v_course4,
    'ACH2000',
    TO_DATE ('01-JUN-2001', 'DD-MON-YYYY'),
    v_student_grade,
    v_course_final_grade,
    NULL);
    END IF;
    END IF;
    END LOOP;
    END add_tests;
    END ldsw;
    Save the file.
    SQL> START ldsw
    Package created.
    Package body created.
    SQL> EXECUTE ldsw.add_tests
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM student_facts;
    null

  • PL/SQL - Using procedure parameters inside cursor definition.

    Hello all,
    I'm currently working on a procedure that has a cursor in it. The only parameter passed in when calling it is a table name (TABLE_NAME parameter) which I want to use as a string in a LIKE comparison inside the defined cursor.
    Here is the code:
    PROCEDURE PURGE (TABLE_NAME IN VARCHAR)
        IS
            CURSOR TABLES_CUR
            IS
                SELECT
                    OBJECT_NAME
                FROM
                    SYS.DBA_OBJECTS
                WHERE
                    OWNER = 'MYSCHEMA'
                    AND OBJECT_TYPE = 'TABLE'
                    AND OBJECT_NAME like 'TABLE_NAME_%'
                    AND CREATED = sysdate-3;
            TABLE_DEL TABLES_CUR%rowtype;
        BEGIN
            OPEN TABLES_CUR;
            LOOP
                FETCH TABLES_CUR INTO TABLE_DEL;
                EXIT WHEN TABLES_CUR%NOTFOUND;
                DBMS_OUTPUT.PUT_LINE('TABLE_DEL');
            END LOOP;
            CLOSE TABLES_CUR;
        END PURGE;However TABLE_NAME parameter value is not being interpolated, so cursor ends up returning nothing.
    What must I do to get it interpolated and not interpreted as a literal string?
    Thanks in advance.
    Frank.

    Alex Nuijten wrote:
    OBJECT_NAME like your_parameter||'%'
    That's it, thanks a lot Alex.
    I'm such a stupid.. :(

  • Call procedure with return cursor

    Dear All,
    there is a cast with my job. i have procedure like below:
    CREATE OR REPLACE PROCEDURE ISISALL.P_TEST (PARAM1 IN VARCHAR2,RETURN_TABLE OUT SYS_REFCURSOR) IS
    BEGIN
    OPEN RETURN_TABLE FOR
    SELECT FIELD2,FIELD3 FROM MYTABLE
    WHERE FIELD1=PARAM1;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    WHEN OTHERS THEN
    -- Consider logging the error and then re-raise
    RAISE;
    END P_TEST;
    my question, How to call the procedure ? i want insert table with source from the procedure (P_TEST)..

    >
    How to call the procedure ? i want insert table with source from the procedure (P_TEST)..
    >
    This code sample that you can test in the SCOTT schema should give you enough information
    CREATE OR REPLACE TYPE SCOTT.local_type IS OBJECT (
        empno   NUMBER(4),
        ename   VARCHAR2(10));
    CREATE OR REPLACE TYPE SCOTT.local_tab_type IS TABLE OF local_type;
    CREATE OR REPLACE PACKAGE SCOTT.test_refcursor_pkg
    AS
        TYPE my_ref_cursor IS REF CURSOR;
         -- add more cursors as OUT parameters
         PROCEDURE   test_proc(p_ref_cur_out OUT test_refcursor_pkg.my_ref_cursor);
    END test_refcursor_pkg;
    CREATE OR REPLACE PACKAGE BODY SCOTT.test_refcursor_pkg
    AS
         PROCEDURE  test_proc(p_ref_cur_out OUT test_refcursor_pkg.my_ref_cursor)
         AS
            l_recs local_tab_type;
         BEGIN
             -- Get the records to modify individually.
             SELECT local_type(empno, ename) BULK COLLECT INTO l_recs
             FROM EMP;
             -- Perform some complex calculation for each row.
             FOR i IN l_recs.FIRST .. l_recs.LAST
             LOOP
                 DBMS_OUTPUT.PUT_LINE(l_recs(i).ename);
             END LOOP;
             -- Put the modified records back into the ref cursor for output.  
             OPEN p_ref_cur_out FOR
             SELECT * from TABLE(l_recs);      
             -- open more ref cursors here before returning
         END test_proc;
    END;
    SET SERVEROUTPUT ON SIZE 1000000
    DECLARE
      l_cursor  test_refcursor_pkg.my_ref_cursor;
      l_ename   emp.ename%TYPE;
      l_empno   emp.empno%TYPE;
    BEGIN
      test_refcursor_pkg.test_proc (l_cursor);
      LOOP
        FETCH l_cursor
        INTO  l_empno, l_ename;
        EXIT WHEN l_cursor%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(l_ename || ' | ' || l_empno);
      END LOOP;
      CLOSE l_cursor;
    END;
    /Are you sure you wouldn't be better off using a PIPELINED function instead? Then you can just select from it as if it were a table and do whatever you want with the data
    -- type to match emp record
    create or replace type emp_scalar_type as object
      (EMPNO NUMBER(4) ,
       ENAME VARCHAR2(10),
       JOB VARCHAR2(9),
       MGR NUMBER(4),
       HIREDATE DATE,
       SAL NUMBER(7, 2),
       COMM NUMBER(7, 2),
       DEPTNO NUMBER(2)
    -- table of emp records
    create or replace type emp_table_type as table of emp_scalar_type
    -- pipelined function
    create or replace function get_emp( p_deptno in number )
      return emp_table_type
      PIPELINED
      as
       TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
        emp_cv EmpCurTyp;
        l_rec  emp%rowtype;
      begin
        open emp_cv for select * from emp where deptno = p_deptno;
        loop
          fetch emp_cv into l_rec;
          exit when (emp_cv%notfound);
          pipe row( emp_scalar_type( l_rec.empno, LOWER(l_rec.ename),
              l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno ) );
        end loop;
        return;
      end;
    select * from table(get_emp(20))

  • Procedure error with cursor

    I am creating a procedure to update the value (unique id) using cursor.the result is not what i want, it is updating all the rows,it seems that
    where current of is not working in " WHERE CURRENT OF CUR_CPN;"
    Declare
    CURSOR CUR_CPN IS
         SELECT * FROM CPN_MASTER_TEMP FOR UPDATE;
         VAL NUMBER(5);
         UNI_VAL NUMBER(15);
    BEGIN
         FOR R1 IN CUR_CPN
    LOOP
              SELECT ZONE_DETAILS_DATA.UTM_ZONE,ZONE_DETAILS_DATA.UNIQUE_ID INTO VAL,UNI_VAL FROM ZONE_DETAILS_DATA;
              --SELECT ZONE_DETAILS_DATA.UTM_ZONE INTO VAL FROM ZONE_DETAILS_DATA;
              --SELECT ZONE_DETAILS_DATA.UNIQUE_ID INTO UNI_VAL FROM ZONE_DETAILS_DATA;     
         IF R1.UTM_ZONE=VAL THEN
              UPDATE CPN_MASTER_TEMP SET ZONE_DETAIL_ID_TEMP=UNI_VAL WHERE CURRENT OF CUR_CPN;
         END IF;
         END LOOP;
    END;
    output is as follows
    SQL> SELECT ZONE_DETAIL_ID_TEMP FROM CPN_MASTER_TEMP;
    ZONE_DETAIL_ID_TEMP
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    20 rows selected.
    the output should be only for rows where uniqueid is existing, now it is updating all rows
    please suggest help
    thankx

    select the rows only you want to update in cursor select condition
    Edited by: 781237 on Jul 10, 2010 4:45 AM

  • Procedures declaring a cursor

    Hi ,
    I have the following I am declaring a cursor within a procedure before a BEGIN - How can i decalre the cursor inside the the procedure
    as this is not correct below ?
    Something like so :
    PROCEDURE abc(
    table_name IN VARCHAR2)
    IS
    --v_sql varchar2(4000); 
    DECLARE
    temp VARCHAR(20);
    CURSOR ...................IS
    BEGIN
    using the cursor
    END
    Edited by: user618557 on Feb 25, 2009 3:47 AM

    user618557 wrote:
    Thanks that worked ...That's good.
    As to your new question; I have no idea as to what you are trying to do.
    Ever seen this?
    SQL> select dbms_metadata.get_ddl ('TABLE', 'EMP', 'SCOTT') from dual
    DBMS_METADATA.GET_DDL('TABLE','EMP','SCOTT')                                   
      CREATE TABLE "SCOTT"."EMP"                                                   
       (     "EMPNO" NUMBER(4,0) NOT NULL ENABLE,                                      
         "ENAME" VARCHAR2(10),                                                         
         "JOB" VARCHAR2(9),                                                            
         "MGR" NUMBER(4,0),                                                            
         "HIREDATE" DATE,                                                              
         "SAL" NUMBER(7,2),                                                            
         "COMM" NUMBER(7,2),                                                           
         "DEPTNO" NUMBER(2,0)                                                          
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING          
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645        
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)             
      TABLESPACE "USERS"                                                           
    1 row selected.Regards
    Peter

Maybe you are looking for

  • Contacts appointments not synching after upgrading to ios6

    Most of my appointments and some of my contacts aren't showing up on my iTouch after synching with my iMac since i upgraded to ios6.

  • Please advise about internal hard drive

    I just ordered this internal hard drive from Mac Mall... Seagate Barracuda 7200.12 1TB Internal SATA 3Gb/s Hard Drive (ST31000528AS) http://www.macmall.com/p/product~dpno~7758831~pdp.fddjgjb The phone person said it's compatible with my Mac Pro from

  • IPod Nano data recovery

    Hi. I own an iPod Nano, and yesterday, I accidentally dropped it into a sink. It flashed a message about firewire connections and prompty shut off. Now, I tried to turn it on, about 5 times, and plugged it in once, so it's probably gone. But here's m

  • CS5 Audio Playback Issue

    I can't get an audio file to play for longer than 1 second without stopping.  Don't see anything in any setting that would affect this.  Any ideas? I just installed Soundbooth CS5.  I opened a mono, 9 minute mp3 file, 32000 Hz, 4.36 MB. I have tried

  • 4GB HBAs on a 66mhz 64-bit PCI-X Bus

    I have some older servers that are having issues and I believe the bus speed might be the cause. I'm actually a storage guy, not a UNIX admin. I'm trying to identify why I have some slow-drain devices on my switches and I believe the Bus speed on som