Query on cursors in procedures

hi, I have been trying to pass a tablename as a parameter in a procedure. This tablename I then need to use in a cursor .
my code is something like this.
create procedure abc (tablename varchar2)
is
cursor xyz is select rowid from tablename;
But for some reason I can't access the tablename from that cursor. I get an error saying
PL/SQL: SQL Statement ignored
PL/SQL: ORA-00942: table or view does not exist.
Please assist

Hi,
you can use rowid type for the array. Moreover, you can use dynamic sql with bulk collect option. For instance:
oradev> select * from v$version;
BANNER
Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
PL/SQL Release 9.2.0.6.0 - Production
CORE 9.2.0.6.0 Production
TNS for Solaris: Version 9.2.0.6.0 - Production
NLSRTL Version 9.2.0.6.0 - Production
oradev> create table a1(c1 int);
Table created.
oradev> insert into a1 select rownum from all_objects;
34466 rows created.
oradev> create or replace procedure proc1 (table_name varchar2, num_rows out int)
2 as
3 type tr is table of rowid index by binary_integer;
4 vs varchar2(1000);
5 arr tr;
6 begin
7 vs := 'select rowid from '||table_name;
8 execute immediate vs bulk collect into arr;
9 num_rows := arr.count;
10 end;
11 /
Procedure created.
oradev> var n number
oradev> exec proc1('A1', :n)
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.06
oradev> print :n
N
34466
Andrey

