Return Record type - Help required

Hi ,
I have a package which uses a record type
TYPE cont_rec IS RECORD
     (cont_id Number
     ,cont_number Number
     ,cont_number_modifier Number
,s_l_id Number);
TYPE cont_tbl IS TABLE OF cont_rec INDEX BY BINARY_INTEGER;
and then calls a function
go_cont(p_id In Number,
x_name in Varchar2,
x_con out cont_tbl);
I want to use this function in a procedure and receive the result set of go_cont. how can i do this??

Here is one example:
SQL>
SQL> create or replace package prec is
  2 
  3  type cont_rec is record
  4  (cont_id Number
  5  ,cont_number Number
  6  ,cont_number_modifier Number
  7  ,s_l_id Number);
  8 
  9  type cont_tbl is table of cont_rec index by binary_integer;
10 
11  function go_cont(
12  p_id In Number,
13  x_name in Varchar2
14  ) return cont_tbl;
15 
16  end;
17  /
Package created.
SQL> show errors
No errors.
SQL>
SQL> create or replace package body prec is
  2 
  3  function go_cont(
  4  p_id In Number,
  5  x_name in Varchar2
  6  ) return cont_tbl
  7  is
  8  v_r cont_rec;
  9  v_t cont_tbl;
10  begin
11    v_r.cont_id := 1;
12    v_r.cont_number := 1;
13    v_r.cont_number_modifier := 1;
14    v_t(1) := v_r;
15    v_r.cont_id := 2;
16    v_r.cont_number := 2;
17    v_r.cont_number_modifier := 2;
18    v_t(2) := v_r;
19    return v_t;
20  end;
21 
22  end;
23  /
Package body created.
SQL> show errors
No errors.
SQL>
SQL> set serveroutput on
SQL>
SQL> declare
  2  tab prec.cont_tbl;
  3  begin
  4  tab:= prec.go_cont(1, NULL);
  5  for i in tab.first..tab.last
  6  loop
  7   dbms_output.put_line(tab(i).cont_id);
  8  end loop;
  9  end;
10  /
1                                                                              
2                                                                              
PL/SQL procedure successfully completed.
SQL>
SQL> exit

