Function returning a set of records - how to do this?

Hi,
I need to return something of a table as a result:
function Find_Item (vNUMBER in NUMBER(3,0)
vNAME in VARCHAR2(200) ) return ???
as
begin
SELECT UUID, Number, Name FROM Tab1
Where NUMBER LIKE vNUMBER|| '%'
intersect
SELECT UUID, Number, Name FROM Tab1
Where NAME LIKE vNAME|| '%' ;
end;
How to do this? Should I use a collection? Any ideas? I would be grateful for any hint.
Best regards,
Alicja

user651039 wrote:
And it would work if not for INTERSECT. So, I either I change the query or have to find walk-around.What is the issue with the INTERSECT? Why should the approach shown not work when using INTERSECT?
Note that you can't define the parameters of your function like that, you have to specify the length of the varchar2 column in the calling code.
If your query is going to return potentially a large number of rows you should consider using a "pipelined" function, as already mentioned, as the non-pipelined version could be consuming a lot of memory in case a large collection is going to be generated.
Here's a sample of a pipelined table function:
alter session set nls_language = 'AMERICAN';
set echo on linesize 130 feedback 1
drop type t_find_item_record_col force;
drop type t_find_item_record force;
drop function find_item;
create or replace type t_find_item_record as object(
uuid varchar2(30),
a_number number,
a_name varchar2(30)
create or replace type t_find_item_record_col as table of t_find_item_record;
create or replace function find_item(
vNUMBER in NUMBER, vNAME in VARCHAR2) return t_find_item_record_col pipelined
as
  a_find_item_record_col t_find_item_record_col;
  cursor c is
  select t_find_item_record(uuid, a_number, a_name) from (
  SELECT cast('a' as varchar2(30)) as UUID, 1 as a_Number, cast('b' as varchar2(30)) as a_Name
  FROM dual
  Where 35 LIKE vNUMBER|| '%'
  intersect
  SELECT 'a' as UUID, 1 as a_Number, 'b' a_Name FROM dual
  Where 'Bob' LIKE vNAME|| '%'
begin
  open c;
  loop
    fetch c bulk collect into a_find_item_record_col limit 100;
    for i in 1..a_find_item_record_col.count loop
      pipe row(a_find_item_record_col(i));
    end loop;
    exit when a_find_item_record_col.count = 0;
  end loop;
  close c;
  return;
end;
select * from table(find_item(35, 'Bob'));Another option you might want to consider is using a REF CURSOR return type, so that you open the cursor accordingly in your function and return the opened cursor to the caller. The caller can then fetch from this cursor.
And here's a sample function using ref cursor:
create or replace function find_item_cursor(
vNUMBER in NUMBER, vNAME in VARCHAR2) return sys_refcursor
as
  c sys_refcursor;
begin
  open c for
  SELECT cast('a' as varchar2(30)) as UUID, 1 as a_Number, cast('b' as varchar2(30)) as a_Name
  FROM dual
  Where 35 LIKE vNUMBER|| '%'
  intersect
  SELECT 'a' as UUID, 1 as a_Number, 'b' a_Name FROM dual
  Where 'Bob' LIKE vNAME|| '%';
  return c;
end;
variable a refcursor
exec :a := find_item_cursor(35, 'Bob')
print aHere's the output of the samples:
Session altered.
SQL>
SQL> drop type t_find_item_record_col force;
Type dropped.
SQL>
SQL> drop type t_find_item_record force;
Type dropped.
SQL>
SQL> drop function find_item;
Function dropped.
SQL>
SQL> create or replace type t_find_item_record as object(
  2  uuid varchar2(30),
  3  a_number number,
  4  a_name varchar2(30)
  5  );
  6  /
Type created.
SQL>
SQL> create or replace type t_find_item_record_col as table of t_find_item_recor
d;
  2  /
Type created.
SQL>
SQL>
SQL> create or replace function find_item(
  2  vNUMBER in NUMBER, vNAME in VARCHAR2) return t_find_item_record_col pipelin
ed
  3  as
  4    a_find_item_record_col t_find_item_record_col;
  5    cursor c is
  6    select t_find_item_record(uuid, a_number, a_name) from (
  7    SELECT cast('a' as varchar2(30)) as UUID, 1 as a_Number, cast('b' as varc
har2(30)) as a_Name
  8    FROM dual
  9    Where 35 LIKE vNUMBER|| '%'
10    intersect
11    SELECT 'a' as UUID, 1 as a_Number, 'b' a_Name FROM dual
12    Where 'Bob' LIKE vNAME|| '%'
13    );
14  begin
15    open c;
16    loop
17      fetch c bulk collect into a_find_item_record_col limit 100;
18      for i in 1..a_find_item_record_col.count loop
19        pipe row(a_find_item_record_col(i));
20      end loop;
21      exit when a_find_item_record_col.count = 0;
22    end loop;
23    close c;
24    return;
25  end;
26  /
Function created.
SQL>
SQL> select * from table(find_item(35, 'Bob'));
UUID                             A_NUMBER A_NAME
a                                       1 b
1 row selected.
SQL>
SQL> create or replace function find_item_cursor(
  2  vNUMBER in NUMBER, vNAME in VARCHAR2) return sys_refcursor
  3  as
  4    c sys_refcursor;
  5  begin
  6    open c for
  7    SELECT cast('a' as varchar2(30)) as UUID, 1 as a_Number, cast('b' as varc
har2(30)) as a_Name
  8    FROM dual
  9    Where 35 LIKE vNUMBER|| '%'
10    intersect
11    SELECT 'a' as UUID, 1 as a_Number, 'b' a_Name FROM dual
12    Where 'Bob' LIKE vNAME|| '%';
13    return c;
14  end;
15  /
Function created.
SQL>
SQL> variable a refcursor
SQL>
SQL> exec :a := find_item_cursor(35, 'Bob')
PL/SQL procedure successfully completed.
SQL>
SQL> print a
UUID                             A_NUMBER A_NAME
a                                       1 b
1 row selected.Regards,
Randolf
Oracle related stuff:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle:
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/

Similar Messages

  • HT201401 I had restored my iPhone 4 but after restore my camera can't function well after take picture from the camera it's didn't display in the Photo Gallery even can't take a video record,how to solve this?and i had tried to restore again,still the sam

    I had restored my iPhone 4 but after restore my camera can't function well after take picture from the camera it's didn't display in the Photo Gallery even can't take a video record,how to solve this?and i had tried to restore again,still the same
    kindly reply and fix this for me
    reply to my email,tq

    Most likely you have Office 2004 which are PPC-only applications and will not work in Lion. Upgrade to Office 2011. Other alternatives are:
    Apple's iWork suite (Pages, Numbers, and Keynote.)
    Open Office (Office 2007-like suite compatible with OS X.)
    NeoOffice (similar to Open Office.)
    LibreOffice (a new direction for the Open Office suite.)

  • Which planning function i have to use and how to write this planning fucnti

    Hi Bi Guru's,
    I have rolled out  BW SEM-BPS Planning Layout's for the Annual Budget in my organistaion.
    There are two levels of layout given for the each sales person.
    1)  Sales quantity to be entered Material and  country wise for all 12 months ( April 2009 to March 2010)
    2)  Rate per unit and to entered in second sheet, Material and country wise for the total qty entered in the first layout.
    Now i need to calculate the sales vlaue for each period and for the each material.
    Which planning function i have to use and how to write this planning fucntion.
    Please suggest me some solution ASAP.
    Thanks in Advance,
    Nilesh

    Hi Deepti,
    Sorry to trouble you...
    I require your help for the following scenario for caluclating Sales Value.
    I have Plan data in the following format.
    Country   Material    Customer    Currency    Fiscyear    Fiscper           Qty         Rate        Sales Value
    AZ          M0001      CU001          #             2009          001.2009        100.00                        
    AZ          M0001      CU002          #             2009          001.2009        200.00                        
    BZ          M0001      CU003          #             2009          001.2009        300.00
    BZ          M0001      CU003          #             2009          002.2009        400.00
    BZ          M0002      CU003          #             2009          002.2009        300.00
    AZ          M0001       #               USD          2009             #                                 10.00
    BZ          M0001       #               USD          2009             #                                 15.50
    BZ          M0002       #               USD          2009             #                                 20.00
    In the Above data the Rate lines are entered in the Second Layout, Where the user enters on the Country Material Level with 2009 value for FISCYEAR.
    I am facing problem with this type of data. 
    I want to store the sales value for each Material Qty.
    Please suggest some solution.
    Re
    Nilesh

  • Having a SP or Function return a set of rows ?

    Hi,
    I been looking through the documentation that came with PL/SQL and I am trying to figure out how to get a procedure or function to return the rows of a select statement. Would it have to be done using a Table function ?? I am trying to access the results of a procedure that does some pre-processing before returning the results of the query in a JDBC application..
    Thanks

    You can't return the rows of a SQL query through PL/SQL.
    You need to create one or more functions that are called in your select statement to perform the pre-processing i.e.
    select function1(param1), function2(param2)
    from ...
    Regards.

  • Apple TV is asking me to set network time. how to do this?

    Apple TV is asking to set network time. How is this done?

    Assuming this is not the first time you have used your Apple TV
    You might try restarting the Apple TV by removing ALL the cables for 30 seconds.
    Also try restarting the router.
    If the problem persists, try a restore, you may want to try the previous procedures several times before doing this.
    If this is a new Apple TV, it may also be that your network router is not allowing access to the timeserver, check that your router allows access over port 123.

  • TS1717 2 months ago, my iTunes dj (on my PC) lost its ability to "Shuffle"   (I cannot get shuffle on) as well as its shuffle function.  Anyone out ther know how to fix this?

    2 months ago my iTunes dj (0n my ASUS PC) lost its ability to shuffle.  It will not allow me to turn "shuffle" on, and "refresh" does not work either.

    Just connect the new iPod to your computer and setup the iPod via iTunes (instead of via wifi).
    If you want to copy all the infor from an old iPod touch to the inew iPod see:
    iOS: Transferring information from your current iPhone, iPad, or iPod touch to a new device

  • How to fetch 2 set of records in MII from SQL procedure

    Hi Experts,
    I am invoking a SQL procedure from MII which return 2 set of records. But at MII I am able to get only first set of records. Is there any configuration required at MII side or SQL side to get both set of records in MII?
    Here is the SQL Query Structure
    Create procedure Sample_Proc
      @Param1 Varchar(10),
      @Param2 varchar(10),
      @Param3 Varchar(20) OUT,
      SET INCOUNT ON;
    AS
    Begin
      *//Selection statements//*
    END
    SP Executing in MII
    Declare @Param1,
      @Param2,
      @Param3,
    Exec Sample_Proc
      @Param1='name',
      @Param2='Id',
      @Param3=@Param3 OUTPUT,
    Select @Param3
    Our SP is returning values (Say Recordset1)based on the input parameters 1 and 2 , along with Parameter3 value(Say Recordset2) in MS SQL server but in MII its returning only the values(Recordset1) ... how to fetch recordset2 values in MII
    I hope MII can return 2 set of records (rowsets) after executing the procedure.
    MII version -> 12.2.3 Build(182)
    Thanks & Regards,
    Rajasekhar Kantepalli

    Hi Swaroop,
    With MII 14.0 SP5 Patch 11, in a transaction, I get following XML output for a query that executes an SP(returning multiple resultSets) :
    And, results in this format can surely be used for further processing in an MII transaction.
    Thanks Rajasekhar, got to know about this because of your query.
    regards,
    Manisha

  • Retreiving a set of records

    Hello
    I'm a newbie and i have to make a procedure that can return a set of records , in Transact SQL I make using temporal tables , is possible to do the same in Oracle ? Thanks

    The procedure would look something like below. The other statements in the code are just to help test the actual procedure.
    Please post more details so we could suggest solution for your exact needs.
    SQL> variable rc refcursor
    SQL>
    SQL> create or replace procedure get_rows (rc OUT sys_refcursor) is
      2  begin
      3    open rc for
      4    select * from scott.emp ;
      5  end ;
      6  /
    Procedure created.
    SQL> exec get_rows(:rc) ;
    PL/SQL procedure successfully completed.
    SQL> print rc
         EMPNO ENAME      JOB              MGR HIREDATE           SAL       COMM     DEPTNO
          7369            CLERK           7902 17-DEC-1980       1200                    20
          7499            SALESMAN        7698 20-FEB-1981       1600        304         30
          7521            SALESMAN        7698 22-FEB-1981       1250        504         30
          7566            MANAGER         7839 02-APR-1981       2975                    20
          7654            SALESMAN        7698 28-SEP-1981       1250       1404         30
          7698            MANAGER         7839 01-MAY-1981       2850                    30
          7782            MANAGER         7839 09-JUN-1981       2450                    10
          7788            ANALYST         7566 19-APR-0087       3000                    20
          7839            PRESIDENT            17-NOV-1981       5000                    10
          7844            SALESMAN        7698 08-SEP-1981       1500          4         30
          7876            CLERK           7788 23-MAY-0087       1100                    20
          7900            CLERK           7698 03-DEC-1981        950                    30
          7902            ANALYST         7566 03-DEC-1981       3000                    20
          7934            CLERK           7782 23-JAN-1982       1300                    10
    14 rows selected.
    SQL>

  • Call stored function return array

    Hi all,
    I have a function as follow:
    create or replace TYPE string_table IS TABLE OF VARCHAR2(2000);
    create or replace TYPE ARRAYTYPE is VARRAY(20) OF VARCHAR2(30);
    create or replace FUNCTION getEmpArray(s varchar2, t varchar2, st string_table) RETURN ARRAYTYPE AS
    l_data ARRAYTYPE := ARRAYTYPE();
    BEGIN
    l_data.extend; l_data(l_data.count) := s; l_data.extend; l_data(l_data.count) := t; l_data.extend; l_data(l_data.count) := st(1); RETURN l_data;
    END;
    I want to call this function by StoredFunctionCall
    code:
    StoredFunctionCall fun = new StoredFunctionCall();
    fun.setProcedureName("getEmpArray".toUpperCase());
    Object[] arr = new Object[]{"aa", "fgfg", "bbb"};
    ArrayDescriptor arrDescriptor =
    ArrayDescriptor.createDescriptor("string_table".toUpperCase(),
    connection);
    ARRAY arrayToPass = new ARRAY(arrDescriptor, connection, arr);
    fun.addUnamedArgumentValue("a");
    fun.addUnamedArgumentValue("b");
    fun.addUnamedArgumentValue(arrayToPass);
    fun.setResult("FUNCTION_RESULT"); // for get result by this name
    Vector<DatabaseRecord> list = session.executeSelectingCall(fun);
    But Exception
    PLS-00382: expression is of wrong type
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    Error Code: 6550
    Call: BEGIN ? := GETEMPARRAY(?, ?, ?); END;
         bind => [=> FUNCTION_RESULT, a, b, oracle.sql.ARRAY@21fbc01]
    Please help me
    Edited by: fbg on 21:52 26-04-2010

    A few issues,
    1 - JDBC does not support the PLSQL TABLE type, you must use a VARRAY type, or wrap the TABLE function call in a function that takes a VARRAY.
    TopLink also has support for PLSQL types in its PLSQLStoredProcedureCall class, but no support is currently offered for StoredFunctions.
    You can't pass the VARRAY type for the TABLE argument.
    2 - Your function returns a VARRAY, so you need to define this type in the StoredFunctionCall result.
    We don't currently expose the API to set a Array type for the result, so you would need to access the call's first parameter directly, or use a StoredProcedureCall (and convert your function to a procedure).
    You may also wish to investigate returning a cursor from a stored procedure instead of the varray.
    You could also access the JDBC connection directly and perform the call using JDBC code.
    Feel free to log these issues in EclipseLink.
    James : www.eclipselink.org

  • Is their any function module for deleting condition record i am trying

    Hi Experts,
    Is their any function module for deleting condition record i am trying  this way.......
    DATA: TABLE (4) TYPE C.
    DATA: KNUM LIKE KONH-KNUMH
    DATA: K_VEWE LIKE T681-KVEWE VALUE 'A'.
    DATA: T681_STR LIKE T681.
    DATA: LV_NUM TYPE I.
    GET PARAMETERS
    PARAMETERS: TABNO LIKE T681-KOTABNR.
    PARAMETERS: TESTMODE DEFAULT 'X' AS CHECKBOX.
    REFRESH INT_KNUMH.
    Select single * from T681 into T681_STR
    where kvewe = K_VEWE AND
    KOTABNR = TABNO.
    IF SY-SUBRC NE 0.
    WRITE: / 'No entry in T681 for number ', TABNO.
    WRITE: / 'Check whether corresponding condition table exists.'.
    EXIT.
    ENDIF.
    TABLE = T681_STR-KOTAB.
    SELECT KNUMH FROM (TABLE) INTO KNUM.
    SELECT SINGLE * FROM KONH WHERE KNUMH = KNUM.
    IF SY-SUBRC NE 0.
    INT_KNUMH-KNUMH = KNUM.
    COLLECT INT_KNUMH.
    ENDIF.
    ENDSELECT.
    DESCRIBE TABLE INT_KNUMH LINES LV_NUM.
    IF LV_NUM EQ 0.
    WRITE: / 'No inconsistent entries found.'.
    WRITE: / 'Each record in the condition table has a corresponding.'.
    WRITE: / 'entry in the KONH table.'.
    EXIT.
    ENDIF.
    LOOP AT INT_KNUMH.
    IF TESTMODE IS INITIAL.
    DELETE FROM (TABLE) WHERE
    KNUMH = INT_KNUMH-KNUMH.
    IF SY-SUBRC = 0.
    WRITE: / 'KNUMH =', INT_KNUMH-KNUMH(10), ' deleted from table ' ,TABLE.
    ELSE.
    WRITE: / 'DELETE: SY-SUBRC is', SY-SUBRC , ' FOR KNUMH = ' .
    WRITE: INT_KNUMH-KNUMH(10).
    ENDIF.
    ELSE.
    WRITE: / 'TESTRUN: KNUMH =', INT_KNUMH-KNUMH(10).
    ENDIF.
    ENDLOOP.
    is their any Standerd Function module  for comparing  tables if the condition record not exist in it has to exit if it is their then compare  those two tables if not exist in one table also that has  to be delete  the condition record
    Please let me know .....

    Hi,
       You can use Function module PRICING_CHECK to check condition record. Do a where-used list on it to see how to call it.
    Regards
    Kiran Sure

  • How to devide the set of records into groups in SQL itself.

    Hi , i am using 10.2.4.0 of oracle.
    I am having one requirement, in which i have to devide the set of records into certain groups , so that they can be executed partly but not in one run.
    So in the 'SELECT' clause itself i want to asssign particular value (may be 1 )to first 50000 records then another value(may be 2) to next 10000, like wise. And again the total count of records will also varry time to time , if the total count of record set is less than 10000 , then it should only assign '1' to all the records. i will set the group values (1,2,3...) as another column itself.
    Can you please let me know if this can be done in SQL without going for PLSQL?

    Hi,
    That's called a Pagination Query , and here's one way to do it:
    WITH     got_grp          AS
         SELECT     x.*
         ,     CEIL ( ROW_NUMBER () OVER (ORDER BY  x_id) 
                   / 50000
                   )          AS grp
         FROM     table_x  x
    --     WHERE     ...          -- If you need any filtering, put it here
    SELECT     *               -- Or list the columns you want
    FROM     got_grp
    WHERE     grp     = 1
    ;ROW_NUMBER () OVER (ORDER BY x_id)     assigns unique integers 1, 2, 3, ... to all all rows, in the same order as x_id (even if x_id is not unique).
    CEIL (ROW_NUMBER () OVER (ORDER BY x_id) / 50000)     maps the 1st 50,000 of those numbers to 1, the 2nd 50,000 to 2, and so on.
    Analytic functions (like ROW_NUMBER) as computed after the WHERE clause is applied, so, to use the results in a WHERE clause, then you need to compute them in a sub-query. If you just want to display the number, and not use it in a WHERE clause, then you don't need a sub-query.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

  • Creating a function to return a table of records

    Okay, I thought I knew how to do this but apparently not. I have a very complex query that connects multiple tables. I want to put the results of that query into a "table" (non-persistent) that can be passed to another procedure. So, I created an object/record that defines a single row in this table:
    create or replace TYPE SHP_RECORD is OBJECT
    (FIELD01 NUMBER(10),
    FIELD02 NUMBER(10),
    FIELD03 NUMBER(10),
    FIELD04 NUMBER(10),
    FIELD05 NUMBER(10),
    FIELD06 VARCHAR2(200),
    FILED07 NUMBER(10),
    FIELD08 VARCHAR2(200),
    FIELD09 NUMBER(10),
    FIELD10 TIMESTAMP(6),
    FIELD11 TIMESTAMP(6),
    FIELD12 TIMESTAMP(6),
    FIELD13 VARCHAR2(5),
    FIELD14 NUMBER(10),
    FIELD15 VARCHAR2(100),
    FIELD16 VARCHAR2(4000),
    FIELD17 VARCHAR2(1),
    FIELD18 VARCHAR2(1));
    Then I create another type that defines a table of SHP_RECORD:
    Create or replace TYPE SHP_TABLE is TABLE of SHP_RECORD;
    Now I have a function that puts the huge query into a text string (because it's got elements that change depending on what day of the week it's being run on so I have to keep it as a dynamic query. Now I want to run this query and put the results into a table. I've changed all the names to protect the innocent in this code snippet:
    create or replace function get_SHP_data(p_cust_id IN NUMBER,
    p_date IN TIMESTAMP) return SHP_TABLE as
    begin
    declare
    shp_data_out SHP_TABLE;
    TYPE shp_cur_type is REF CURSOR;
    shp_cv shp_cur_type;
    TYPE daily_query is VARRAY(7) of VARCHAR2(15);
    query_values DAILY_QUERY;
    day_index NUMBER;
    old_program_id NUMBER;
    chk_rundown NUMBER;
    query_text VARCHAR2(3000);
    row_index NUMBER;
    program_freq_id NUMBER;
    prog_seg_count NUMBER;
    upload_seg_count NUMBER;
    xfer_count NUMBER;
    sched_count NUMBER;
    bill_count NUMBER;
    rcvr_text VARCHAR2(2000);
    xmsn_start TIMESTAMP;
    xmsn_end TIMESTAMP;
    epi_status VARCHAR2(2000);
    begin
    query_values := daily_query('1, 3, 4, 12','1, 2, 5, 12','1, 2, 6, 12','1, 2, 7, 12','1, 2, 8, 12','1, 2, 9, 12','1, 3, 10, 12');
    day_index := to_number(to_char(p_date,'D'));
    query_text := {really ugly query here that includes concatinating a value from query_values as well as defines five bind variables numbered :1 through :5};
    old_program_id := 0;
    open shp_cv for query_text using p_date, p_date, p_date, p_date, p_cust_id;
    fetch shp_cv bulk collect into shp_data_out;
    close shp_cv;
    end;
    end;
    Okay, the function compiles just fine. But when I try to run it I get:
    select * from table(get_shp_data(226, SYSTIMESTAMP))
    ERROR at line 1:
    ORA-00932: inconsistent datatypes: expected - got -
    ORA-06512: at "SCHEMA.GET_SHP_DATA", line 69
    The line it's blowing up on is "fetch ship_cv bulk collect into shp_data_out" I've checked and verified that the record/object structure SHP_RECORD matches in both type and order the values that are returned by the query. So...what gives? I've been beating my head against this particular problem for several days now and am no closer to a solution.
    Any and all suggestions or corrections gratefully appreciated.
    Oh, and this is being run in a 10g release 2 environment:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, Real Application Clusters, OLAP, Data Mining
    and Real Application Testing options
    HELP??!!

    Hi,
    Even though the fetch is seemingly taking the exact same types, Oracle will still need you to cast the resultset into the proper type.
    Here's a short example of one way of doing it:
    Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.5.0
    Connected as FSITJA
    SQL>
    SQL> create table my_table as select owner, table_name from all_tables where rownum <= 5;
    Table created
    SQL> create or replace type SHP_RECORD as object (owner varchar2(30), table_name varchar2(30));
      2  /
    Type created
    SQL> create or replace type SHP_TABLE as table of SHP_RECORD;
      2  /
    Type created
    SQL> create or replace function get_shp_data(p_owner in my_table.owner%type) return shp_table as
      2    shp_data_out shp_table;
      3    cur_shp sys_refcursor;
      4  begin
      5    open cur_shp for
      6      select cast (multiset(select owner, table_name
      7                              from all_tables
      8                             where owner = p_owner
      9                               and rownum <= 5) as shp_table)
    10         from dual;
    11    fetch cur_shp
    12      into shp_data_out;
    13    return shp_data_out;
    14  end;
    15  /
    Function created
    SQL> select * from table(get_shp_data('SYS'));
    OWNER                          TABLE_NAME
    SYS                            TABLE_PRIVILEGE_MAP
    SYS                            SYSTEM_PRIVILEGE_MAP
    SYS                            STMT_AUDIT_OPTION_MAP
    SYS                            P$POK_CFG
    SYS                            DUALYou might want to check on Pipelined table functions and perhaps the function result cache in the docs, as means to improve your performance.
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/tuning.htm#LNPLS01210
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/subprograms.htm#LNPLS00817

  • How to use stored procedure which returns result set in OBIEE

    Hi,
    I hav one stored procedure (one parameter) which returns a result set. Can we use this stored procedure in OBIEE? If so, how we hav to use.
    I know we hav the Evaluate function but not sure whether I can use for my SP which returns result set. Is there any other way where I can use my SP?
    Pls help me in solving this.
    Thanks

    Hi Radha,
    If you want to cache the results in the Oracle BI Server, you should check that option. When you run a query the Oracle BI Server will get its results from the cache, based on the persistence time you define. If the cache is expired, the Oracle BI Server will go to the database to get the results.
    If you want to use caching, you should enable caching in the nqsconfig.ini file.
    Cheers,
    Daan Bakboord

  • How to create count() measure for certain set of records in BMM Layer

    Hello all.
    I have a logical table like this one (Table AAA)
    Table AAA
    <p>
    --------------------------+<p>
    |       *Key*            |    *Name* |   <p>
    --------------------------+<p>
    |    1-2EMHS9     | AAA      |<p>
    --------------------------+<p>
    | 1-2EMWMO      | BBB      |<p>
    --------------------------+<p>
    |         NULL       |     CCC   |<p>
    --------------------------+<p>
    I need to calculate count() of records where <b>Key is not NULL</b>. In this example, this field must return coun() = 2.
    I suppose, CASE operator may help me with that, but I do not know for sure how to do this.
    Thank you for help,
    Alex.

    Thank you.
    But I must concretise my issue.
    I need to calculate number of records (e.g. order_id) that sutisfy appropriate condition (one of columns (e.g. loy_member_id) is set to null).
    I created logical column, that returns order_id if condition (loy_member_id is null) is met.
    Look at my logical column:
    Q Orders (LPM) - must return number of orders where loyalty_member_id is null.
    It has an expression:
    CASE  WHEN  NOT "Foxtrot (my) replica"."Sales Orders".LOY_MEMBER_ID IS NULL  THEN "Foxtrot (my) replica"."Sales Orders".ORDER_ID ELSE  NULL  END
    So, this returns order_id I need.
    But the question is how to count number of <b>order_id</b>'s returned by this column on BMM Layer.
    When I define my column with next expression:
    *<u>COUNT</u>(CASE WHEN NOT "Foxtrot (my) replica"."Sales Orders".LOY_MEMBER_ID IS NULL THEN "Foxtrot (my) replica"."Sales Orders".ORDER_ID ELSE NULL END)*
    I receive error:
    +[38083] The Attribute 'Q Orders LPM' defines a measure using an obsolete method.+
    Thank you,
    Alex.
    Edited by: Alex B on 3/3/2009 19:59

  • Returning a set of registers in a PL/SQL function

    Does anybody knows if there is some way to return a set of registers (like a cursor) in a PL/SQL function without using a temporary table?
    Thank you

    To: [email protected]
    Sub: Returning a set of registers in a PL/SQL function
    Hi: Nei S
    Create a Package first:
    CREATE OR REPLACE PACKAGE sp_xxxPKG AS
    TYPE RT1 IS RECORD (
    sp_col1 emp.emp_no%TYPE,
    sp_col2 emp.emp_name%TYPE);
    TYPE RCT1 IS REF CURSOR RETURN RT1;
    END;
    Then Create a Procedure:
    CREATE OR REPLACE PROCEDURE sp_xxx (
    RC1 IN OUT sp_xxxPKG.RCT1) AS
    BEGIN
    OPEN RC1 FOR
    SELECT emp_no, emp_name FROM emp;
    RETURN;
    END;
    null

Maybe you are looking for

  • Can you add new Page layouts within an Indesign Document like you can in QuarkXpress using tabs

    I am slowly switching to Indesign from QuarkXpress but have encountered my first hurdle. I have grown up with QuarkXpress and want to change to Indesign. I work as a graphic designer and do large POS projects. These projects require many different si

  • Only V1 hub works on my line. 3 x V2 hubs wont con...

    I've been with BT Broadband for years. The V1 hub was fine - but when I got the V2 hub a year or 2 ago, it just refused to connect to broadband. The light flashes, then settles on solid amber - no connection. I went through various tests with the cal

  • Only the part of a song uploaded to itunes

    Only part of a song uploaded to my itunes on the computer. How do I fix this issue?

  • IPhoto 6.9 not able to sharing to Facebook

    Help, Ive upgraded to Yosemite and iPhoto 9.6 but now my iPhoto isn't allowing me to share photos to my Facebook account. In the Share menu I'm only able to select the Share to Email options. The Facebook, Twitter and flicker account are there but th

  • Remove non-existant AirPort network

    Many versions of iTunes ago I set up an airport network using an airport express called Mandy. Many quarter notes later I'm using AirPlay and all of my iOS devices and iTunes 10.1 are showing Mandy as one of the options for AirPlaying. But when I lau