Fetch cursor types

Hello
I want to write a procedure that has parameters which are records in a table.
But I don't know how to search cursor type and then pass the result to the settings.
  
create or replace procedure out_student_names3
  (id out students.std_id%type,name out students.std_name%type)
  is
 type TYPE_STD is table of students.STD_ID%type ;
 type type_std_name is table of students.STD_NAME%type;
 type_1 type_std;
 type_2 type_name;
 cursor c is  select std_id ,std_name from students ;
  begin
OPEN C;
  LOOP
--fetch c into type_1,type_2;
 
exit when c%notfound; 
 
 end loop;
end;
/

A cursor is a memory structure where stored instructions to execute a SQL statement. There are 3 operation involved in the treatment of a slider they are OPEN, FETCH, and CLOSE. So to print a data in the cursor, you need to open the cursor, fetch the cursor, then close.

Client tools like SQLPlus offers an API to display the records of cursor. PRINT is a custom api provided by SQLPlus to print a cursor. You can use it. Here is an example.

SQL> create or replace procedure get_emp_detail(out_cursor out sys_refcursor)
  2  is
  3  begin
  4     open out_cursor for select empno, ename from emp;
  5  end;
  6  /

Procedure created.

SQL> var rc refcursor

SQL> exec get_emp_detail (:rc)

PL/SQL procedure successfully completed.

SQL> print rc

     EMPNO ENAME
---------- ----------------------------------------------------------------------------------------------------
         1 Karthick
         2 Karthick_1
         3 Ram
         4 Ram_1

SQL> 

Tags: Database

