Unit test, how to test a function which returns a PL/SQL table.

I've got the following type definition:
create or replace type method_tbl as table of varchar2(255);
/I've got the following function
function abc(p_param1 in varchar2) return method_tbl;When I create a unit test for this I am not able to specify what the table should contain on return of the function, all I can see is an empty table. Which is off course one of the unit tests. But I also want to test where the table that is returned contains a number of rows.
Is there something that I'm missing?
Typically the function is called like this:
select * from table(abc('a'));Thanks,
Ronald

>
When I create a unit test for this I am not able to specify what the table should contain on return of the function, all I can see is an empty table. Which is off course one of the unit tests. But I also want to test where the table that is returned contains a number of rows.
Is there something that I'm missing?
>
You will have to create a collection that represents the result set and then compare that to the actual result set.
Assuming tables A and B you would typically have to do
1. SELECT * FROM A MINUS SELECT * FROM B -- what is in A that is NOT in B
2. SELECT * FROM B MINUS SELECT * FROM A -- what is in B that is NOT in A
You could combine those two queries into one with a UNION ALL but since the results are tables and the comparison is more complex it is common to write a function to determine the comparison result.
Here is sample code that shows how to create an expected result collection.
DECLARE
expectedItemList sys.OdciVarchar2List;
functionItemList sys.OdciVarchar2List;
newItemList sys.OdciVarchar2List;
expectedCount INTEGER;
countFunctionItemList INTEGER;
BEGIN
expectedItemList := sys.OdciVarchar2List('car','apple','orange','banana','kiwi');
expectedCount := 5; -- or query to count them
functionItemList := sys.OdciVarchar2List('car','apple','orange','peanut');
-- use your function to get the records
-- select * from myFunctino BULK COLLECT INTO functionItemList
IF functionItemList.count != expectedCount THEN
  DBMS_OUTPUT.PUT_LINE('Count is ' || functionItemList.count || ' but should be ' || expectedCount);
END IF;
END;
Count is 4 but should be 5If the collections are the same type you can use the MULTISET operators.
See Solomon's reply in this thread for how to use the MULTISET operators on collections.
PLS-00306: wrong number or type of argument in call to 'MULTISET_UNION_ALL'
See MultisetOperators in the SQL Reference doc
http://docs.oracle.com/cd/B13789_01/server.101/b10759/operators006.htm
>
Multiset operators combine the results of two nested tables into a single nested table.