Similar Messages

  • Error : The label 'http' has already been declared. Label names must be unique within a query batch or stored procedure.

    Hi all,
        I have created one SP for sending mail with formatting the HTML code inside script whenever i am individually declaring it and printing its expected but the problem at time of executing SP its giving error like this
    Msg 132, Level 15, State 1, Line 47
    The label 'http' has already been declared. Label names must be unique within a query batch or stored procedure.
    what is the possibilities to overcome this problem follwing is my stored procedure code 
    ALTER PROCEDURE [dbo].[USP_DataLoadMailsend_essRules]
    AS
    BEGIN
    SET NOCOUNT ON;
    SET XACT_ABORT ON;
    BEGIN TRY
    ---BEGIN TRANSACTION T1
    DECLARE @packagelogid INT
    DECLARE @batchlogid INT
    DECLARE @packagestatus CHAR(2)
    select @batchlogid =19870
    --print(@batchlogid)
    DECLARE @script VARCHAR(MAX)
    DECLARE @tableHTML VARCHAR(MAX)
    DECLARE @mailheader VARCHAR(50)
    DECLARE @count INT
    DECLARE @recipients1 VARCHAR(50)
    DECLARE @subject1 VARCHAR(200)
    DECLARE @sql VARCHAR(MAX)
    Declare @UserId varchar(Max)
    Declare @Information varchar(max)
    Declare @TableHTML1 varchar(max)
    Declare @TableHTML2 varchar(max)
    SET @mailheader = ''
    SET @mailheader = (select case
    WHEN FileUpload = 'F'
    THEN 'BussinessRules is Aborted'
    WHEN (InRule = 'S')
    AND (
    SELECT sum(isnull(ErrorRecords, 0)) tot
    FROM abc.FileUploadSummary z
    WHERE z.BatchId = bts.BatchId
    GROUP BY BatchId
    ) > 0
    THEN 'BussinessRules is Processed with Errors'
    WHEN InRule = 'F'
    THEN 'BussinessRules is Failed'
    WHEN (InRule = 'S')
    AND (
    SELECT sum(isnull(ErrorRecords, 0)) tot
    FROM abc.FileUploadSummary z
    WHERE z.BatchId = bts.BatchId
    GROUP BY BatchId
    ) = 0
    THEN 'BussinessRules is Succeeded'
    end
    from abc..BatchStatus bts where BatchId=@batchlogid)
    /* Selecting Person Mail as Recipient */
    SELECT TOP 1 @recipients1 = EmailId FROM abc.PersonEmail
    WHERE PersonId = ( SELECT TOP 1 personid FROM abc.FileUploadSummary WHERE BatchId = @batchlogid )AND EmailTypeId = 1
    /* Selecting UserId*/
    select top 1 @UserId=loginid from abc.FUS where BatchId=@batchlogid
    /*Selecting Information about the Status */
    Set @Information=
    (select case
    WHEN FileUpload = 'F'
    THEN 'BussinessRules is Aborted'
    WHEN (InRule = 'S')
    AND (
    SELECT sum(isnull(ErrorRecords, 0)) tot
    FROM abc.FileUploadSummary z
    WHERE z.BatchId = bts.BatchId
    GROUP BY BatchId
    ) > 0
    THEN 'BussinessRules is Processed with Errors'
    WHEN InRule = 'F'
    THEN 'BussinessRules is Failed'
    WHEN (InRule = 'S')
    AND (
    SELECT sum(isnull(ErrorRecords, 0)) tot
    FROM abc.FileUploadSummary z
    WHERE z.BatchId = bts.BatchId
    GROUP BY BatchId
    ) = 0
    THEN 'BussinessRules is Succeeded'
    end + N' <br> <B>BatchId= '+ convert(varchar(250),(select @batchlogid)) +'</B>'
    from abc..BatchStatus bts where BatchId=@batchlogid )
    /*Selecting the Error Reason*/
    if exists (select 1 from BatchStatus where BatchId=@batchlogid and ( InRule='f'))
    begin
    set @TableHTML1 = '<table border=1><tr><th>Sr.No.</th><th><P>Error Reason :</th></tr>'+
    cast((select td= ROW_NUMBER()over (order by (select 1)),'',
    td=isnull(e.ErrorDescription, '')
    from abc.x.tbPackageErrorLog e --50594
    join abc.x.tbPackageLog p -- 10223
    on p.PackageLogID=e.PackageLogID
    where p.BatchLogID= @batchlogid FOR XML PATH('tr'), TYPE )
    as NVarchar(max)) +'</table>'
    -- print @tableHTML
    if not exists (select 1 from BatchStatus where BatchId=@batchlogid and ( InRule='f'))
    set @TableHTML2 = 'Error Reason :N/A'
    end
    -- insert into #tmp values ( @TableHTML1)
    --select * from #tmp
    Set @tableHTML= 'Hello '+@UserId+', <br>Information:'+isnull(@Information,'') +
    '<Table Border=1><Tr><th>Sr No</th><th>Uploaded files </th>:'+
    CAST ((select td= ROW_NUMBER()over(order by f.FileUploadId), '',
    td = f.TableName , ''
    from abc.FileUploadSummary F where BatchId=@batchlogid
    FOR XML PATH('tr'), TYPE ) AS NVARCHAR(max) )
    +'</table>'+
    'Error Reason :'+isnull(isnull(@TableHTML1,'')+ isnull(@TableHTML2,''),'N/A')+ --concat (isnull(@TableHTML1,''),isnull(@TableHTML2,'')
    '<br> Please login to Your Account for further Details..!'
    +'<br>@Note: This is system generated message, Do not reply to this mail. <br>Regards,<br>'+
    'Admin'
    print @tableHTML
    SET @sql = ' EXEC msdb.dbo.sp_send_dbmail @profile_name = ''DBA_mail_test''
    ,@recipients = ''' + isnull(@recipients1,'''') + ''',@subject = ''' + isnull(@mailheader,'''') + ''',
    @body = ''' +isnull(@tableHTML,'''')+ ''',
    @body_format = ''HTML'''
    Exec(@sql)
    END TRY
    BEGIN CATCH
    PRINT error_message()
    -- Test whether the transaction is uncommittable.
    -- IF (XACT_STATE()) = - 1
    -- ROLLBACK TRANSACTION --Comment it if SP contains only select statement
    DECLARE @ErrorFromProc VARCHAR(500)
    DECLARE @ErrorMessage VARCHAR(1000)
    DECLARE @SeverityLevel INT
    SELECT @ErrorFromProc = ERROR_PROCEDURE()
    ,@ErrorMessage = ERROR_MESSAGE()
    ,@SeverityLevel = ERROR_SEVERITY()
    --INSERT INTO dbo.ErrorLogForUSP (
    -- ErrorFromProc
    -- ,ErrorMessage
    -- ,SeverityLevel
    -- ,DateTimeStamp
    --VALUES (
    -- @ErrorFromProc
    -- ,@ErrorMessage
    -- ,@SeverityLevel
    -- ,GETDATE()
    END CATCH
    END
    please help me to solve this problem
    Niraj Sevalkar

    This is no string http in your procedure. Then again the error message points to a line 47 outside a stored procedure. I can't tell it is outside, since there is no procedure name.
    But I see that you have this piece of dynamic SQL:
    SET @sql = ' EXEC msdb.dbo.sp_send_dbmail @profile_name = ''DBA_mail_test''
    ,@recipients = ''' + isnull(@recipients1,'''') + ''',@subject = ''' + isnull(@mailheader,'''') + ''',
    @body = ''' +isnull(@tableHTML,'''')+ ''',
    @body_format = ''HTML'''
     Exec(@sql)
    Why is this dynamic SQL at all? Why not just make plain call to sp_send_dbmail?
     EXEC msdb.dbo.sp_send_dbmail @profile_name = 'DBA_mail_test'
    ,@recipients = @recipients1, @subject = @mailheader, @body = @tableHTML
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Query for records on a block with Query Data Source Type : Procedure

    Hi All,
    The veriosn of form I'm using is:
    Forms [32 Bit] Version 6.0.8.23.2
    I have a block based on a procedure.
    But when I enetr-query and search for records specific to ceratin criteria even then the result of the Query is all records.
    Is Query not allowed on a block with Query Data Source Type : Procedure.
    Hope my question is clear.
    Thanks in advance.
    Regards
    Arif

    When you use a table based block, forms can construct any select with any where clause based on the given inputs. Using a procedure based block, forms cannot "know" which in or out parameter of the procedure corresponds to which item. Even if Forms could pass the value of an item to an argument automagically, the procedure would have to "do something" with the argument, and you´d have to code it.
    So, any item that should be used in the where-clause must be mapped to an argument.
    Perhaps it would be easier to use a table based block querying a view? For DDL, you could use an instead-of-trigger on the view.
    Regards,
    Gerd

  • Query slower in stored procedure(after upgrade to 16)

    Hi all,
    We are looking to upgrade our SQL Anywhere 9 database to 16. We thought version 16 is slower in update tables, but the reason of slowness are query's in stored procedures called from the trigger. One of the query's has a duration of 8 times the duration in version 9!! When I run the query in Interactive Sql(v16), they run fast like version 9. So the query runs slower in a stored procedure.
    I thought parameter sniffing, but it's not MS Sql Server. I've no idea why it was good in v9 and bad in v16. Have someone a idea?
    It's a query with subquery's in the where , a view in the from. In the view are unions. Looks not so special.
    thanks

    It may be more convenient for you to ask this question on the other forum: SAP SQL Anywhere Forum
    Preamble...
    It sometimes happens that (a) the same query will perform faster or slower in different versions because of different behaviors by the query optimizer. In most cases a minor change is necessary to restore good performance; in some rare cases, the changes are difficult.
    It also sometimes happens that (b) the same query will perform faster or slower under different operating conditions; e.g., client request (ISQL) versus inside a BEGIN block (stored procedure). Again, minor changes all that's required in most cases, sometimes otherwise.
    Details...
    In order to help, we will need more information. Two graphical plans with statistics for the same problematic query, both using V16, one captured in ISQL, and the other one captured inside the stored procedure, is the best way to pass on the information; ALL OTHER forms are inadequate, especially prose descriptions and edited snippets of code (that way lies frustration for all parties).
    There are a number of articles about graphical plans on this blog.

  • How return parameter ref Cursor from procedure using dynamic SQL?

    I sorry, but i very need help.
    I using Oracle 8.0.6
    I need to return parameter of type ref Cursor from procedure.
    create or replace package PlanExp is
    type cursortype is ref cursor;
    procedure ShowPlan (cursorparam out
    cursortype.............);
    end PlanExp;
    create or replace package body PlanExp is
    procedure ShowPlan (cursorparam out cursortype,
    .............) Is
    sql_str varchar2(1000);
    sql_str_select varchar2(100);
    sql_str_from varchar2(100);
    sql_str_where varchar2(500);
    Return_Code integer;
    Num_Rows integer;
    cur_id_sel integer;
    tSum_Plan DBMS_SQL.NUMBER_TABLE;
    tSum_Plan_Ch DBMS_SQL.NUMBER_TABLE;
    tSum_Plan_Day DBMS_SQL.NUMBER_TABLE;
    begin
    /* calculating string variables ........... /*
    sql_str := 'select ' || sql_str_select ||
    'from ' || sql_str_from ||
    'where ' || sql_str_where ||
    'group by ' || sql_str_select;
    cur_id_sel := dbms_sql.open_cursor;
    dbms_sql.parse(cur_id_sel, sql_str, dbms_sql.native);
    dbms_sql.define_array(cur_id_sel, 1, tSum_Plan, 20, 1);
    dbms_sql.define_array(cur_id_sel, 2, tSum_Plan_Ch, 20, 1);
    dbms_sql.define_array(cur_id_sel, 3, tSum_Plan_Day, 20, 1);
    Return_Code := dbms_sql.execute(cur_id_sel);
    delete from TEMP_SHOWPLAN;
    Loop
    Num_Rows := dbms_sql.Fetch_Rows(cur_id_sel);
    dbms_sql.column_value(cur_id_sel, 1, tSum_Plan);
    dbms_sql.column_value(cur_id_sel, 2, tSum_Plan_Ch);
    dbms_sql.column_value(cur_id_sel, 3, tSum_Plan_Day);
    if Num_Rows = 0 then
    exit;
    end if;
    Exit When Num_Rows < 20;
    End Loop;
    dbms_sql.close_cursor(cur_id_sel);
    end;
    end PlanExp;
    How return cursor (cursorparam) from 3 dbms_sql.column_value-s ?

    I am using Oracle 8.1.7, so I don't know if this will work in
    8.0.6 or not:
    SQL> CREATE TABLE test
      2    (col1                    NUMBER,
      3     col2                    NUMBER,
      4     col3                    NUMBER)
      5  /
    Table created.
    SQL> INSERT INTO test
      2  VALUES (1,1,1)
      3  /
    1 row created.
    SQL> INSERT INTO test
      2  VALUES (2,2,2)
      3  /
    1 row created.
    SQL> INSERT INTO test
      2  VALUES (3,3,3)
      3  /
    1 row created.
    SQL> CREATE TABLE temp_showplan
      2    (tSum_Plan               NUMBER,
      3     tSum_Plan_Ch            NUMBER,
      4     tSum_Plan_Day           NUMBER)
      5  /
    Table created.
    SQL> EDIT planexp
    CREATE OR REPLACE PACKAGE PlanExp
    IS
      TYPE CursorType IS REF CURSOR;
      PROCEDURE ShowPlan
        (cursorparam    IN OUT CursorType,
         sql_str_select IN     VARCHAR2,
         sql_str_from   IN     VARCHAR2,
         sql_str_where  IN     VARCHAR2);
    END PlanExp;
    CREATE OR REPLACE PACKAGE BODY PlanExp
    IS
      PROCEDURE ShowPlan
        (cursorparam    IN OUT CursorType,
         sql_str_select IN     VARCHAR2,
         sql_str_from   IN     VARCHAR2,
         sql_str_where  IN     VARCHAR2)
      IS
        sql_str                VARCHAR2 (1000);
        cur_id_sel             INTEGER;
        return_code            INTEGER;
      BEGIN
        DELETE FROM temp_showplan;
        sql_str := 'INSERT INTO   temp_showplan '
               || ' SELECT '   || sql_str_select
               || ' FROM '     || sql_str_from
               || ' WHERE '    || sql_str_where;
        cur_id_sel := DBMS_SQL.OPEN_CURSOR;
        DBMS_SQL.PARSE (cur_id_sel, sql_str, DBMS_SQL.NATIVE);
        return_code := DBMS_SQL.EXECUTE (cur_id_sel);
        DBMS_SQL.CLOSE_CURSOR (cur_id_sel);
        OPEN cursorparam FOR SELECT * FROM temp_showplan;
      END ShowPlan;
    END PlanExp;
    SQL> START planexp
    Package created.
    Package body created.
    SQL> VARIABLE g_ref REFCURSOR
    SQL> EXEC PlanExp.ShowPlan (:g_ref, 'col1, col2,
    col3', 'test', ' 1 = 1 ')
    PL/SQL procedure successfully completed.
    SQL> PRINT g_ref
    TSUM_PLAN TSUM_PLAN_CH TSUM_PLAN_DAY
             1            1             1
             2            2             2
             3            3             3

  • How to out Dynamic ref cursor from Procedure to Forms

    Hi
    I am trying to out Dynamic ref cursor from Procedure to Forms, But I am unable to do so. however cursor return the value within procedure but I am failed to capture the same in Forms
    Pl advice suggestion if any, Here I am attaching full procedure for reference
    CREATE PACKAGE winepkg
    IS
    TYPE wine IS RECORD ( mynumber number);
    /* Define the REF CURSOR type. */
    TYPE wine_type IS REF CURSOR RETURN wine;
    END winepkg;
    CREATE procedure find_wine
    (col1_in in number,
    c1 out winepkg.wine_type) as
    vsql varchar2(1000);
    cur sys_refcursor;
    x number;
    BEGIN
    vsql:='select bo_id from bo_details where bo_details.bo_id = '||col1_in ;
    open cur for vsql;
    c1:=cur;
    --fetch c1 into x;
    --dbms_output.put_line(x);
    END find_wine;
    In front end forms
    Declare
    TYPE F is REF CURSOR;
    CUR_F F;
    rec number;
    Begin
    break;
    find_wine( 1601480000011078,cur_f ) ;
    Loop
    fetch cur_f into rec ;
    Message(rec ) ;pause;
    exit when cur_f%notfound ;
    End loop ;
    exception
    when others then
    Message(sqlerrm) ;pause;
    End ;

    yo can use
    declare
    c_cursor EXEC_SQL.CursType;
    v_stmt varchar2(2000) = 'select a, b, c from mytab where cond1'; -- you can create this value dynamically
    begin
    c_cursor := Exec_SQL.Open_cursor;
    EXEC_SQL.PARSE(c_articulos, v_stmt);
    EXEC_SQL.DEFINE_COLUMN(c_articulos,1, v_colchar1, 30);
    EXEC_SQL.DEFINE_COLUMN(c_articulos,2, v_colchar2, 15);
    EXEC_SQL.DEFINE_COLUMN(c_articulos,3, v_colchar3, 30);
    v_exec := EXEC_SQL.EXECUTE(c_cursor);
    WHILE EXEC_SQL.FETCH_ROWS(c_cursor) > 0 LOOP
    EXEC_SQL.COLUMN_VALUE(c_cursor,1,v_colchar1);
    EXEC_SQL.COLUMN_VALUE(c_c_cursor,2,v_colchar2);
    EXEC_SQL.COLUMN_VALUE(c_c_cursor,3,v_colchar3);
    assign_values_to_block;
    END LOOP;
    EXEC_SQL.CLOSE_CURSOR(c_cursor);
    end;
    and WORKS IN FORMS 6

  • How to Query a Cursor and retrieve a selected records

    Hi,
    I'm using a ScrollableCursor for pagination and it is working fine. Now i want to filter that cursor to get a selected records So i need to Query a cursor. Is it possible to Query a Cursor using Oracle Toplink.
    looking an api i found
    cursor.setSelectionCriteriaClone(expression)
    method is this method useful to apply the expression(Query) to the cursor. If it is possible then please send me the sample code.
    Thanks

    You cannot filter a Cursor, you would need the execute a new query (you could base your new query on the cursor's query's secltionCriteria though).
    James : http://www.eclipselink.org

  • I need return the result of a query on a stored procedure

    I need return the result of a query on a stored procedure, I mean when I execute a stored procedure it returns a result set as a select query.
    Best regards...

    If you want some pl/sql code that can be used in a query as it were a table you may be interested in table functions:
    SQL> create or replace type
      2  t_emp is object (
      3  name            varchar2(30),
      4  hire_date date,
      5  salary       number);
      6  /
    Tipo creato.
    SQL> create or replace type
      2  t_emptab is table of t_emp;
      3  /
    Tipo creato.
    SQL> create or replace function tab_fun(p_dept in number)
      2  return t_emptab is
      3  e t_emptab;
      4  begin
      5    select t_emp(ename,hiredate,sal)
      6      bulk collect into e
      7      from emp
      8     where deptno=p_dept;
      9
    10    return dip;
    11  end;
    12  /
    Funzione creata.
    SQL> select *
      2  from table(tab_fun(20));
    NAME                           HIRE_DATE  SALARY
    SMITH                          17-DIC-80        800
    JONES                          02-APR-81       2975
    SCOTT                          09-DIC-82       3000
    ADAMS                          12-GEN-83       1100
    FORD                           03-DIC-81       3000A procedure cannot be used in a select statement.
    Max
    http://oracleitalia.wordpress.com

  • Query to show what procedure isn´t assigned to any user!

    Hi all,
    I whant to know if anyone have a query that show all procedures from a specified user that is not granted the execute privilege to anyone!
    Tks,
    Paulo.
    i'm trying this one but don´t know if it is correct:
    select privilege, owner, table_name from dba_tab_privs
    where table_name not in (select object_name from dba_objects
    where object_type = 'PROCEDURE')
    and privilege = 'EXECUTE'
    and owner not in ('SYS','SYSTEM','XDB','DBSNMP','WMSYS')

    You can start to work with Pete Finnigan's script :
    http://www.petefinnigan.com/who_can_access.sql
    Nicolas.

  • How to return cursor from procedure to jdbc

    plz help me through example of code as wl as procedure where.... return cursor from procedure to jdbc

    SET QUOTED_IDENTIFIER OFF
    GO
    SET ANSI_NULLS OFF
    GO
    CREATE procedure anil3 @count INT OUT,@opcode INT OUT,@total_tiff INT OUT
    as
    declare @query2 varchar(300),@tiff_count int,@query1 varchar(300)
    set @query1='declare move_cursor   cursor forward_only static for
    select count(opcode),opcode from TABLE1 group by opcode
    open move_cursor'
    exec(@query1)
    fetch next  from move_cursor into @count,@opcode
    set @opcode="'"+@opcode+"'"
    set @total_tiff=0
    while (@@fetch_status=0)
    begin
         set @query2='declare move_cursor2  cursor static for '+
         ' select count(tiff) from TABLE2  where opcode='+@opcode+
           ' open move_cursor2 '
         exec(@query2)
         fetch next  from move_cursor2 into @tiff_count
         while (@@fetch_status=0)
         begin
              set @total_tiff=@total_tiff+@tiff_count
              fetch next  from move_cursor2 into @tiff_count
         end
         close move_cursor2
         deallocate move_cursor2
    print  @total_tiff
    print @count
    print @opcode
    fetch next  from move_cursor into @count,@opcode
    end
    close move_cursor
    deallocate move_cursor
    SET QUOTED_IDENTIFIER OFF
    GO
    SET ANSI_NULLS ON
    GO******************************************************************************
    above this is sql server 2000 PL/SQL and i hv to get the value
    print @total_tiff
    print @count
    print @opcode
    through JDBC
    plz help me out how to return Cursor to JDBC and HOW toPRINT THESE THREE VALUE @total_tiff, @count, @opcode through JDBC
    get this values through JDBC

  • Query data source type = procedure or from clause

    1)I have a form where a block is based on a from clause. In the source name I entered a simple sql statement.
    Isn't the items suppose to show without any other action or
    WHAT ELSE DO I NEED TO DO IN ORDER TO SEE THE BLOCK ITEMS EQUIVALENT TO THE COLUMNS IN THE QUERY?
    2) I have a form where a block is based on a procedure.
    First I created a package in a program unit with the procedures query_procedure, insert_procedure, update_procedure, delete_procedure and lock_procedure.
    Then I set the query data source name to the package query_procedure. The columns and arguments were automatically filled by Forms - they are fine as well.
    Forms automatically created the block triggers insert-procedure,delete-procedure, update-procedure and lock-procedure.
    Everything seems to be fine but when I run the form and execute the query I get frm 40505 - unable to perform query.
    What am i doing wrong?
    This is the package:
    PACKAGE pkgdeptemp IS
    type dept_emp is record (
    empno number(4),
    ename varchar2(10),
    job varchar2(9),
    hiredate date,
    sal number(7,2),
    deptno number(2),
    dname varchar2(14));
    success constant number :=0;
    type dept_emp_ref is ref cursor return dept_emp;
    type dept_emp_tab is table of dept_emp index by binary_integer;
    procedure query_procedure (resultset in out dept_emp_ref, p_empno in number);
    procedure lock_procedure (dmlset in out dept_emp_tab);
    procedure insert_procedure (dmlset in out dept_emp_tab);
    procedure update_procedure (dmlset in out dept_emp_tab);
    procedure delete_procedure (dmlset in out dept_emp_tab);
    END;
    PACKAGE BODY pkgdeptemp IS
    function get_success return number is
         begin
              return(success);
         end;
    procedure query_procedure (resultset in out dept_emp_ref, p_empno in number) is
    begin
         open resultset for
              select e.empno, e.ename, e.job, e.hiredate, e.sal, e.deptno, d.dname
              from emp e, dept d
              where e.deptno = d.deptno
              and e.empno = nvl(p_empno, e.empno);
    end query_procedure;
    procedure lock_procedure(dmlset in out dept_emp_tab) is
         tempout number(4);
    begin
         for i in 1..dmlset.count loop
              select empno
              into tempout
              from emp
              where empno = dmlset(i).empno
              for update;
         end loop;
    end lock_procedure;
    procedure insert_procedure (dmlset in out dept_emp_tab) is
         cursor c_dept (i binary_integer) is
         select deptno
         from dept
         where deptno = dmlset(i).deptno;
         tempout number(4);
    begin
         for i in 1..dmlset.count loop
              open c_dept(i);
              fetch c_dept into tempout;
              if c_dept%notfound then
                   insert into dept(deptno,dname)
                   values(dmlset(i).deptno, dmlset(i).dname);
              end if;
              close c_dept;
              insert into emp (empno,ename,job,hiredate,sal,deptno)
              values (dmlset(i).empno, dmlset(i).ename, dmlset(i).job, dmlset(i).hiredate, dmlset(i).sal, dmlset(i).deptno);
         end loop;
    end insert_procedure;
    procedure update_procedure (dmlset in out dept_emp_tab) is
         cursor c_dept (i binary_integer) is
         select deptno
         from dept
         where deptno = dmlset(i).deptno;
         tempout number(4);
    begin
         for i in 1..dmlset.count loop
              open c_dept(i);
              fetch c_dept into tempout;
              if c_dept%notfound then
                   insert into dept(deptno,dname)
                   values(dmlset(i).deptno, dmlset(i).dname);
              else
              update dept
              set deptno=dmlset(i).deptno,
              dname=dmlset(i).dname;
              end if;
              close c_dept;
         update emp
              set empno=dmlset(i).empno,
              ename=dmlset(i).ename,
              job=dmlset(i).job,
              hiredate=dmlset(i).hiredate,
              sal=dmlset(i).sal,
              deptno=dmlset(i).deptno;
         end loop;
    end update_procedure;
    procedure delete_procedure (dmlset in out dept_emp_tab) is
    begin
         for i in 1..dmlset.count loop
              delete from emp where empno = dmlset(i).empno;
         end loop;
    end delete_procedure;
    END;

    for ur q1:
    create the text items manually in the layout editor or in the obj navigator then specify there properties manually in the the pallette.
    database item = yes
    column name = field name in ur select statement
    for q2:
    try running the form again and press F8 then if an error occur press F1 or shift F1 to show the error in ur code.
    i suspect u forgot to specify a value for the in parameter the reason why u get an error that is specify the actual parameter for ur in argument then press F8.
    enjoy!

  • Cursors in Procedures

    hi, i am writing a procedure where initially a cursor stores student ids in c_st_id based on certain conditions. Now on the selected Student ids i have to perform more logic which will filter them again and the filrered student ids are stored in cursor c_nf_st_id . Here i want those student ids that are in the cursor c_st_id but not present in c_nf_st_id. Can anybody suggest me how do i perform subtraction in cursors so that i get those that are in first cursor and not present in second cursor.
    CURSOR c_st_id IS
    SELECT st_id FROM ci_st_char a,ci_st b
    where a.adhoc_char_val in( select value from st_val) and a.prem_id=b.char_prem_id and char_type_cd = 'PLOT# '
    and trim(sa_type_cd) in ('stfr',stre,stup,stbo) and st_status_flg in ('20','50')
    ) where r_num=1;
    cr_st_rec c_st_id%ROWTYPE;
    OPEN c_st_id;
    LOOP
    FETCH c_st_id INTO cr_st_rec;
    EXIT WHEN c_st_id%NOTFOUND;
    BEGIN
    CURSOR c_nf_st_id IS
    SELECT st_id FROM ci_ft a,ci_adj b where a.st_id = cr_st_rec.st_id and a.parent_id='PIDPLFEE '
    and a.sibling_id = b.adj_id and b.adj_status_flg in ('50')
    cr_nf_st_rec c_nf_st_id%ROWTYPE;
    END LOOP;
    CLOSE c_st_id;
    Edited by: chesplay on Dec 22, 2011 12:07 AM

    chesplay wrote:
    I should modify my main query where the st id's are taken and perform the second cursor filter there itself , rather than using two cursors? is my undstanding correct?All SQLs are cursors. So there is no getting away from not using cursors.
    The issue is how to effectively use that SQL cursor (and PL/SQL supplies a bunch of interfaces to interact with a SQL cursor).
    A SQL select cursor represents the truth at a specific point in time. A simple example.
    - At T1 you create a cursor for select * from emp.
    - At T2 you fetched 2 of the 100 emp rows.
    - At T3 the CEO in a fit of rage, fires all employees and the employee table content is deleted using a delete from emp cursor and the transaction is committed.
    - At T4 your code, using your select cursor fetches the next set of rows output by that cursor.
    What happens? There are no more rows in the table.
    Your cursor sees the truth at T1. And that is what it will return - all 100 rows. Despite the fact that the new truth (version) of that table says that there are no more rows in that table.
    So from a basic issue of consistency, you need to realise that a cursor itself is consistent. But when you (in the client side) compare or match results from one cursor with another cursor, these cursors can represent different versions of the truth.
    Therefore it is safer to provide both sets of logic for getting the data of interest, and adding the logic for comparing the data of interest, into a single SQL. This is executed as a single cursor - that will look at a single truth and single version of the data of interest.
    The added benefits to this is performance and scalability.
    There is no need for data having to be pulled from the SQL engine for PL/SQL to process - and often then push back to the very same SQL engine for use via yet another cursor.
    Instead of sending SQL data via a detour through the PL/SQL engine to be processed, a single SQL statement is tasked to do this. There's no need for context switching to the PL/SQL engine. No need for the SQL engine to send data to the PL/SQL engine.
    SQL can be parallelised. If the data is being processed by PL/SQL, that by default means a single serialised process. No scalability to deal with larger volumes - unless that PL/SQL code is redesigned and rewritten to support some form of (mostly manual) parallel processing.
    So data crunching is best done using SQL and using SQL alone. It is the best, most flexible, and most performant and scalable language to crunch database data. Only when the crunching is too complex for the SQL language to deal with, then it makes sense to use PL/SQL to fill that gap.
    The basic mantra for using SQL and PL/SQL: maximise SQL and minimise PL/SQL

  • Querying Block Based on Procedure

    I built the form based off the following thread:
    Form based on stored procedure
    However, the block created by the procedure does not appear to be queryable with any given criteria. Query Enter, enter criteria, Query Execute didn't work it still returns the all the data. I also tried putting in a default where clause, but that didn't work. Is there a way to query the result set returned?
    Thanks,
    Roschera

    Okay, now I've tried adding data source arguments to pass in a parameter to the cursor being used to generate the data. I've set the default value to null and double checked to make sure the same data types are being used, however, I'm still receiving an ORA-6502 error. Any help would be appreciated.
    Thanks,
    Roschera

  • URGENT!!passing variables to ref-cursor stored procedures

    I have build forms6 block base ona stored procedures with ref
    cursor.
    But....it's impossible to pass variables from block.item to
    in-out parameter of ref cursor..to make a where clause for
    example!!
    I've tried all..but nothing happens..
    Can someone help me?
    Thanks..
    null

    Manish Wadhwa (guest) wrote:
    : Gigi (guest) wrote:
    : : I have build forms6 block base ona stored procedures with ref
    : : cursor.
    : : But....it's impossible to pass variables from block.item to
    : : in-out parameter of ref cursor..to make a where clause for
    : : example!!
    : : I've tried all..but nothing happens..
    : : Can someone help me?
    : : Thanks..
    : >>
    : It is not possible to send values as parameter to the stored
    : procedure because, oracle uses the trigger query-procedure for
    : calling the stored procedure and it does not entertain any
    : changes to that trigger. This is a problem with block based on
    : stored procedure, we have also tried it with table of records
    : instead of ref cursor, but doesn't work.
    : Manish
    Thanks Manish..
    i was afraid about that..
    But ..i ask to myself(retoric question..) it's possible the
    development oracle team build a "black box" like a stored
    procedure with ref o table of records who permit to select
    million of records in few second( i selected 5 million of records
    in 2 seconds..) and cannot permit to passing variables to these
    cursor.. every end users production forms must be working in
    this way..I don't understand..
    Gigi
    null

  • Can not delete data from table which is queried in my stored procedure

    Hi,
    Anyone knows how to fix it:
    I have a table. In a stored procedure, I have a simple query running on this table.
    When I want to delete one record from that table, I got error message:
    ORA-04091: table *** is mutating, trigger/function may not see it.
    Thanks first.

    Rick, the only time you should get a mutating table error is when a trigger is involved. FK problems have separate error codes (and would be a different problem than the one that started this thread). Using a DBA id check all the tables subject to DML by your function and by whatever calls your function for triggers. Only the owner or a DBA can see the existence of triggers on a non-owned table. This has caused some of the developers I work with to think tables that had triggers do not have them since they do not work under the owning or a DBA ID.
    By your description of what you are trying to do in the function we do that all the time without problem.
    How large is the function? How/When is it called?
    Mark D Powell

Maybe you are looking for

  • How to supress the result in a query?

    Hi Experts! I have a query, and by default show results right / down. How can I set in design-mode that dont show any result? Thanks!

  • BPEL Process returns "empty variable/expression result."

    Hi, I have an Asynchronous BPEL Process which uses a DB Adapter (which in turn uses a custom SQL Procedure) to insert a value in to a table and return a sequence value generated in the procedure back to the BPEL Process. The process inserts the value

  • Latest version of NWDS

    Hi, I am using the NW developer studio 2.0.9. I need to know the latest version of NWDS. For doing applications in webdynpro for java Composite Environment 7.11 Ehp. Do I need to change only developer studio or I need to Upgrade the Netweaver. Thanks

  • ADDT file upload

    Hi people I'm making a document upload site for mainly pdf files with php and mysql and i'm using the developer toolbox file upload. I got it all to work except one thing - international charachters in the file names. I need to convert the signs to h

  • Kerberos support on iOS

    Hi, Currently I'm trying to run the kerberos sample code on iOS. There is a GSS framework in iOS SDK and I can use that to run the sample kerberos gss code on iOS. But there are two problems I met. Can't find GSS api to access the kerberos configurat