Similar Questions

  • Dynamic cursor Type strong?

    I am currently using Oracle 11.2 G and I was wondering if you can declare a dynamic cursor as a strong Ref Cursor type or it may be declared as weak type ref cursor? Now, if she can only be declared as a weak type Ref Cursor, is it possible to avoid having to explicitly declare the type names and field being returned by the cursor? Sense, is any way to avoid having to do something like that...
    TYPE example_rec IS RECORD
    (
     col1 VARCHAR2,
     col2 NUMBER,
     col3 NUMBER,
     etc...
    )
    Instead, I was wondering if I could just set the fields and their types by defining them as a TABLE OF THE ref cursor?

    I wonder if this is possible is because I have a large number of fields returned in my cursor, and I was hoping on not having to type each person and its type. In addition, I think this would make maintenance easier.

    user652714 wrote:
    No, not quite. I ask if I can create a strong dynamic type Ref cusors. Here is a Pseudo code:

    DECLARE
    TYPE test_rec IS TABLE OF test_cur%ROWTYPE; -- i'm wondering if i can do something like this
    --'The code below is what I am TRYING TO AVOID'
    TYPE test_cur IS REF CURSOR;
    TYPE test_rec IS RECORD
    (
    col1 VARCHAR2,
    col2 NUMBER,
    col3 NUMBEr
    )
    

    Is not possible.

    Let's say you would set an TEST_REC as above. How would refer to the members of the structure of your code? This type could describe anything like projection of the cursor could be anything - a unique column, to a 100 columns. A combination of columns that can include data types of the LOB of tables nested SQL types defined by the user.

    So, how can you refer to these columns in the structure of table TEST_REC ? Guess?

    A new concept - all SQL statements are parsed, stored and executed as sliders. REF CURSOR, cursors implicit, explicit cursors and so on, are CLIENT interfaces to the created SQL cursor. Each of these interfaces to client cursor works in a specific way and provide a set of specific features.

    Next concept - to extract a SQL cursor, the client code NEEDS to know the structure of the projection of this cursor SQL. The code needs to know the number and types of data in the columns returned by the cursor.

    The customer may address the issue in two ways.

    Statically. In other words, at the time of coding, SQL projection, returned by this SQL cursor is known. The developer can thus use some thing like + % RowType % + to indicate to the compiler that record structure to define. The compiler parses the SQL cursor in the code, describes the projection of SQL and compiles this projection of SQL as the static structure in the code.

    + % RowType + in this regard is as a #define of C macro. He tells the PL/SQL compiler to describe the cursor SQL projection, then produced a PL/SQL, based on the record structure.

    Dynamically. This means at the time of coding, SQL, returned by this SQL cursor is unknown. In this case the compiler has no idea at compile time what structure will be returned by the cursor. Compiled source code may not define a static structure for this cursor SQL - the SQL cursor may return any kind of structure. The source code needs to use the same approach as what the compiler does when it comes to SQL static cursors.

    The source code needs to analyze the cursor, describe the SQL cursor and then pick dynamically by the cursor. Client cursor interface that supports this approach is DBMS_SQL. No ref Cursor.

    Keep in mind that these static and dynamic methods to describe how the code consumes the cursor - extraction of rows in the cursor.

    A static method (where the projection of SQL is known) however apply to the TWO instructions static SQL and dynamic SQL statements. You can use dynamic SQL statements in your code, but a rule which stipulates that, regardless of the SQL code is waiting for a specific static SQL projection of this SQL cursor.

    The dynamic method (where the projection of SQL is unknown) is 'real' dynamic SQL - as the projection of SQL and are all two dynamic SQL code.

    Examples of Basic code:

    // STATIC SQL CURSOR
    SQL> create or replace procedure FooProc is
      2          cursor  c is select object_id, object_name from user_objects;
      3          type    TBuffer is table of c%RowType;
      4          buffer  TBuffer;
      5  begin
      6          open c;
      7          loop
      8                  fetch c bulk collect into buffer limit 100;
      9                  DBMS_OUTPUT.put_line( buffer.Count||' row(s) fetched.' );
     10                  exit when c%NotFound;
     11          end loop;
     12          close c;
     13  end;
     14  /
    
    Procedure created.
    
    SQL>
    SQL> exec FooProc
    100 row(s) fetched.
    43 row(s) fetched.
    
    PL/SQL procedure successfully completed.
    
    // STATIC SQL PROJECTION, BUT DYNAMIC SQL CURSOR
    SQL> create or replace procedure FooProc( c in out sys_refcursor ) is
      2          E_CURSOR_ERROR  exception;
      3          pragma exception_init( E_CURSOR_ERROR, -00932 );
      4          type    TRecord is record(
      5                          name varchar2(30),
      6                          value varchar2(100)
      7                  );
      8          type    TBuffer is table of TRecord;
      9          buffer  TBuffer;
     10  begin
     11          loop
     12                  fetch c bulk collect into buffer limit 100;
     13                  DBMS_OUTPUT.put_line( buffer.Count||' row(s) fetched.' );
     14                  exit when c%NotFound;
     15          end loop;
     16          close c;
     17  exception when E_CURSOR_ERROR then
     18          close c;
     19          raise_application_error(
     20                  -20000,
     21                  'Cursor projection contains an invalid data structure.'
     22          );
     23  end;
     24  /
    
    Procedure created.
    
    SQL> var c refcursor
    SQL> exec open :c for select object_id, object_name from user_objects;
    
    PL/SQL procedure successfully completed.
    
    SQL> exec FooProc( :c );
    100 row(s) fetched.
    43 row(s) fetched.
    
    PL/SQL procedure successfully completed.
    
    SQL> exec open :c for select object_id, object_name, created from user_objects;
    
    PL/SQL procedure successfully completed.
    
    SQL> exec FooProc( :c );
    BEGIN FooProc( :c ); END;
    
    *
    ERROR at line 1:
    ORA-20000: Cursor projection contains an invalid data structure.
    ORA-06512: at "BILLY.FOOPROC", line 19
    ORA-06512: at line 1
    
    // DYNAMIC SQL AND DYNAMIC SQL PROJECTION
    SQL> create or replace procedure FooProc( sqlSelect varchar2 ) is
      2          c               integer;
      3          rc              integer;
      4          colCnt          integer;
      5          fetchCnt        integer;
      6          projection      DBMS_SQL.DESC_TAB;
      7  begin
      8          --// ceate and parse the cursor
      9          c := DBMS_SQL.open_cursor;
     10          DBMS_SQL.parse(
     11                  c,
     12                  sqlSelect,
     13                  DBMS_SQL.native
     14          );
     15
     16          rc := DBMS_SQL.execute( c );
     17
     18          --// describe the sql projection
     19          DBMS_SQL.describe_columns( c, colCnt, projection );
     20
     21          --// the sql projection's fields/columns
     22          DBMS_OUTPUT.put_line( 'SQL projection:' );
     23          for i in 1..colCnt loop
     24                  DBMS_OUTPUT.put_line( '- '||projection(i).col_name );
     25          end loop;
     26
     27          --// fetch and process
     28          fetchCnt := 0;
     29          loop
     30                  rc := DBMS_SQL.fetch_rows( c );
     31                  exit when rc = 0;
     32                  --// use DBMS_SQL.column_value() to read fetched row's columns
     33                  fetchCnt := fetchCnt + 1;
     34          end loop;
     35          DBMS_OUTPUT.put_line( fetchCnt||' row(s) fetched.' );
     36
     37          DBMS_SQL.close_cursor( c );
     38  end;
     39  /
    
    Procedure created.
    
    SQL>
    SQL> exec FooProc( 'select object_id, object_name from user_objects' );
    SQL projection:
    - OBJECT_ID
    - OBJECT_NAME
    143 row(s) fetched.
    
    PL/SQL procedure successfully completed.
    
  • In Illustrator, how can I get the cursor type to effectively indicate WHERE the guy is going to start?

    I don't understand. What is the point of having a cursor type at all if the cursor position doesn't look like whatever the point type will begin in? I checked all the Options in the type menu and any leader is zero, so there is no lag anywhere, but when I click on a particular spot on the page, it's because that's where I hope to see the type. What a laugh! No placement type correct, will never be. It must be scooted in place. using the arrow. Is it possible to make the entry point makes it a resemblance to the point ' by clicking on '?

    I don't see a problem:

    Your paragraph palette has something inside in addition to zeros? My guess is that you have left a big indent in the first field.

  • Fetch cursor object type ref

    Hello! I have a Ref Cursor already opened by an external procedure. I need to fetch it in a table of objects like this
    CREATE OR REPLACE TYPE TAB_CUSTOM AS TABLE OF REC_CUSTOM;
    where
    CREATE OR REPLACE TYPE REC_CUSTOM AS OBJECT
    (
         my_id     NUMBER(6)
            .......
           ,CONSTRUCTOR FUNCTION REC_CUSTOM RETURN SELF AS RESULT
    )
    NOT FINAL;
    /
    a correct columns, types and size of the open cursor ref.

    How can this be accomplished?

    Something like:

    declare
        v_custom_tbl TAB_CUSTOM := TAB_CUSTOM();
    begin
        loop
          v_custom_tbl.extend;
          v_custom_tbl(v_custom_tbl.count) := REC_CUSTOM(null,...);
          fetch ref_cursor
            into v_custom_tbl(v_custom_tbl.count).my_id,
                 v_custom_tbl(v_custom_tbl.count)....,
                 v_custom_tbl(v_custom_tbl.count)....;
          exit when ref_cursor%notfound;
        end loop;
        v_custom_tbl.delete(v_custom_tbl.count);
    end;
    /
    

    SY.

    Published by: Solomon Yakobson on June 29, 2012 09:13

  • Iterating through a collection of cursor type give PLS-00306: wrong number or types of arguments in the call to "PUT_LINE '.

    I wrote the following anonymous block. He has a slider ""cur_total_tckt "who choose 6 columns."  A nested table 'total_tckt_colcn' is declared of type ""cur_total_tckt "."  In the dbms_output.put_line I want to print each item in my collection. It gives me the following error:

    PLS-00306: wrong number or types of arguments in the call to "PUT_LINE '.

    ORA-06550: line 29, column 2:

    PL/SQL: Statement ignored

    06550 00000 - "line %s, column % s:\n%s".

    I want to print all 6 columns of an element for 366 these elements.

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

    DECLARE
    CURSOR cur_total_tckt    
      is
      select t.ticket_id ticket_id, t.created_date created_date, t.created_by created_by, t.ticket_status ticket_status,
      t.last_changed last_changed, h.created_date closed_date
      from n01.cc_ticket_info t
      inner join n01.cc_ticket_status_history h
      on (t.ticket_id = h.ticket_id)
      where t.last_changed >= '6/28/2012 17:28:59' and t.last_changed < (sysdate + interval '1' day);

    type total_tckt_colcn
    is
      TABLE OF cur_total_tckt%rowtype;
      total_tckt_col total_tckt_colcn;
      total_coach_col total_tckt_colcn;
    begin
    total_tckt_col := total_tckt_colcn ();
    total_coach_col := total_tckt_colcn ();
      OPEN cur_total_tckt;
      loop
      fetch cur_total_tckt bulk collect into total_tckt_col limit 100;

      dbms_output.put_line(total_tckt_col.last);

      FOR i IN total_tckt_col.first..total_tckt_col.last
      loop

      -- dbms_output.put_line(total_tckt_col(i).ticket_id);          -- this line works
      dbms_output.put_line(total_tckt_col(i));                       -- this line gives error

      END LOOP;

      exit
      WHEN (cur_total_tckt%NOTFOUND);

      END LOOP ;
      CLOSE cur_total_tckt; 




    end;

    making reference to an element differs from the reference to a field in the record that is part of the collection.

    'dbms_output.put_line (total_tckt_col (i))' works if there is only a single element.

    will not work if this element has subcomponents. in your case it has subcomponents as fields in a record.

  • The stored procedure PL/SQL - t - it accept the custom Ref Cursor type?

    I am not able to compile the following procedure in the HR schema comes with default oracle... I use Oracle 11g Release 11.2.0.2.0 Express edition. It gives me an error (given after the code block):

    Block of code:
    CREATE OR REPLACE PROCEDURE TEST_REF IS
    DECLARE
    TYPE REF_EMP IS REF CURSOR RETURN % ROWTYPE EMPLOYEES;
    RF_EMP REF_EMP;
    V_EMP EMPLOYEES % ROWTYPE;
    BEGIN
    DBMS_OUTPUT. ENABLE (1000000);
    OPEN FOR RF_EMP
    SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID > 100;
    EXTRACT THE RF_EMP IN V_EMP;
    DBMS_OUTPUT. PUT_LINE (V_EMP. FIRST_NAME. ' ' || V_EMP. LAST_NAME);
    CLOSE RF_EMP;
    EXCEPTION
    WHILE OTHERS
    THEN DBMS_OUTPUT. PUT_LINE (SQLERRM);
    END TEST_REF;
    /

    Error:
    Errors in PROCEDURE TEST_REF:

    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    2/1 PLS-00103: encountered the symbol "DECLARE" when waiting for an a
    What follows:
    Start function < an ID > pragma procedure subtype type
    < between double quote delimited identifiers > delete the current cursor
    There are the external language prior
    The symbol 'start' is substituted for 'DECLARE' continue.

    16/13 PLS-00103: encountered the symbol "end-of-file" when waiting for him
    one of the following values:
    (begin case declare exit end exception for goto if loop mod)
    pragma raise return null select update while with

    Get rid of the DECLARED:

    SQL> CREATE OR REPLACE PROCEDURE TEST_REF IS
      2  TYPE REF_EMP IS REF CURSOR RETURN HR.EMPLOYEES%ROWTYPE;
      3  RF_EMP REF_EMP;
      4  V_EMP EMPLOYEES%ROWTYPE;
      5  BEGIN
      6  DBMS_OUTPUT.ENABLE(1000000);
      7  OPEN RF_EMP FOR
      8  SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID > 100;
      9  FETCH RF_EMP INTO V_EMP;
     10  DBMS_OUTPUT.PUT_LINE(V_EMP.FIRST_NAME || ' ' || V_EMP.LAST_NAME);
     11  CLOSE RF_EMP;
     12  EXCEPTION
     13  WHEN OTHERS
     14  THEN DBMS_OUTPUT.PUT_LINE(SQLERRM);
     15  END TEST_REF;
     16  /
    
    Procedure created.
    
    SQL> set serveroutput on
    SQL> exec TEST_REF;
    Donald OConnell
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • How to read my ref cursor return user defined cursor type

    Hello
    I have the types defined as follows:
    TYPE MY_RECORD IS RECORD (
    COL1 TABLE1.COL1%TYPE,
    COL2 TABLE1.COL2%TYPE
       );
    
    TYPE MY_CURSOR IS REF CURSOR
    RETURN MY_RECORD;
    It is used as a return type in a stored procedure.
    I have a pl/sql block, where I make a call to MS that returns this cursor.
    How to read individual values for SP?
    SQL> create or replace package pkg
    as
       type my_record is record (col1 emp.empno%type, col2 emp.ename%type);
    
       type my_cursor is ref cursor
          return my_record;
    
       procedure p (cur out my_cursor);
    end pkg;
    /
    Package created.
    
    SQL> create or replace package body pkg
    as
       procedure p (cur out my_cursor)
       as
       begin
          open cur for
             select   empno, ename
               from   emp
              where   rownum <= 2;
       end p;
    end pkg;
    /
    Package body created.
    
    SQL> declare
       cur     pkg.my_cursor;
       e_rec   pkg.my_record;
    begin
       pkg.p (cur);
    
       loop
          fetch cur into   e_rec;
    
          exit when cur%notfound;
          dbms_output.put ('Empno: ' || e_rec.col1);
          dbms_output.put_line ('; Ename: ' || e_rec.col2);
       end loop;
    
       close cur;
    end;
    /
    Empno: 7369; Ename: SMITH
    Empno: 7499; Ename: ALLEN
    PL/SQL procedure successfully completed.
    
  • How we prevent suddenly back in the mark cursor type?

    When you type numbers or letters in the words, emails etc. type suddenly will return to the cursor mark.  Is there a solution?

    This happened after my Dell 1720 pc crashed and "all" Windows Vista has been reinstalled.

    Hey Stan,

    Glad to know that the problem is solved. Let us know if face you any problems with Windows in the future.

  • Appellant the package with the cursor type and registration type variables

    Hello
    I tried the following package, which is similar to my requriement, the package has been successfully created, when you call it gives me error, the number of false arguments
    CREATE OR REPLACE PACKAGE Pkg_test1
    IS
      ----- Record Variable ----
      TYPE rec_job IS RECORD
       ( job varchar2(50),
         ename varchar2(50),
         sal number
       );
      TYPE typ_job IS TABLE OF rec_job;
      
      -- cursor declaration
      cursor emp_cur is select empno from  emp;
      TYPE emp_ttyp IS TABLE OF emp_cur%ROWTYPE INDEX BY PLS_INTEGER;
      ---- Procedure Declaration ----
    PROCEDURE proc_job ( p_cur IN   emp_ttyp,
                         o_Rat     OUT  typ_job );
     
    END Pkg_test1;
    /
    
    CREATE OR REPLACE PACKAGE BODY Pkg_test1
    IS
     
     PROCEDURE proc_job ( p_cur IN   emp_ttyp, o_Rat     OUT  typ_job )
      IS 
        -- Declare collection variable 
        l_typ_job typ_job; 
     
    BEGIN
       for i  in 1..p_cur.count loop
        select job,ename,sal bulk collect into l_typ_job
          from emp
          where empno=p_cur(i).empno ; 
    o_Rat:= l_typ_job;
    end loop;
    --Output
    for i in 1..o_rat.count loop
     DBMS_OUTPUT.PUT_LINE ( 'Output :'||o_rat(i).job||','||o_rat(i).ename||','||o_rat(i).sal );
      end loop;
    
    EXCEPTION
      WHEN OTHERS THEN 
           DBMS_OUTPUT.put_line('Procedure proc_job  - '|| SQLCODE|| '-'|| SQLERRM);
     END proc_job;
      end pkg_test1;
    /
    The package is created without errors
    But during the call, it gives me errors
    DECLARE 
      P_CUR PKG_TEST1.emp_ttyp;
      O_RAT PKG_TEST1.rec_job;
    BEGIN 
      PKG_TEST1.PROC_JOB ( P_CUR, O_RAT );
      COMMIT; 
    END; 
    Error is:
    PLS-00306: wrong number or types of arguments in call to 'PROC_JOB'
    Can you let me see how to overcome this error...

    Thank you..

    Published by: Smile on 9 may 2012 07:27
    SQL> DECLARE
      2  P_CUR PKG_TEST1.emp_ttyp;
      3  O_RAT PKG_TEST1.typ_job := PKG_TEST1.typ_job(null);
      4  BEGIN
      5  PKG_TEST1.PROC_JOB ( P_CUR, O_RAT );
      6  END;
      7  /
    Procedure proc_job  - -6531-ORA-06531: Reference to uninitialized collection
    
    PL/SQL procedure successfully completed.
    
    SQL> CREATE OR REPLACE PACKAGE BODY Pkg_test1
      2  IS
      3
      4   PROCEDURE proc_job ( p_cur IN   emp_ttyp, o_Rat     OUT  typ_job )
      5    IS
      6      -- Declare collection variable
      7      l_typ_job typ_job := typ_job();
      8
      9  BEGIN
     10     for i  in 1..p_cur.count loop
     11      select job,ename,sal bulk collect into l_typ_job
     12    from emp
     13    where empno=p_cur(i).empno ;
     14  o_Rat:= l_typ_job;
     15  end loop;
     16  --Output
     17  if o_rat is null then return; end if;
     18  for i in 1..o_rat.count loop
     19   DBMS_OUTPUT.PUT_LINE ( 'Output :'||o_rat(i).job||','||o_rat(i).ename||','||o_rat(i).sal );
     20    end loop;
     21  EXCEPTION
     22    WHEN OTHERS THEN
     23     DBMS_OUTPUT.put_line('Procedure proc_job  - '|| SQLCODE|| '-'|| SQLERRM);
     24   END proc_job;
     25    end pkg_test1;
     26  /
    Package body created.
    
    SQL> DECLARE
      2  P_CUR PKG_TEST1.emp_ttyp;
      3  O_RAT PKG_TEST1.typ_job;
      4  BEGIN
      5  PKG_TEST1.PROC_JOB ( P_CUR, O_RAT );
      6  END;
      7  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • Cursor type spans multiple lines of text. Photoshop CS6

    In Photoshop CS6 the blinking cursor of type through multiple lines of text (see image).

    typecursor.jpg

    Making it difficult to select text as it is difficult to say which line the select cursor will (see image).

    type_highlighted.jpg

    The text cursor can be resized?  This happens no matter what size of type is used or what paragraph settings are selected.  Everyone knows about this problem?  I use Windows 7 Professional, service pack 1 on a Dell Precision T3500 with 8.0 GB of RAM.

    Yes, the problem is Cambria. I included a link in the post with the details 4. You will need to find a similar font.

    Gene

  • Call function pipeline with entry as a record of cursor type parameter

    Hello

    I want result set of query curosr to function in pipeline and then proceed to Ref cusror for java application. I wrote the code below:
    CREATE OR REPLACE PACKAGE emp_pkg IS
    TYPE t_emp_rec IS RECORD(empid varchar2(5),last_name varchar2(25),email varchar2(25));
         
         type obj_t_emp_rec is table of t_emp_rec;
    
         CURSOR get_emp_data_cur(empid IN employee.employee_id%type)
         IS
              SELECT     EMPLOYEE_ID,LAST_NAME,EMAIL
              FROM     employee
              WHERE     employee_id=empid;
    
              --Rowtype for table
              TYPE t_emp IS TABLE OF get_emp_data_cur%ROWTYPE INDEX BY PLS_INTEGER;
    
              --Object for the table type created
              get_emp_rec t_emp;
    
         PROCEDURE Populate_emp_details(empid     IN     employee.employee_id%type,get_emp_rec     OUT     t_emp, result out sys_refcursor);
         
         function type_out(get_emp_rec in t_emp) return obj_t_emp_rec pipelined;
    
    END emp_pkg;
    /
    
    CREATE OR REPLACE PACKAGE BODY emp_pkg AS
    
    PROCEDURE Populate_emp_details(empid     IN     employee.employee_id%type,get_emp_rec     OUT     t_emp,result out sys_refcursor)
    IS
    
    BEGIN
    
         SELECT     EMPLOYEE_ID,LAST_NAME,EMAIL
         BULK COLLECT
         INTO     get_emp_rec
         FROM     employee
         WHERE     employee_id=empid;     
    
         open result for SELECT * FROM TABLE (type_out(get_emp_rec));     
    
    EXCEPTION
         when no_data_found then
              dbms_output.put_line('Invalid booking number entered');
    
    END Populate_emp_details;
    
    function type_out(get_emp_rec in t_emp) return obj_t_emp_rec pipelined
    as
    currec     t_emp_rec;
    begin
              for i in 1..get_emp_rec.count loop
                        pipe row(currec);
                        dbms_output.put_line('row count of rec -'|| get_emp_rec.count);
              end loop;
    end;
    
    END emp_pkg;
    /
    It gives me compilation error when you call the function pipeline (type_out (get_emp_rec)). Is it wrong to call pipelined function or please correct where I'm wrong.

    Help, please.

    Thank you

    Engine SQL doesn't know PL/SQL types.

    Really? :

    SQL> create or replace package emp_pkg
    is
      type t_emp_rec is record
      (
        empid       varchar2 (5),
        last_name   varchar2 (25),
        email       varchar2 (25)
      );
    
      type obj_t_emp_rec is table of t_emp_rec;
    
      cursor get_emp_data_cur (empid in employees.employee_id%type)
      is
        select employee_id, last_name, email
          from employees
         where employee_id = empid;
    
      --Rowtype for table
      type t_emp is table of get_emp_data_cur%rowtype;
    
      get_emp_rec t_emp;
    
      procedure populate_emp_details (empid in employees.employee_id%type);
    
      function type_out (empid in employees.employee_id%type) return obj_t_emp_rec pipelined;
    end emp_pkg;
    /
    Package created.
    
    SQL> create or replace package body emp_pkg
    as
    
      function type_out (empid in employees.employee_id%type)
        return obj_t_emp_rec pipelined
      as
        currec   t_emp_rec;
      begin
        populate_emp_details (empid);
    
        for i in 1 .. get_emp_rec.count
        loop
          currec.empid := get_emp_rec(i).employee_id;
          currec.last_name := get_emp_rec(i).last_name;
          currec.email := get_emp_rec(i).email;
          pipe row (currec);
          --dbms_output.put_line ('row count of rec -' || get_emp_rec.count);
        end loop;
        return;
      end type_out;
    
      procedure populate_emp_details (empid in employees.employee_id%type)
      is
      begin
        select employee_id, last_name, email
          bulk collect into get_emp_rec
          from employees
         where employee_id = empid;
    
      end populate_emp_details;
    
    end emp_pkg;
    /
    Package body created.
    
    SQL> select * from table(emp_pkg.type_out(114))
    /
    EMPID   LAST_NAME                             EMAIL
    ------- ------------------------------------- -------------------------------------
    114     Raphaely                              DRAPHEAL
    1 row selected.
    

    ;)

  • Followed, does not not for the cursor Type

    I just SC5. I remember when I wanted to address followed, I used to be able to just drag the icon in the character Panel. This doesn't seem to work now! I looked through prefs but can't seem to find anything to fix. Any thoughts are appreciated.

    Not in Illustrator, there no dynamic cursors as other applications such as After Effects

  • Problem with the cursor TYPE

    I have table with data week_tab

    week_num bkg1 bkg2 bkg_type
    1 10 20 at_prod
    2 40 10 at_serv
    3 30 20 prod
    2 20 60 at_prod
    1 10 50 at_serv
    1 20 80 at_net
    3 10 30 at_net

    I'm putting this request in a cursor

    SELECT SUM (bkg2), bkg_type
    OF week_tab
    WHERE bkg_type LIKE 'to %.
    GROUP BY bkg_type;

    PROCEDURE get_bkg_tot)
    p_colName IN VARCHAR2,
    p_refCursor OUT ref_cursor) AS

    v_query VARCHAR2 (4000);

    BEGIN
    v_query: = ' select sum('|| p_colName ||'), bkg_type
    of week_tab
    where bkg_type like: x
    Bkg_type group ';

    P_refcursor OPEN FOR v_query 'than ';
    END;
    --------------------------------------------------------------------------------
    PROCEDURE get_total_val AS
    v_refCursor ref_cursor;
    v_sum NUMBER;
    v_week NUMBER;
    v_total NUMBER: = 0;
    STRARRAY v_colName: = STRARRAY ('BKG1', 'BKG2');

    BEGIN

    I'm IN v_colName.FIRST... v_colName.Last LOOP

    get_bkg_tot ("bkg2", v_refcursor);
    LOOP
    EXTRACTION v_refCursor
    IN v_sum, v_week;
    EXIT WHEN v_refcursor % NOTFOUND;
    v_total: = v_total + v_sum;
    DBMS_OUTPUT. Put_line (' week ' | v_week |': ' | v_sum);
    END LOOP;
    DBMS_OUTPUT. Put_line (' total sales reservations :'|| v_total);

    END LOOP;
    END get_total_val;

    When I tried to run get_total_val, I get

    ORA-01722: invalid number
    ORA-06512: at "SCOTT. GET_TOTAL", line 45
    ORA-06512: at line 2

    What could be the error?

    Thanks in advance

    Well, look at the query behind your refcursor:

    v_query := 'select sum('||p_colName||'), bkg_type
    from week_tab
    where bkg_type like : x
    group by bkg_type';
    

    Based on your sample bkg_type is a string.

    Now consider the procedure get_total_val. It retrieves bkg_type in NUMBER variable v_week. No wonder you get ORA-01722: invalid number.

    SY.

  • type mismatch between cursor fetch and into clause

    Hi all
    Let us, considering what follows in the 11g:
    create table TEST1
    (
      ID   NUMBER(38),
      COL1 NUMBER(38)
    )
    tablespace USERS
      pctfree 10
      initrans 1
      maxtrans 255;
    CREATE OR REPLACE TYPE t_test IS OBJECT
    (
       id NUMBER(38),
       col1 NUMBER(38)
    )
    ;
    CREATE OR REPLACE TYPE t_test_table IS TABLE OF t_test
    and...

    declare
    
    cursor c is select 10 as id, 20 as col1 from dual connect by level < 1000;
    
    v_data t_test_table;
    
    begin
      
    
    open c;
    loop
      fetch c bulk collect into v_data limit 100;
      
      
      forall i in 1..v_data.count
        insert /*+ append_values */ 
        into test1 
        values(v_data(i).id, v_data(i).col1);
        
      exit when c%notfound;  
    
    end loop;
    close c;
    
    end;
    When we execute the statement we received the error:
    ORA-06550: line 13, column 29:
    PLS-00386: type mismatch found at 'V_DATA' between FETCH cursor and INTO variables
    ORA-06550: line 13, column 3:
    PL/SQL: SQL Statement ignored
    I know that a possibility here is to change the V_DATA type as being the rowtype cursor... consider that I want to use the v_data data after a DML operations in other / something like cast iron table process.


    Any ideas?


    Thanks in advance,
    Alexander.

    Could you remove the indication (append_values) and see?

  • Declare a cursor that can be played back in array of type

    Hello

    I have a problem - how to declare a cursor that can be played back in array of type.

    
    create or replace type testType as object  
    (  
      dokid number(10),          
      name varchar2(20)  
    );  
      
    CREATE OR REPLACE TYPE testTableType AS TABLE OF testType;  
      
    procedure test(  
         author in number      
    )   
    is  
      tempTable testTableType := testTableType();  
      --cursor type should be changed
      curs out sys_refcursor;
    begin  
         --open cursor  
         open curs for  
         select documentID, documentName from documents;
         
         --loop that fetches data
         loop
              FETCH curs 
              BULK COLLECT INTO tempTable LIMIT 100;
              --need bulk collect as table has too many records if used without bulk
              EXIT WHEN curs %NOTFOUND;
              --do some work with temp table
              DBMS_OUTPUT.put_line(tempTable .count || ' rows');
         end loop;
         close curs;
           
          
    end test;
    

    First question is why want you to loop through data of cursor? Do it in SQL directly, it is the fastest way to do it.

    What about fixing your code, you can go. Code in RED are which I changed.

    test procedure
    (
    the author number
    )
    is
    tempTable testTableType: = testTableType();

    curs sys_refcursor;
    Start
    Open the curs
    for
    Select testtype (documentID, documentName) in documents;

    loop
    FETCH Curs
    bulk collect into temptable limit 100;
    dbms_output.put_line (TEMPTABLE. Count | "lines");
    When exit curs % notfound;
    end loop;

    close the curs;
    end test;
    /