Similar Messages

  • How to call a function, which name is stored in table?

    Dear members,
    I have a function with return number, and store its name in a table.
    now I want to select this function name from table and run it and return the value to a variable in my form.
    here is my code in when-button-pressed trigger.
    DECLARE
         v_value number;
         V_FUNC VARCHAR2(100);
         V_PARAM VARCHAR2(100);
    begin
         select FUNCTION_NAME, PARAM
         INTO V_FUNC, V_PARAM
         from function_table
         where id =1;
         message('V_FUNC='||V_FUNC); pause;
         v_value := v_func||';'; --run_tb_function;
         :text01 := v_value;
    end;this code gives the following error:
    ora-06502
    regards:
    Edited by: user2040934 on Feb 2, 2013 9:47 AM

    Below is the modified code:
    DECLARE
         v_value number;
         V_FUNC VARCHAR2(100);
         V_PARAM VARCHAR2(100);
    v_cmd varchar2(1000);
    begin
         select FUNCTION_NAME, PARAM
         INTO V_FUNC, V_PARAM
         from function_table
         where id =1;
    -- create a valuetable with one column vval varchar2 type
         v_cmd := 'declare val varchar2(100); Begin val := '||v_func||'; delete from valuetable; insert into valuetable(vval) values (v); commit; end;';
    forms_ddl(v_cmd);
    begin
    select vval into :text01 from valuetable where rownum = 1;
    exception
    when no_data_found then
    -- do your action....
    null;
    end;
    end;
    Edited by: user5213229 on Feb 2, 2013 4:33 PM

  • How to create a function that returns multiple rows in table

    Dear all,
    I want to create a funtion that returns multiple rows from the table (ex: gl_balances). I done following:
    -- Create type (successfull)
    Create or replace type tp_gl_balance as Object
    PERIOD_NAME VARCHAR2(15),
    CURRENCY_CODE VARCHAR2(15),
    PERIOD_TYPE VARCHAR2(15),
    PERIOD_YEAR NUMBER(15),
    BEGIN_BALANCE_DR NUMBER,
    BEGIN_BALANCE_CR NUMBER
    -- successfull
    create type tp_tbl_gl_balance as table of tp_gl_balance;
    but i create a function for return some rows from gl_balances, i can't compile it
    create or replace function f_gl_balance(p_period varchar2) return tp_tbl_gl_balance pipelined
    as
    begin
    return
    (select gb.period_name, gb.currency_code, gb.period_type, gb.period_year, gb.begin_balance_dr, gb.begin_balance_cr
    from gl_balances gb
    where gb.period_name = p_period);
    end;
    I also try
    create or replace function f_gl_balance(p_period varchar2) return tp_tbl_gl_balance pipelined
    as
    begin
    select gb.period_name, gb.currency_code, gb.period_type, gb.period_year, gb.begin_balance_dr, gb.begin_balance_cr
    from gl_balances gb
    where gb.period_name = p_period;
    return;
    end;
    Please help me solve this function.
    thanks and best reguard

    hi,
    Use TABLE FUNCTIONS,
    [http://www.oracle-base.com/articles/9i/PipelinedTableFunctions9i.php]
    Regards,
    Danish

  • How to call Java function which returns byteArray

    context I have a class say
    public class ByteArray{
      public byte[] getByteArray(String str){
           return str.getBytes();
    }Consider i have object of ByteArray (some how) in native C code. I want to call getByteArray("Test") and obtain a byteArray. what is the C JNI function can i use?

    hy
    CREATE OR REPLACE FUNCTION GET_SAL1(NN in NUMBER)
    RETURN BOOLEAN
    IS
    BEGIN
    INSERT INTO STD(ENO) VALUES(NN);
    RETURN TRUE;
    EXCEPTION
    WHEN OTHERS THEN
    RETURN false;
    END;
    you can call :
    if GET_SAL1(NN) then
    else
    error
    end if;
    I hope i understand
    Regards

  • Function which returns multiple values that can then be used in an SQL Sele

    I'd like to create a function which returns multiple values that can then be used in an SQL Select statement's IN( ) clause
    Currently, the select statement is like (well, this is a very simplified version):
    select application, clientid
    from tbl_apps, tbl_status
    where tbl_apps.statusid = tbl_status.statusid
    and tbl_status.approved > 0;
    I'd like to pull the checking of the tbl_status into a PL/SQL function so my select would look something like :
    select application, clientid
    from tbl_apps
    where tbl_apps.statusid in (myfunction);
    So my function would be running this sql:
    select statusid from tbl_status where approved > 0;
    ... will return values 1, 5, 15, 32 (and more)
    ... but I haven't been able to figure out how to return the results so they can be used in SQL.
    Thanks for any help you can give me!!
    Trisha Gorr

    Perhaps take a look at pipelined functions:
    Single column example:
    SQL> CREATE OR REPLACE TYPE split_tbl IS TABLE OF VARCHAR2(32767);
      2  /
    Type created.
    SQL> CREATE OR REPLACE FUNCTION split (p_list VARCHAR2, p_delim VARCHAR2:=' ') RETURN SPLIT_TBL PIPELINED IS
      2      l_idx    PLS_INTEGER;
      3      l_list   VARCHAR2(32767) := p_list;
      4      l_value  VARCHAR2(32767);
      5    BEGIN
      6      LOOP
      7        l_idx := INSTR(l_list, p_delim);
      8        IF l_idx > 0 THEN
      9          PIPE ROW(SUBSTR(l_list, 1, l_idx-1));
    10          l_list := SUBSTR(l_list, l_idx+LENGTH(p_delim));
    11        ELSE
    12          PIPE ROW(l_list);
    13          EXIT;
    14        END IF;
    15      END LOOP;
    16      RETURN;
    17    END SPLIT;
    18  /
    Function created.
    SQL> SELECT column_value
      2  FROM TABLE(split('FRED,JIM,BOB,TED,MARK',','));
    COLUMN_VALUE
    FRED
    JIM
    BOB
    TED
    MARK
    SQL> create table mytable (val VARCHAR2(20));
    Table created.
    SQL> insert into mytable
      2  select column_value
      3  from TABLE(split('FRED,JIM,BOB,TED,MARK',','));
    5 rows created.
    SQL> select * from mytable;
    VAL
    FRED
    JIM
    BOB
    TED
    MARK
    SQL>Multiple column example:
    SQL> CREATE OR REPLACE TYPE myrec AS OBJECT
      2  ( col1   VARCHAR2(10),
      3    col2   VARCHAR2(10)
      4  )
      5  /
    Type created.
    SQL>
    SQL> CREATE OR REPLACE TYPE myrectable AS TABLE OF myrec
      2  /
    Type created.
    SQL>
    SQL> CREATE OR REPLACE FUNCTION pipedata(p_str IN VARCHAR2) RETURN myrectable PIPELINED IS
      2    v_str VARCHAR2(4000) := REPLACE(REPLACE(p_str, '('),')');
      3    v_obj myrec := myrec(NULL,NULL);
      4  BEGIN
      5    LOOP
      6      EXIT WHEN v_str IS NULL;
      7      v_obj.col1 := SUBSTR(v_str,1,INSTR(v_str,',')-1);
      8      v_str := SUBSTR(v_str,INSTR(v_str,',')+1);
      9      IF INSTR(v_str,',')>0 THEN
    10        v_obj.col2 := SUBSTR(v_str,1,INSTR(v_str,',')-1);
    11        v_str := SUBSTR(v_str,INSTR(v_str,',')+1);
    12      ELSE
    13        v_obj.col2 := v_str;
    14        v_str := NULL;
    15      END IF;
    16      PIPE ROW (v_obj);
    17    END LOOP;
    18    RETURN;
    19  END;
    20  /
    Function created.
    SQL>
    SQL> create table mytab (col1 varchar2(10), col2 varchar2(10));
    Table created.
    SQL>
    SQL> insert into mytab (col1, col2) select col1, col2 from table(pipedata('(1,2),(2,3),(4,5)'));
    3 rows created.
    SQL>
    SQL> select * from mytab;
    COL1       COL2
    1          2
    2          3
    4          5

  • Plsql use a function which returns a ref cursor

    Hi
    I've been using an function which returns a ref cursor. I've been returning this into a java resultset. Fine!
    Now i'm in plsql and want to use the same function. I'm not sure how to get this resultset in plsql.

    It's not very practical to use a refcursor like you want to, but here you go
    create or replace function test_ref
    return sys_refcursor
    is
    v_rc sys_refcursor;
    begin
    open v_rc for select emp_name  from emp ;
    return v_rc;
    end;
    declare
    v_rc sys_refcursor;
    v_emp_name emp.emp_name%type;
    begin
    v_rc :=  test_ref ;
    loop
        fetch v_rc into v_emp_name ;
        exit when v_rc%notfound ;
        dbms_output.put_line('Employee Name: '||v_emp_name );
    end loop;
    end;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to create and execute a function whose return value is  a table

    hi folks ,
    i would like know how to create and execute a function whose return value is a table ,
    am new to pl/sql ,
    my statement for the function is
    SELECT ct.credential_code, c.expiration_date
    FROM certifications c, credential_types ct
    WHERE ct.crdnt_id = c.crdnt_id
    AND c.person_id = person_id;
    i would like to have the result of the above query as return value for the function.
    Thanks in advance ,
    Ashok.c

    hi Ps ,
    Can you please do small sample ,
    that would help me in clear understanding
    thanks in advance
    ashok.c

  • Error while calling the function which returns SQL Query!!!

    Hi,
    I have a Function which returns SQL query. I am calling this function in my APEX report region source.
    The query is dynamic SQL and its size varies based on the dynamic "where clause" condition.
    But I am not able to execute this function.It gives me the following error in APEX region source.
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    Even in SQL* Plus or SQL developer also same error .
    The length of my query is more than 4000. I tried changing the variable size which holds my query in the function.
    Earlier it was
    l_query varchar2(4000)
    Now I changed to
    l_query varchar2(32767).
    Still it is throwing the same error.
    Can anybody help me to resolve this.???
    Thanks
    Alaka

    Hi Varad,
    I am already using 32k of varchar2. Then also it is not working.
    It is giving the same error. I think there is something to do with buffer size.
    My query size is not more than 4200. Even if i give 32k of varchar2 also buffer is able to hold only 3997 size of the query only.
    Error is
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    Tried CLOB also. It is not working.
    Any other solution for this.
    Thanks
    Alaka

  • How to pass values and see outout of PL/SQL Tables, SYS_REFCURSORs?

    I am new to SQL Developer (Version 3.0.02).
    Our QC division wants to test stored procedures using SQL Developer.
    I tried to test procedures with PL/SQL tables and SYS_REFCURSORS as input and output parameters.
    When we run it by pressing the green arrow we get the Run PL/SQL window.
    How can we:
    - Put values to SYS_REFCURSOR and PL/SQL table type input parameters?
    - How can we display SYS_REFCURSOR and PL/SQL table type output parameters?
    All this time we were using SQL*Navigator. In Navigator the PL Tables and SYS_REFCURSORs outputs are shown in a nice grid.
    Here, in SQL Developer, do we have to WRITE our own code to input and display these types of parameters????

    Hi Channa,
    Yes in SQL Developer 3.0 you will have to write your own code to test out ref cursors.
    I had created test harness scripts for all my procedures having ref cursors as parameters.
    And I had to dbms_output all the values on the screen.
    Probably a limitation of the SQL Developer 3.0 tool.
    In case you come across different solution to this do let me know also.
    Thanks,
    Viju
    blog: http://whizdba.wordpress.com

  • How to call function which return and out

    My function specifcation is
    FUNCTION GetGoogleScholarActivation (
    pi_clnt_id IN google_scholar_status.clnt_id%TYPE,
    pi_status_type IN ci_status_type_tab_type,
    po_status OUT ci_status_tab_type,
    po_date OUT ci_date_tab_type
    RETURN NUMBER ;
    where type is
    TYPE ci_status_type_tab_type IS TABLE OF VARCHAR2 (1) INDEX BY BINARY_INTEGER;
    TYPE ci_status_tab_type IS TABLE OF VARCHAR2 (10) INDEX BY BINARY_INTEGER;
    TYPE ci_date_tab_type IS TABLE OF VARCHAR2 (8) INDEX BY BINARY_INTEGER;
    I am trying to call function in SQL PLUS for testing as
    declare
    var number ( 10);
    TYPE p_st1 IS TABLE OF VARCHAR2 (1) INDEX BY BINARY_INTEGER;
    p_st p_st1 ;
    type p_status1 IS TABLE OF VARCHAR2 (1) INDEX BY BINARY_INTEGER;
    p_status p_status1 ;
    TYPE p_date1 IS TABLE OF VARCHAR2 (8) INDEX BY BINARY_INTEGER;
    p_date p_date1 ;
    Begin
    p_st(0) := 'A';
    var := PQDKGOSH.GetGoogleScholarActivation(11920 , p_st, p_status ,p_date );
    dbms_output.put_line ('Activation_status '|| p_status(0) );
    dbms_output.put_line ('Activation_date '|| p_date(0) );
    dbms_output.put_line ('Retun Value'|| var );
    End;
    but getting error PLS-00306: wrong number or types of arguments in call to
    'GETGOOGLESCHOLARACTIVATION'
    so how to test from SQL Plus

    HI
    I tried to execute below like this
    declare
    var number ( 10);
    p_st ci_status_type_tab_type ;
    p_status ci_status_tab_type;
    p_date ci_date_tab_type;
    Begin
    p_st(0) := 'A';
    var := PQDKGOSH.GetGoogleScholarActivation(11920 , p_st, p_status ,p_date );
    dbms_output.put_line ('Activation_status '|| p_status(0) );
    dbms_output.put_line ('Activation_date '|| p_date(0) );
    dbms_output.put_line ('Retun Value'|| var );
    End;
    still iget error
    PLS-00201: identifier 'CI_STATUS_TYPE_TAB_TYPE' must be declared
    becuse this declareation i did in package specification .
    and i am trying to execute the function .

  • How to call oracle Function which has If else condition in Data Template

    Hi,
    currently I am working on creating Data Template which uses a Oracle Function which I need to make use in my data template. But I have some confusions on using the same. Could anybody please help me in this regard.
    I have a function like this,
    function invoice_query (p_facility_id facility.facility_id%TYPE,
    p_wave_nbr pick_directive.wave_nbr%TYPE,
    p_container_id unit_pick_group_detail.container_id%TYPE,
    p_distro_nbr unit_pick_group_detail.distro_nbr%TYPE) return invoice_refcur IS
    refcur invoice_refcur;
    begin
    IF p_wave_nbr IS NOT NULL THEN
    OPEN refcur FOR SELECT t1.distro_nbr,
    t1.cust_order_nbr,
    t1.pick_not_before_date,
    SYSDATE,
    t1.ship_address_description,
    t1.ship_address1,
    t1.ship_address2,
    t1.ship_address3,
    t1.ship_address4,
    t1.ship_address5,
    t1.ship_city || ', ' || t1.ship_state || ' ' || t1.ship_zip,
    t1.ship_country_code,
    t1.bill_address_description,
    t1.bill_address1,
    t1.bill_address2,
    t1.bill_address3,
    t1.bill_address4,
    t1.bill_address5,
    t1.bill_city || ', ' || t1.bill_state || ' ' || t1.bill_zip,
    t1.bill_country_code,
    min(t2.pick_order),
    NULL,
    t2.wave_nbr
    FROM stock_order t1,
    pick_directive t2,
    unit_pick_group_detail t3
    WHERE t1.facility_id = t2.facility_id
    AND t1.facility_id = t3.facility_id
    AND t2.facility_id = t3.facility_id
    AND t1.distro_nbr = t2.distro_nbr
    AND t1.distro_nbr = t3.distro_nbr
    AND t2.distro_nbr = t3.distro_nbr
    AND t1.facility_id = p_facility_id
    AND t2.wave_nbr = p_wave_nbr
    AND g_scp(p_facility_id, 'interface_tcp_flag') = 'N'
    AND t2.pick_type = 'U'
    AND t3.group_id in (SELECT t4.group_id
    FROM unit_pick_group t4
    WHERE t4.facility_id = p_facility_id
    AND t4.wave_nbr = p_wave_nbr)
    GROUP BY t1.distro_nbr,
    t1.cust_order_nbr,
    t1.pick_not_before_date,
    t1.ship_address_description,
    t1.ship_address1,
    t1.ship_address2,
    t1.ship_address3,
    t1.ship_address4,
    t1.ship_address5,
    t1.ship_city || ', ' || t1.ship_state || ' ' || t1.ship_zip,
    t1.ship_country_code,
    t1.bill_address_description,
    t1.bill_address1,
    t1.bill_address2,
    t1.bill_address3,
    t1.bill_address4,
    t1.bill_address5,
    t1.bill_city || ', ' || t1.bill_state || ' ' || t1.bill_zip,
    t1.bill_country_code,
    t2.wave_nbr
    ORDER BY MIN(t3.group_id), MAX(t3.slot);
    elsif p_container_id is not null then
    OPEN refcur FOR SELECT distinct t1.distro_nbr,
    t1.cust_order_nbr,
    t1.pick_not_before_date,
    SYSDATE,
    t1.ship_address_description,
    t1.ship_address1,
    t1.ship_address2,
    t1.ship_address3,
    t1.ship_address4,
    t1.ship_address5,
    t1.ship_city || ', ' || t1.ship_state || ' ' || t1.ship_zip,
    t1.ship_country_code,
    t1.bill_address_description,
    t1.bill_address1,
    t1.bill_address2,
    t1.bill_address3,
    t1.bill_address4,
    t1.bill_address5,
    t1.bill_city || ', ' || t1.bill_state || ' ' || t1.bill_zip,
    t1.bill_country_code,
    NULL,
    t2.dest_id,
    null
    FROM stock_order t1,
    unit_pick_group_detail t2
    WHERE t1.facility_id = t2.facility_id
    and t1.distro_nbr = t2.distro_nbr
    and t1.facility_id = p_facility_id
    AND g_scp(p_facility_id, 'interface_tcp_flag') = 'N'
    AND t2.container_id = p_container_id;
    else
    open refcur for SELECT distinct t1.distro_nbr,
    t1.cust_order_nbr,
    t1.pick_not_before_date,
    SYSDATE,
    t1.ship_address_description,
    t1.ship_address1,
    t1.ship_address2,
    t1.ship_address3,
    t1.ship_address4,
    t1.ship_address5,
    t1.ship_city || ', ' || t1.ship_state || ' ' || t1.ship_zip,
    t1.ship_country_code,
    t1.bill_address_description,
    t1.bill_address1,
    t1.bill_address2,
    t1.bill_address3,
    t1.bill_address4,
    t1.bill_address5,
    t1.bill_city || ', ' || t1.bill_state || ' ' || t1.bill_zip,
    t1.bill_country_code,
    NULL,
    NULL,
    t3.wave_nbr
    FROM stock_order t1,
    unit_pick_group_detail t2,
    unit_pick_group t3
    WHERE t1.facility_id = t2.facility_id
    and t2.facility_id = t3.facility_id
    and t1.distro_nbr = t2.distro_nbr
    and t2.group_id = t3.group_id
    and t1.facility_id = p_facility_id
    AND g_scp(p_facility_id, 'interface_tcp_flag') = 'N'
    AND t2.distro_nbr = p_distro_nbr;
    END IF;
    return refcur;
    end;
    I have created data template like following,
    <sqlStatement name="Q_INVOICE">
                   <![CDATA[
              SELECT Pack_Slip_R.invoice_query(:P_FACILITY_ID,:P_WAVE_NBR,:P_CONTAINER_ID,:P_DISTRO_NBR) from dual
                                                     ]]>
    </sqlStatement>
    But how does I create a element for the "t1.ship_city || ', ' || t1.ship_state || ' ' || t1.ship_zip" column in the oracle function. I normally create an element like following,
    <group name="G_INVOICE" source="Q_INVOICE">
                   <element name="CUST_ORDER_NBR" value="cust_order_nbr"/>
                   <element name=":dest_id" value="dest_id"/>
    </Group>
    But how do i create element if a column name is kind of dynamic. Please help. I cannot Rename/change the Column in SQL Query. Please let me know If I could handle this whole logic in BI Publsiher.
    Regards,
    Ashoka BL

    try useing alias
    t1.ship_city || ', ' || t1.ship_state || ' ' || t1.ship_zip as <COLUMN_ALIAS>

  • How to call a function which has a cursor

    hey folks I have a function which has a cursor,,like this
    CREATE OR REPLACE FUNCTION EMPCU RETURN VARCHAR
    AS
    CURSOR EMPC IS
    SELECT LNAME,SALARY,SSN
    FROM EMPLOYEE
    WHERE DNO IN(4,5);
    EMPV EMPC%ROWTYPE;
    BEGIN
    OPEN EMPC;
    LOOP
    FETCH EMPC INTO EMPV;
    EXIT WHEN EMPC%NOTFOUND;
    /*DBMS_OUTPUT.PUT_LINE(EMPV.LNAME||' '||EMPV.SALARY||' '||EMPV.SSN);*/
    RETURN EMPV. LNAME ||' '|| EMPV.SALARY||' '||EMPV.SSN;
    END LOOP;
    CLOSE EMPC;
    END EMPCU;
    Above function created successfully. I called above function like this
    DECLARE
    ENAMESAL VARCHAR2(70);
    BEGIN
    ENAMESAL:=EMPCU();
    DBMS_OUTPUT.PUT_LINE(ENAMESAL);
    END;
    Function is called and function is returning only one row instead of 7 rows. Actually cursor is supposed to return 7 rows but it is returning only one row. Is there any snytax to call a function which has a cursor. So experts please tell me where I have to make changes. I would be very thankful to you

    Well, you've told the function to RETURN within the loop, so after the first record in the loop, the function returns as you've instructed it.
    You would need to change your function to accept a specific input from the EMP table and then do a look up for that specific record and return the values you wanted, and wrap the function call in a loop in your anonymous block.
    Or you could just have the anonymous block like this....
    BEGIN
       FOR X IN
          SELECT EMPV. LNAME ||' '|| EMPV.SALARY||' '||EMPV.SSN AS Line_Data
          FROM EMPLOYEE
          WHERE DNO IN(4,5)
       LOOP 
          DBMS_OUTPUT.PUT_LINE(x.Line_Data);
       END LOOP;     
    END;
    /

  • How to create a structure which can hold a dynamic table as a field in DDIC

    Hi ,
           I am designing a solution for a problem and have a unique requirement.  I need to create a structure which can hold a field where dynamic table data can be stored.  Let me illustrate with an example :
    My structure  ( say  Z_output_struc ) will have the fields
    Table_name  Table_Data
    My function module will have a table type of the above structure, so in effect ,my output can have multiple table names and related to each of them, there will be table data of that table name. The issue is how do I configure this in DDIC ?
    I tried creating table_data as "Type ref to Data"  but was stuck  inside the func module when I tried to transfer data to this.
    Any pointers as to how to think about this differently ? 
    Best Regards,
    Girish

    Hi Girish,
    you start directly from the ref to data. You assign it to a field symbol and cast this to the type of the destination of your select. So you can directly add the reference to the cache:
    I hope this example helps a bit (I took a form instead of a function module as it is easier to add here and used an hr table as kna1 is empty on my test system):
    REPORT  z_rwe_99_dyn_tab_cache.
    * type definition
    TYPES:
      BEGIN OF _s_cache,
        table TYPE        tabname16,
        cache TYPE REF TO data,
      END   OF _s_cache,
      _t_cache TYPE STANDARD TABLE OF _s_cache.
    * data declaration
    DATA:
      lv_table     TYPE tabname16,
      lv_condition TYPE string,
      lt_cache     TYPE _t_cache.
    * define table and condition
    lv_table     = 'HRP1000'.
    lv_condition = 'plvar = ''01'' and otype = ''S'' and objid = ''50000016'''.
    * get the result of a single table into the cache
    PERFORM get_dyn_table USING
                            lv_table
                            lv_condition
                          CHANGING
                            lt_cache.
    * form to read a single table
    FORM get_dyn_table USING
                         iv_table     TYPE tabname16
                         iv_condition TYPE string
                       CHANGING
                         ct_cache     TYPE _t_cache.
      FIELD-SYMBOLS:
        <lt_table> TYPE ANY TABLE.
      DATA:
        ls_cache TYPE        _s_cache,
        lr_data  TYPE REF TO data.
      CREATE DATA lr_data TYPE STANDARD TABLE OF (iv_table).
      ASSIGN lr_data->* TO <lt_table>.
      SELECT * FROM (iv_table) INTO TABLE <lt_table>
        WHERE
          (iv_condition).
      ls_cache-table = lv_table.
      ls_cache-cache = lr_data.
      APPEND ls_cache TO ct_cache.
    ENDFORM.                    "get_dyn_table
    If you have more questions just give another post.
    Best Regards
    Roman

  • How to call package function and procedure by PL/SQL

    Dear all,
    I created a package and I want test it by a select statement. e.g. select packagename.function(1, 'A') . However, there is an error message. "ORA-14551: cannot perform a DML operation inside a query ".
    In the package, there is a function and I passed two parameters to the function and return a number. These two parameters will be used in the cursor select statment. Is there sth wrong that I use the cursor with the parameters? What can I do then?
    On the other hand, I want to test the package procedure by using select statement in SQL Plus. How can I call it (with parameter)?
    Remark: I am using Oracle 8i.
    Thanks for advance!!
    Regrads.

    Hi!
    I don't know why it is not running in ur computer. Pls check the script --
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace package pack_test
      2  is
      3    function try_test(eno in number,depno in number)
      4    return number;
      5* end;
    SQL> /
    Package created.
    SQL> create or replace package body pack_test
      2  is
      3    function try_test(eno in number,depno in number)
      4    return number
      5    is
      6      saln number(10);
      7    begin
      8      select sal
      9   into saln
    10   from emp
    11   where empno = eno
    12   and deptno = depno;
    13  
    14   return saln;
    15    end;
    16  end pack_test;
    17  /
    Package body created.
    SQL>
    SQL> select pack_test.try_test(7777,30) from dual;
    PACK_TEST.TRY_TEST(7777,30)
                           3456-it is working fine in my system.
    Regards.
    Satyaki De.

  • How to get a function to return a value occuring after a character

    I need to write a function to return the next value occurring after the ":" character in a column. If multiple values of ":" occurs then the function should return the sum of the next value occurring after each ":" in the column.
    For example a rating value of 4:1 would return the value of 1. However, the rating of "5:1:1" should return a value of 1+1 = 2, and 6:2:1 will return of 2+1 = 3.
    I have the below function skeletion and trying to figure out how the select statement will compute based on the position of : in the column and add the values and return the value back to function.
    Function fn_check_internalrating(p_internalrating IN VARCHAR2)
          RETURN number
    IS
        cnumber number;
        cursor c1 is
       select ................................
    BEGIN
    open c1;
    fetch c1 into cnumber;
    close c1;
    RETURN cnumber;
    EXCEPTION
    WHEN OTHERS
    THEN RETURN NULL;
    END;

    Hi,
    You don't need a cursor: there's no table involved in this function, and no point in using any table.
    Here's one way:
    CREATE OR REPLACE FUNCTION  fn_check_internalrating
    (   p_internalrating   IN   VARCHAR2
    ,   p_delimiter            IN   VARCHAR2     DEFAULT     ':'
    RETURN  NUMBER
    DETERMINISTIC          -- Same input always produces same output
    IS
        cnumber     NUMBER     := 0;               -- value to be returned
        pos          PLS_INTEGER := INSTR ( p_internalrating
                                        , p_delimiter
                             );          -- position where delimiter was found
    BEGIN
        WHILE  pos != 0
        LOOP
            cnumber := cnumber + TO_NUMBER ( SUBSTR ( p_internalrating
                                                  , pos + 1
                                         , 1
         pos := INSTR ( p_internalrating
                          , p_delimiter
                   , pos + 1
        END LOOP;
        RETURN cnumber;
    END fn_check_internalrating;
    SHOW ERRORSThis assumes the function is a stand-alone function. If it's part of a package, you don't say CREATE OR REPLACE at the beginning.
    Try to make functions generic, so that if a similar (but not identical) situation comes up in 6 months from now, you can use the same function. I'm guessing that somethimes you may want to do the same thing with some character other than ':' before each number, so I added the 2nd (optional) argument p_delimiter. You can call the fucntion with either 1 or 2 arguments.
    If an error occurs in a PL/SQL fucntion, an error message (showing the exact location of the error) is displayed, and execution halts. If you use an EXCEPTION sectinn, you lose all that functionality, or have to code it yourself. Only use an EXCEPTION handler when you really have to.
    For this function, you may or may not want to. For example, if the character right after a delimiter is not a digit, the call to TO_NUMBER in function will raise "ORA-01722: invalid number". You may want to catch that error in an exception handler, and return 0 or NULL. On the other hand, you may want to test that the character after the delimiter is a digit before calling TO_NUMBER, and not have an EXCEPTION section.
    What else could go wrong? Try to think of potential problems and fix them when you first write the function. If you discover an error next year, you'll have to spend a fair amount of time finding the function, and getting acquainted with it again.
    What should the function return if p_internalrating is NULL, or doesn't contain any delimiters?
    What if there's a number longer than 1 digit after a delimiter, e.g. '6:78:9'?

Maybe you are looking for

  • Error while creating the Excise Doc in J1IIN

    Hi Friends, When we are trying to create an excise doc using J1IIN, we are getting error: "Error updating table J_1IPART2." What could be the possible reason for this? Regards, Abhishek

  • CS1 Install/Uninstall Problems ?

    I can't uninstall CS1, nor can can I reinstall Photoshop from CS1, which is presently not installed. My OS is Windows Vista Home Premium. I am out of warranty and Adobe will not provide suppport. I have read all I can find about FLEXnet licensing sus

  • Create oracle table from sql server

    Dear Gurus, I need to create some tables from sql server 2008 to a oracle 11g database. Some tables contain vbinary datatype. Now my queries are 1. How can I do that? 2. If DB link is a solution then would you please provide me a step by step process

  • How to access the ms access database in the JApplet?

    I am New here. Please help me. I am create one java file to access MS access the database in the JApplet. It say "Access denied". How to access the ms access database in the JApplet? Message was edited by: SVPRM

  • Time Machine NAS Backup HELP!!!

    Have been in and out of a local mac store to no avail. Heres the story so far..... A few weeks ago I made a time machine backup of my Macbook on a Buffalo linkstation NAS. I followed instructions from the internet in which I made a sparsebundle image