Similar Messages

  • Can stored function return record type or cursor type?

    Hi everybody,
    I am working with a stored function now.
    Can the function output more that ONE result? i.e. cursor or record type.
    Thanks.
    Brigitta.

    Brigitta,
    If you are calling the stored function from SQL then the function can only return one of the base datatypes, as Murali has said. However, if you are calling the function from PLSQL you can return any complex datatype, eg:
    package test_package is
    type rec_test is
      ( col_a number
      , col b varchar2(30) );
    type tab_test is
      table of rec_test
      index by binary ineteger;
    function test_function (.....)
    return tab_test;
    end test_package;and to call this function:
    declare
    l_table test_package.tab_test;
    begin
    l_table := test_package.test_function(....);
    end;Hope that helps!

  • Query returning wrong results - Help required.

    Hi All,
    I am having a query in which I have 10 records, 5 with stop time 1 and 5 with stop time 2.
    I have a scenario in which, I need to calculate the maximum,minimum for the records
    with stop time 1 and 2.
    What I did is, I selected all the 10 records using for loop. Within the loop
    I am trying to find the maximum and minimum. It is giving me wrong results.
    Please help me. My code is follows
    declare
         v_p1_min_stop_tm     number;
         v_p1_max_stop_tm     number;
         v_p2_min_stop_tm     number;
         v_p2_max_stop_tm     number;
    begin
         for i in(
              select
                   stop_tm
              from
                   sample_stop
              where
                   map_nbr = 16645 and
                   stop_dt = '05-sep-08'
         )loop
              if i.stop_tm = 1 then
                   select
                        min(i.stop_tm),
                        max(i.stop_tm)
                   into
                        v_p1_min_stop_tm,
                        v_p1_max_stop_tm
                   from
                        dual;
              elsif i.stop_tm = 2 then
                   select
                        min(i.stop_tm),
                        max(i.stop_tm)
                   into
                        v_p2_min_stop_tm,
                        v_p2_max_stop_tm
                   from
                        dual;
              end if;
         end loop;
         dbms_output.put_line('minimum p1 stop time : '|| v_p1_min_stop_tm);
         dbms_output.put_line('maximum p1 stop time : '|| v_p1_max_stop_tm);
         dbms_output.put_line('minimum p2 stop time : '|| v_p2_min_stop_tm);
         dbms_output.put_line('maximum p2 stop time : '|| v_p2_max_stop_tm);
    end;
    My o/p is :
    Minimum P1 stop time : 523
    Maximum P1 stop time : 523
    Minimum P2 stop time : 719
    Maximum P2 stop time : 719
    Here how can I make the data as two sets, one set with stop time 1 and
    other with stop time 2.
    Regards
    Raghu

    If the data type of stop_tm is varchar then try following
    declare
         v_p1_min_stop_tm number;
         v_p1_max_stop_tm number;
         v_p2_min_stop_tm number;
         v_p2_max_stop_tm number;
    begin
         for i in(select  stop_tm  from  sample_stop
              where
                   map_nbr = 16645 and
                   stop_dt = '05-sep-08'
              )loop
         if i.stop_tm = 1 then
              select min(to_number(i.stop_tm)), max(to_number(i.stop_tm))
                   into v_p1_min_stop_tm,v_p1_max_stop_tm
              from
                   dual;
         elsif i.stop_tm = 2 then
              select
                   min(to_number(i.stop_tm)),     max(to_number(i.stop_tm))
                   into
                   v_p2_min_stop_tm,v_p2_max_stop_tm
              from
                   dual;
         end if;
    end loop;
    dbms_output.put_line('minimum p1 stop time : '|| v_p1_min_stop_tm);
    dbms_output.put_line('maximum p1 stop time : '|| v_p1_max_stop_tm);
    dbms_output.put_line('minimum p2 stop time : '|| v_p2_min_stop_tm);
    dbms_output.put_line('maximum p2 stop time : '|| v_p2_max_stop_tm);
    end;
    / Regards
    Singh

  • Mime type help required

    with following code
    response.setContentType("application/vnd.ms-excel");
    response.addHeader("Content-Disposition"," filename=OpportunityReport.xls");
    dialog shows download dialog with three buttons
    Open, Save, Cancel
    i want to show only
    Save and Cancel
    how to adjust mime type?

    That would have helped, I supposed :o)
    However, I've resolved the issue.

  • Converting OBJECT Type into RECORD Type

    folks,
    Is there a way to Convert a OBJECT Type into a RECORD Type in Oracle PL/SQL, Because i have a stored procedure with RECORD Type as a IN parameter and as we know that we JDBC doesn't support calling or returning RECORD Types , So i was thinking of sending a OBJECT type and convert that to a RECORD type,
    I appreciate any help with the code or point to the documentation,
    thanks
    KM

    folks,
    Is there a way to Convert a OBJECT Type into a RECORD Type in Oracle PL/SQL, Because i have a stored procedure with RECORD Type as a IN parameter and as we know that we JDBC doesn't support calling or returning RECORD Types , So i was thinking of sending a OBJECT type and convert that to a RECORD type,
    I appreciate any help with the code or point to the documentation,
    thanks
    KM

  • Help in using record type and object type

    Hi Experts,
    I am new to object types and record types.
    I want to return the output of this query using one OUT parameter
    from the procedure using RECORD type or OBJECT type.
    with out using refcursor.
    SELECT empno,ename,sal FROM emp WHERE deptno=30;
    Let us assume the query is returning 50 records.
    I want to send those 50 records to OUT parameter using record type or object type.
    Please provide the for the requirement code using RECORD TYPE and OBJECT TYPE separately.
    Your earliest response is appreciated.
    Thanks in advance.

    Hi All,
    I have tried this.But it ising not work
    CREATE OR REPLACE PACKAGE maultiplevalues_pkg
    IS
    TYPE t_record IS RECORD
    (empno emp.empno%TYPE,
    ename emp.ename%TYPE,
    sal emp.sal%TYPE);
    V_RECORD t_record;
    TYPE t_type IS TABLE OF V_RECORD%TYPE;
    PROCEDURE maultiplevalues_pROC(p_deptno IN emp.deptno%TYPE,
    dept_result OUT t_type);
    END;
    CREATE OR REPLACE PACKAGE body maultiplevalues_pkg
    IS
    PROCEDURE maultiplevalues_pROC(p_deptno IN emp.deptno%TYPE,
    dept_result OUT t_type)
    is
    begin
    dept_result :=t_type();
    for I in(
    select EMPNO,ENAME,SAL from EMP WHERE deptno=p_deptno
    LOOP
    dept_result.extend;
    dept_result(i).empno :=i.empno;
    dept_result(i).ename :=i.ename;
    dept_result(i).sal :=i.sal;
    END LOOP;
    END;
    END;
    Please help me OUT return multiple values through single OUT variable in a procedure.
    Thanks.

  • How to return more than one value through RECORD TYPE from function

    Hi friends,
    i m ew in oracle forms. i want to return the two values at a time from a function but can't,Please help me. my codding is as following
    Thanks in advance.
    FUNCTION Fun_Choose_Right_cast(v_post_no payroll.post_register.post_no%TYPE) RETURN RECORD IS --here is the error 
    v_return_char CHAR NOT NULL := 'X';
    TYPE row_no_record_type IS RECORD
         (v_row_id NUMBER(3)NOT NULL := 0,
         v_char CHAR NOT NULL := 'X');
    row_no_record row_no_record_type;
    BEGIN
    IF v_post_no = 1 THEN
         IF TRUNC(v_post_no*0.15) >= 1 THEN
              row_no_record_type.v_row_id := v_post_no;
              v_char := 'A';
              --v_return_char := 'A';
         END IF;
         IF TRUNC(v_post_no*0.075) >= 1 THEN
              row_no_record_type.v_row_id := v_post_no;
              v_char := 'B';
              --v_return_char := 'B';
         END IF;
         IF TRUNC(v_post_no*0.275) >= 1 THEN
              row_no_record_type.v_row_id := v_post_no;
              v_char := 'C';
              --v_return_char := 'C';
         END IF;
         IF row_no_record_type.v_row_id = 0 AND v_char = 'X' THEN
              row_no_record_type.v_row_id := v_post_no;
              v_char := 'D';
         --IF v_return_char = 'X' THEN 
              --v_return_char := 'D';
         END IF;
    ELSIF(v_post_no BETWEEN 2 AND 100) THEN
         IF TRUNC(v_post_no*0.15) > TRUNC((v_post_no-1)*0.15) THEN
              row_no_record_type.v_row_id := v_post_no;
              v_char := 'A';
              --v_return_char := 'A';
         END IF;
         IF TRUNC(v_post_no*0.075) > TRUNC((v_post_no-1)*0.075) THEN
              IF TRUNC(v_post_no*0.15) > TRUNC((v_post_no-1)*0.15) THEN
                   row_no_record_type.v_row_id := v_post_no-1;
                   v_char := 'B';
                   --v_return_char := 'A';
              ELSE
                   row_no_record_type.v_row_id := v_post_no;
                   v_return_char := 'B';
              END IF;
         END IF;
         IF TRUNC(v_post_no*0.275) > TRUNC((v_post_no-1)*0.275) THEN
              row_no_record_type.v_row_id := v_post_no;
              v_char := 'C';
              --v_return_char := 'C';
         END IF;
         IF row_no_record_type.v_row_id = 0 AND v_char = 'X' THEN
              row_no_record_type.v_row_id := v_post_no;
              v_char := 'D';
         --IF v_return_char = 'X' THEN 
              --v_return_char := 'D';
         END IF;
         END IF;
    RETURN row_no_record;
    END;

    Posting your Oracle version is immensely helpful when asking questions (different version = different answers / functionality available).
    select * from v$version;Also, using tags will preserve the formatting of your code.
    You should likely read (a lot) about  [http://www.stanford.edu/dept/itss/docs/oracle/10g/appdev.101/b10807/05_colls.htm]
    Basically, you would need to create a PL/SQL record and reference that, OR you could create a SQL type.
    If you're looking for a 'simple' way to return many single values (no arrays) then your best bet would be a procedure with multiple OUT parameters.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • DB  Adapter Calling DB Procedure that returns a Record Type

    I am trying to call a PL/SQL procedure that returns a Record Type and a VARCHAR2 and I'm getting this error:
    <Faulthttp://schemas.xmlsoap.org/soap/envelope/>
    <faultcode>env:Server</faultcode>
    <faultstring>java.sql.SQLException: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'MY_PROC.GET_ID' ORA-06550: line 1, column 7: PL/SQL: Statement ignored </faultstring> </Fault>
    Is there something different I need to do to handle the Record Type OUT parameter?
    Thanks.

    The adapter configuration wizard should take care of the Record Type for you. It should invoke JPublisher to create an equivalent Object type and a package containing a wrapper that will be called by the adapter runtime. The package also contains conversion functions for converting between your Record Type and the generated Object type. Maybe it would help if you posted the signature of your stored procedure (not the body).

  • [HELP] Procedure return records

    Hi All,
    I want to create a procedure that will return records (not only single record) base on some parameters. Is it possible?
    While i used MS SQL Server, it is just a simple way. In the body of procedure i just need to call select query with some parameters in where clause. For example:
    Create procedure GetEmployee
    @grade char(1)
    As
    Select * From Employee Where EMP_Grade=@grade
    Please help me!

    First off, what are you going to do with the records that are returned here?
    Second, you can return a REF CURSOR
    CREATE OR REPLACE PACKAGE refcursor_demo
    AS
      TYPE emp_refcursor_strong IS REF CURSOR RETURN emp%rowtype;
      TYPE emp_refcursor_weak   IS REF CURSOR;
      -- You can define either procedures that have the strongly typed
      -- REF CURSOR as an OUT parameter or you can define a function that
      -- returns the REF CURSOR.
      PROCEDURE refCursorProc( employees OUT emp_refcursor_strong );
      FUNCTION  refCursorFunc RETURN emp_refcursor_weak;
    END;
    CREATE OR REPLACE PACKAGE BODY refcursor_demo
    AS
      PROCEDURE refCursorProc( employees OUT emp_refcursor_strong )
      AS
      BEGIN
        OPEN employees FOR
          SELECT * FROM emp;
      END;
      FUNCTION refCursorFunc RETURN emp_refcursor_weak
      IS
        out_cursor emp_refcursor_weak;
      BEGIN
        OPEN out_cursor FOR
          SELECT * FROM emp;
        RETURN out_cursor;
      END;
    END;Alternately, you could return a collection, potentially in a pipelined table function.
    Justin

  • Return rows from pl-sql record type

    We have a requirement to create function which returns cursor to java application. This cursor will have data from pl-sql record type.
    Tried with pipelined function. I have written code below.
    CREATE or replace PACKAGE test_pkg IS
        TYPE tp_rec IS RECORD(tt_id INTEGER,tt_text VARCHAR2(40));
        TYPE obj_tp_recs IS TABLE OF tp_rec;
        TYPE obj_tp_recs1 IS TABLE OF tp_rec;
        FUNCTION test_func RETURN tp_rec;
        function type_out return obj_tp_recs1 PIPELINED;
        PROCEDURE test_type (result out sys_refcursor);
    END;
    CREATE OR REPLACE PACKAGE BODY OMS.test_pkg IS
        FUNCTION test_func RETURN tp_rec
        AS
           currec tp_rec;
        BEGIN
           currec.tt_id := 1;
           currec.tt_text := 'test1';
        END;
         FUNCTION type_out RETURN obj_tp_recs1 PIPELINED
             AS
           currec1 test_pkg.tp_rec;
          begin
                    currec1 := test_pkg.test_func;
                    PIPE ROW(currec1);
                    dbms_output.put_line(currec1.tt_id);
                end;
        PROCEDURE test_type (result out sys_refcursor)
        AS   
        BEGIN
                  OPEN RESULT
                  FOR SELECT * FROM TABLE(test_pkg.type_out());
        END;
    END;
    SQL> VARIABLE x REFCURSOR
    SQL> exec test_pkg.test_type(:x);
    PL/SQL procedure successfully completed.
    SQL> print xThis code returns no data found exeception from function. How to achieve result 1 and test1 from above code?
    Thanks in advance

    SQL> VARIABLE x REFCURSOR
    SQL> exec test_pkg.test_type(:x);
    PL/SQL procedure successfully completed.
    SQL> print x
    ERROR:
    ORA-06503: PL/SQL: Function returned without value
    ORA-06512: at "SCOTT.TEST_PKG", line 8
    ORA-06512: at "SCOTT.TEST_PKG", line 14
    no rows selectedIf you look at test_func body it is missing return statement. Now:
    SQL> CREATE OR REPLACE PACKAGE BODY test_pkg IS
      2      FUNCTION test_func RETURN tp_rec
      3      AS
      4         currec tp_rec;
      5      BEGIN
      6         currec.tt_id := 1;
      7         currec.tt_text := 'test1';
      8         RETURN currec;
      9      END;
    10     
    11       FUNCTION type_out RETURN obj_tp_recs1 PIPELINED
    12       AS
    13         currec1 test_pkg.tp_rec;
    14        begin
    15          currec1 := test_pkg.test_func;
    16          PIPE ROW(currec1);
    17          dbms_output.put_line(currec1.tt_id);
    18          end;
    19  
    20      PROCEDURE test_type (result out sys_refcursor)
    21      AS   
    22      BEGIN
    23        OPEN RESULT
    24        FOR SELECT * FROM TABLE(test_pkg.type_out());
    25       
    26      END;
    27  END;
    28  /
    Package body created.
    SQL> exec test_pkg.test_type(:x);
    PL/SQL procedure successfully completed.
    SQL> print x
         TT_ID TT_TEXT
             1 test1
    SQL> SY.

  • Query-Automatic assignment of Record type to Book of Business-Pls help me

    I have a query about Automatic assignment of record in Book of Business.
    Using 5 record types & 50 regions as a part of Book of Business. You can say 50 sub-books.
    I want to assign these 5 record type to particular Book when to create & modify.
    Eg. When I create new account it should be automatically assigned to Book 1 & later I modify this account for reassignment to new user then it should be automatically added to the new user’s book.
    I need to create workflow for this as Assign to book criteria for both when new record saved & when modified record saved.
    I have tried this & its working; however problem is with the creation of two many workflows.
    50 region (Books) x 5 record types * 2 - Create/modify flow = 500 workflows for one country!
    If I am right then I can assign 1 record type with action as create or modify in 1 book only.
    How to reduce these no. of workflows?
    Pls help me out in this regard.
    Regards
    Mangesh

    Mangesh,
    I am sorry to tell you that there is no quick answer to this but i will say that maybe you need to rethink your book structure and their requirements here.
    I have 4 types and 7 regions so you need to create books to allocate all these on create and also modify. Customers have raised concerns with this to Oracle and they are looking into it but they are along way from completing this. Sorry to spoil your day but i would strongly ask you to consider your books structure before you complete this.
    Otherwise if you are using webservices you could assisgn the book when the record is piped into the CRM and then you only need to complete the modify workflows.

  • Reports not returning records utilizing different currency type.

    Good morning,
    My company has numerous subsidiaries utlizing CRM On Demand. Although our defauct currency is USD, one of our operations enters opportuntiy data in Canadian dollars. Both currency types are active in the system but for some reason, the custom reports I have created are not returning records created by our Canadian company entering in CAD.
    There is probably a quick solution, but so far I have yet to find it! Thanks in advance for your feedback!
    Ryan

    yes...your report won't show data for canadian currency. even the admins won't be able to see it.
    try this fix instead:
    you will have to create a new field for currency in the opty page layout and change it to canadian dollar otherwise the currency would still appear as USD in the database.
    Then use this field in your reports.
    This should help. please let us know your feedback.

  • Error while creating function with record type as return type

    Hi i tried the following code to get the nth highest sal using record type and function.
    CREATE OR REPLACE PACKAGE pack_rec_cur AS
    TYPE rec_type IS RECORD (
    name EMP.ename%TYPE,
    sal EMP.sal%TYPE);
      END;The above package is created
    CREATE OR REPLACE
      FUNCTION fun_rec_cur(n INT) RETURN pack_rec_cur.rec_type AS
       rec pack_rec_cur.rec_type;
        CURSOR cur_rec IS
          SELECT ename,sal
            FROM emp
             WHERE sal is not null
              ORDER BY DESC;
    BEGIN
    OPEN cur_rec;
      FOR i IN 1..n LOOP
       FETCH cur_rec into rec;
       EXIT WHEN cur_rec%NOTFOUND;
      END LOOP;
    CLOSE cur_rec;
    RETURN rec;
    END;   The above function is giving errors
    LINE/COL ERROR
    4/7      PL/SQL: SQL Statement ignored
    7/16     PL/SQL: ORA-00936: missing expression
    SQL> Could you please correct me where i'm doing mistake
    Thanks.

    You are missing the column name in order by clauase. Is it ename desc?
    CREATE OR REPLACE
      FUNCTION fun_rec_cur(n INT) RETURN pack_rec_cur.rec_type AS
       rec pack_rec_cur.rec_type;
        CURSOR cur_rec IS
          SELECT ename,sal
            FROM emp
             WHERE sal is not null
              ORDER BY ENAME DESC; ---added ename
    BEGIN
    OPEN cur_rec;
      FOR i IN 1..n LOOP
       FETCH cur_rec into rec;
       EXIT WHEN cur_rec%NOTFOUND;
      END LOOP;
    CLOSE cur_rec;
    RETURN rec;
    END;  
    -OUTPUT
    SQL> SET SERVEROUT ON
    SQL>
    SQL> DECLARE
      2     rec            pack_rec_cur.rec_type;
      3  BEGIN
      4     rec         := fun_rec_cur (6); --you get the 6th record in order of ename desc
      5     DBMS_OUTPUT.put_line ('ename::' || rec.NAME || '  sal ::' || rec.sal);
      6  END;
      7  /
    ename::MARTIN  sal ::1250
    PL/SQL procedure successfully completed.
    SQL>

  • Video stream recording (not webcam) help required

    I am making a media player / recorder type web application in flex 4.
    The application plays video streams streamed from my red5 server.
    I want to give users the ability to make / record clips of the video they are viewing.
    I know that netstream.publish is used to record/save video on the server.
    All the help i've found on google so far just give examples to save video from webcam.
    But i want to save video from a video being streamed from red5 server and being played
    on VideoPlayer control in flex.
    All help is greatly appreciated.
    Thanks.

    Thanks for the reply but i think u misunderstood my problem.
    I am not receiving any RTP Stream but RTMP stream.RTMP is a proprietary protocol of Adobe For Streaming Flash video from Flash Media Server (FMS).
    I again state the problem.
    I am getting an RTMP Stream now i want to convert it into an RTP Stream so that i can process or transmit it further.I want to convert this RTMP Stream to RTP format.
    Anyone plz help me out.I am stuck into this for past 2 days and it is very critical for my project. :-(

  • Return cursor help Required-urgent

    Hi All
    I need to show 2 column list which is a formula calculation
    these now i am getting in dbms output
    but i need return cursor , please help
    ITEM RATIO
    asd v_asd
    zyx v_zyx
    afd v_afd
    xcv v_xcv
    ITEM RATIO
    asd 23.90
    zyx 24.6
    afd 43.67
    xcv 78.67
    Regards,

    Select the variables over dual in Union query under a REF CURSOR.
    Like
    OPEN RefCursor FOR
    SELECT 'asd' col1, v_asd col2 FROM Dual
    UNION
    SELECT 'zyx', v_zyx FROM Dual
    ....

Maybe you are looking for