Maybe you are looking for

  • HP Slate 8 Plus 7500nz: HP DataPass service

    I recently bought a new (HP Slate 8 more 7500nz) Tablet from HP in Switzerland website. The Tablet comes with the HP DataPass service included. The table is actually a gift for someone who lives in Italy. The person in Italy to register for HP DataPa

  • Windows Recovery 8 8.1

    I've recently updated to 8.1 Windows but am unhappy with it for many reasons. I would go back to Windows 8. How can I do this? I created a set of recovery disc for Windows 8 shortly after obtaining this computer (laptop HP 2000-2b19wm). Thank you!

  • Battery ThinkPad Tablet has taken a lot of time to fully charge

    As the title says, when the battery remains below 20%. It took more than 20 hours to fully recharge the battery which is impossible for me to use every day. But sometimes, it took only about 4 hours to fully charge which happens rarely. So, I think t

  • LaserJet M451dw: black line to the bottom of the page

    When I print a document, a continuous black line appears in the middle of the pages. The first 2 pages are normally well, but the rest of the pages have the black line.  I cleaned the printheads etc.  I hesitate to change the ink because there is mor

  • How can I fix the USB ports on work for Vista?

    I have Windows Vista basic and USB does not work for all devices when they are plugged in. I get the message "devices connected to the computer USB has malfuctioned and Windows does not. "I also noticed that in the pilot do message"No driver for this