String_to_table - cast vc_arr2 to table

Hi all,
Is there an easy way or a workaround to cast the result of string_to_table function to a table ?
Edit : I don't want to use for loop because i need to add lots of members in a collection using add_members procedure.
I try to do something like this :
DECLARE
   loc_test   htmldb_application_global.vc_arr2;
BEGIN
   loc_test := apex_util.string_to_table('a:b:c');
   -- Test code --
   SELECT first_table.*, second_table.name
   FROM table(cast(loc_test as vc_arr2)) first_table, second_table
   WHERE first_table.id = second_table.id;
   -- Add members in collection
END;Regards,
Grégory
Message was edited by:
mercierg

Gregory,
You can only cast an SQL array type the way you want it. Looks like the VC_ARR2 type is a PL/SQL array: "... type APEX_APPLICATION_GLOBAL.VC_ARR2. This array is a VARCHAR2(32767) table."
Sima

Similar Messages

  • How to type cast PL/SQL table to REF cursor?

    any one knows how to CAST PL/SQl table to Ref cursor?
    eg
    procedure some_name(r_out out sys_refcurosr)
    IS
    type t is table of tab%ROWTYPE;
    my_type t;
    begin
    select * bulk collect into my_type from tab;
    r_out := my_type; -- need help here..
    end;
    it's 10g

    ref cursor is pointer to result set. You can not cast to PL/SQL table.
    1 create or replace procedure some_name(r_out out sys_refcursor)
    2 IS
    3 begin
    4 OPEN r_out for select * from emp;
    5* end;
    SQL> /
    Procedure created.
    SQL> var mycursor refcursor;
    SQL> exec some_name(:mycursor);
    PL/SQL procedure successfully completed.
    SQL> set linesize 2000
    SQL> print :mycursor;
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7369 SMITH CLERK 7902 12/17/80 00:00:00 800 20
    7499 ALLEN SALESMAN 7698 02/20/81 00:00:00 1600 300 30
    7521 WARD SALESMAN 7698 02/22/81 00:00:00 1250 500 30
    7566 JONES MANAGER 7839 04/02/81 00:00:00 2975 20
    7654 MARTIN SALESMAN 7698 09/28/81 00:00:00 1250 1400 30
    7698 BLAKE MANAGER 7839 05/01/81 00:00:00 2850 30
    7782 CLARK MANAGER 7839 06/09/81 00:00:00 2450 10
    7788 SCOTT ANALYST 7566 04/19/87 00:00:00 3000 20
    7839 KING PRESIDENT 11/17/81 00:00:00 5000 10
    7844 TURNER SALESMAN 7698 09/08/81 00:00:00 1500 0 30
    7876 ADAMS CLERK 7788 05/23/87 00:00:00 1100 20
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7900 JAMES CLERK 7698 12/03/81 00:00:00 950 30
    7902 FORD ANALYST 7566 12/03/81 00:00:00 3000 20
    7934 MILLER CLERK 7782 01/23/82 00:00:00 1300 10
    14 rows selected.

  • Question on using CAST, MULTISET and TABLE

    Hi,
    I am trying to do something that is utterly meaningless, but I am studying the use of CAST with MULTISET and TABLE.
    I have created a type: a Nested Table of Number values:
    create type numTable as table of number;
    Now I perform the following query:
    select d.dname
    , ( select avg(column_value)
    from table
    ( cast( d.salaries as numTable)
    ) Department_Avg_Salary
    from ( select cast
    ( multiset
    ( select e.sal
    from emp e
    where e.deptno = d1.deptno
    ) as numTable
    ) salaries
    , d1.dname
    from dept d1
    ) d
    I had expected to see each department name and the average salary within that department. Instead, I see the same Department_Avg_Salary value for each row - the average of the first department:
    DNAME DEPARTMENT_AVG_SALARY
    ACCOUNTING 1875
    RESEARCH 1875
    SALES 1875
    OPERATIONS 1875
    However, when I change the query to the following:
    select d.dname
    , d.salaries
    from ( select cast
    ( multiset
    ( select e.sal
    from emp e
    where e.deptno = d1.deptno
    ) as numTable
    ) salaries
    , d1.dname
    from dept d1
    ) d
    I get the following result - note that each department shows the correct list of salaries, not the list of the 1st department's salaries over and over.
    DNAME
    SALARIES
    ---------------------------------------------------------ACCOUNTING
    NUMTABLE(2450, 1300)
    RESEARCH
    NUMTABLE(800, 2975, 3000, 5000, 1100, 3000)
    SALES
    NUMTABLE(1600, 1250, 1250, 2850, 1500, 950)
    OPERATIONS
    NUMTABLE()
    Can someone explain why the
    , ( select avg(column_value)
    from table
    ( cast( d.salaries as numTable)
    ) Department_Avg_Salary
    does not give an average per department but instead only the first department's average?
    thanks for your help!
    regards
    Lucas Jellema

    scott@ORA92> select d.dname,
      2           (select avg(column_value)
      3            from   table (cast (d.salaries as numTable))
      4            where d.dname = dname) Department_Avg_Salary
      5  from   (select cast (multiset (select e.sal
      6                          from   emp e
      7                          where  e.deptno = d1.deptno) as numTable) salaries,
      8                 d1.dname
      9            from    dept d1) d
    10  /
    DNAME          DEPARTMENT_AVG_SALARY
    ACCOUNTING                2916.66667
    RESEARCH                        2175
    SALES                     1566.66667
    OPERATIONS

  • Problem about casting in internal tables

    Hello,
    TYPES:
      BEGIN OF ts_matnr,
        matnr TYPE matnr,
        objct TYPE cuobj,
      END   OF ts_matnr.
      tables: mara.
    DATA:
      myStatus(20) type c,
      mySTANDARDCLASS(20) type c,
      gt_matnr TYPE STANDARD TABLE OF ts_matnr WITH DEFAULT KEY,
      gs_matnr LIKE LINE OF gt_matnr,
      gs_mara  TYPE mara.
    SELECT-OPTIONS:
      pr_matnr FOR gs_mara-matnr.
    START-OF-SELECTION.
    SELECT matnr
           matnr AS objct
           FROM mara
           INTO CORRESPONDING FIELDS OF TABLE gt_matnr WHERE matnr IN pr_matnr.
    I want to write both the normal String and the value as object  into the table. But there is a error at the select saying the fields can't be converted to target field.
    I don't know what the problem is. Can you see it?
    Edited by: Daniel Gerne on Apr 23, 2008 2:31 PM

    unfortunately, I just saw that I just walked around my problem instead of solving it. The reason I want to have this MATNR is that I need to use it as Objectkey for a BAPI call:
    LOOP AT gt_matnr INTO gs_matnr.
    CALL FUNCTION 'BAPI_OBJCL_GETDETAIL_KEY'
      EXPORTING
    *    CLOBJECTKEY           = gt_matnr-objct "nicht Tabelle, sondern Arbeitsbereich
        CLOBJECTKEY           = gs_matnr-objct "hat Typ OBJCT <=> BAPI1003_KEY-OBJECT_GUID
        CLASSNUM              = 'FARBIGE_UNTERLAGEN'
    *   KEYDATE               = SY-DATUM
    *   LANGUAGE              = SY-LANGU
    IMPORTING
       STATUS                = myStatus
       STANDARDCLASS         = mySTANDARDCLASS.
    *  TABLES
    *    ALLOCVALUESNUM        =
    *    ALLOCVALUESCHAR       =
    *    ALLOCVALUESCURR       =
    *    RETURN                =.
    ENDLOOP.
    But with the type from Shiva's code the debugger says that the given parameter has a wrong type.I just can't get this BAPI to work. I want to use it to get the classification information about a material.

  • Problem in truncate/drop partitions in a table having nested table columns.

    Hi,
    I have a table that has 2 columns of type nested table. Now in the purge process, when I try to truncate or drop a partition from this table, I get error that I can't do this (because table has nested tables). Can anybody help me telling how I will be able to truncate/drop partition from this table? IF I change column types from nested table to varray type, will it help?
    Also, is there any short method of moving existing data from a nested table column to a varray column (having same fields as nested table)?
    Thanks in advance.

    >
    I have a table that has 2 columns of type nested table. Now in the purge process, when I try to truncate or drop a partition from this table, I get error that I can't do this (because table has nested tables). Can anybody help me telling how I will be able to truncate/drop partition from this table?
    >
    Unfortunately you can't do those operations when a table has a nested table column. No truncate, no drop, no exchange partition at the partition level.
    A nested table column is stored as a separate table and acts like a 'child' table with foreign keys to the 'parent' table. It is these 'foreign keys' that prevent the truncation (just like normal foreign keys prevent truncating partions and must be disabled first) but there is no mechanism to 'disable' them.
    Just one excellent example (there are many others) of why you should NOT use object columns at all.
    >
    IF I change column types from nested table to varray type, will it help?
    >
    Yes but I STRONGLY suggest you take this opportunity to change your data model to a standard relational one and put the 'child' (nested table) data into its own table with a foreign key to the parent. You can create a view on the two tables that can make data appear as if you have a nested table type if you want.
    Assuming that you are going to ignore the above advice just create a new VARRAY type and a table with that type as a column. Remember VARRAYs are defined with a maximum size. So the number of nested table records needs to be within the capacity of the VARRAY type for the data to fit.
    >
    Also, is there any short method of moving existing data from a nested table column to a varray column (having same fields as nested table)?
    >
    Sure - just CAST the nested table to the VARRAY type. Here is code for a VARRAY type and a new table that shows how to do it.
    -- new array type
    CREATE OR REPLACE TYPE ARRAY_T AS VARRAY(10) OF VARCHAR2(64)
    -- new table using new array type - NOTE there is no nested table storage clause - arrays stored inline
    CREATE TABLE partitioned_table_array
         ( ID_ INT,
          arra_col  ARRAY_T )
         PARTITION BY RANGE (ID_)
         ( PARTITION p1 VALUES LESS THAN (40)
         , PARTITION p2 VALUES LESS THAN(80)
         , PARTITION p3 VALUES LESS THAN(100)
    -- insert the data from the original table converting the nested table data to the varray type
    INSERT INTO PARTITIONED_TABLE_ARRAY
    SELECT ID_, CAST(NESTED_COL AS ARRAY_T) FROM PARTITIONED_TABLENaturally since there is no more nested table storage you can truncate or drop partitions in the above table
    alter table partitioned_table_array truncate partition p1
    alter table partitioned_table_array drop partition p1

  • Cast and Order by

    One of the requirements we have in generating reports is to order the results by 'users choice'.
    Example:
    The user wants a report for the following customer's, (in the order the user enters the customers name). The report is generated through a procedure using Utl_File, the GUI passes the list of customers as: 'BILL;ADAM;ZACHARY;OSCAR'
    The procedure parses the parameter into two variables, one the IN_LIST and the ORDER_LIST:
    IN_LIST = 'BILL','ADAM','ZACHARY','OSCAR'
    ORDER_LIST = 'BILL',1, 'ADAM',2, 'ZACHARY',3, 'OSCAR',4
    The statement is then parsed and opened with a ref cursor. The completed statement look (something) like:
    v_sql := 'Select * from My_Table where cust_name in ('
              || IN_LIST ||' ORDER BY DECODE( custname, '|| ORDER_LIST ||' ) ' ;Works great.
    But, I was wondering, is there any way of using, CAST with an Object Type that is a nested table type and a simple parse routine that returns this nested table type given a string input, to accomplish the same thing, keeping in mind the requirement of the ORDER BY.
    Something like:
    create or replace type myTableType as table of varchar2 (255);
    Create or replace function In_list
          ( p_string in varchar2 ) return myTableType  as
    l_string        long default p_string || ',';
    l_data          myTableType := myTableType();
    n               number;
    begin
      loop
         exit when l_string is null;
            n := instr( l_string, ',' );
            l_data.extend;
            l_data(l_data.count) :=  ltrim( rtrim( substr( l_string, 1, n-1 ) ) );
            l_string := substr( l_string, n+1 );
      end loop;
      return l_data;
    end;
    select ID, Cust_Name from Cust_Table
    where cust_name in
         (select * from
            TABLE(select cast( in_list('BILL,ADAM,ZACHARY,OSCAR') as mytableType)
                            from dual) )
    -- HOW TO USE AN ORDER BY ???

    Hello V Garcia
    Yes you can use objects to do what you want. This example just assumes the name and order strings match by order rather than repeating the names in both paramters. You could extend it to do that if you need, but it could get tricky if they switch the order of the names between the name and order by strings. You'd have to check for an existing row by name and be moving forwards and back the whole time. This assumption makes things quite a bit simpler.
    SQL> create or replace type sort_obj as object
      2      (str varchar2(255), n number)
      3  /
    Type created.
    SQL> create or replace type sort_tab as table of sort_obj
      2  /
    Type created.
    SQL> create or replace function sorttab
      2      (p_str in varchar2, p_n in varchar2, p_sep in varchar2)
      3  return sort_tab
      4  is
      5      l_str long := p_str || p_sep;
      6      l_n long := p_n || p_sep;
      7      l_sort_tab sort_tab := sort_tab();
      8  begin
      9      while l_str is not null loop
    10          l_sort_tab.extend(1);
    11          l_sort_tab(l_sort_tab.count) := sort_obj (
    12              rtrim(substr(l_str,1,instr(l_str,p_sep)),p_sep),
    13              to_number(rtrim(substr(l_n,1,instr(l_n,p_sep)),p_sep))
    14              );
    15          l_str := substr(l_str,instr(l_str,p_sep)+1);
    16          l_n := substr(l_n,instr(l_n,p_sep)+1);
    17      end loop;
    18      return l_sort_tab;
    19  end;
    20  /
    Function created.In 9i (at least in R2) then you can just do this.
    SQL> select * from
      2      table(sorttab('BILL,ADAM,ZACHARY,OSCAR','1,2,3,4',','))
      3      order by n;
    STR                 N
    BILL                1
    ADAM                2
    ZACHARY             3
    OSCAR               4
    SQL> select * from
      2      table(sorttab('BILL,ADAM,ZACHARY,OSCAR','3,2,4,1',','))
      3      order by n;
    STR                 N
    OSCAR               1
    ADAM                2
    BILL                3
    ZACHARY             4I only just found this because before that in 8i and up you need to cast to the table type
    SQL> select * from
      2      table(cast(sorttab('BILL,ADAM,ZACHARY,OSCAR','3,2,4,1',',') as sort_tab))
      3      order by n;
    STR                 N
    OSCAR               1
    ADAM                2
    BILL                3
    ZACHARY             4pre 8.1.x the full select from dual cast construct is needed.
    Its nice to see that life is getting easier.
    Hth
    Martin

  • Tables in memory (Nested tables ?)

    For performance reasons, I would like to insert, update, etc...
    a table in memory. Can I use a nested table as if it was a
    normal table ? Can I do updates on nested tables with values
    from normal database tables ??
    Statement like : Update <nested-table> set <nested-
    table>.x=<value> where <nested-table>.y = <normal-table>.y
    Thanks for a quick response.

    The answer is yes and no.
    A nested table is a "collection" and can be referenced in a SQL
    statement using the pseudo-functions THE, CAST, MULTISET and
    TABLE. The nested table and varray collections can be a column
    in a database table (Oracle8) and are persistent. SQL
    statements cannot act on memory held nested tables, varray and
    index-by collections, which are transient. Index-by collections
    are same as the older PL/SQL tables.
    SQL statements cannot operate directly on transient collections.
    For speed you can define an index-by collection as a table of
    rowtype, and move data back and forth from database tables and
    memory held tables using SQL. Records and index-by tables are
    more efficient in Oracle 8 than in Oracle 7
    In PL/SQL you can use replacement (:=) on the record or
    record.column of the rowtype index-by collection. The downside
    is you have to keep track of your own indexing which is only
    BINARY_INTEGER, no SELECT, UPDATE, INSERT using FROM and WHERE
    on transient collections. This works in Oracle 7 also.
    Good Luck.

  • Cast to DATETIME Function?

    Please someone correct me if I'm wrong, but it seems you can use the cast function to convert correctly formatted data to date, timestamp, etc, but it is not possible to cast to datetime?
    OBIEE 11.1.1.6.2
    Thanks,
    Geo

    My date is like '30/04/1990 15:30:00' I want to keep the time after the date... which is why I want to convert to datetime. If I convert to date then I lose the time - i.e. the output becomes 30/04/1990 00:00:00. So I thought the solution was to cast to datetime instead in OBIEE.
    However, CAST("subjectarea"."table"."columnname" AS DATETIME) throws an error. Hence, I'm wondering if it is not possible to cast to datetime......
    Can anyone advise?
    Thanks,
    George

  • Instead of trigger is NOT firing for merge statements in Oracle 10gR2

    The trigger fires fine for a update statement, but not when I use a merge statement
    with an update clause. Instead I get the normal error for the view ( which is a union all view, and therefore not updatable.)
    The error is :-
    ORA-01733: virtual column not allowed here
    oracle release is 10.2.0.2 for AIX 64L
    Is this a known bug ?
    I've used a multi-table insert statement to work around the problem for inserts, but
    for updates, I'd really like to be able to use a merge statement instead of an update.
    Mark.

    This is my cut-down version :-
    In this case case I'm getting an :-
    ORA-01446: cannot select ROWID from, or sample, a view with DISTINCT, GROUP BY, etc.
    rather then the ora-01733 error I get in the real code ( which is an update from an involved
    XML expression - cast to a table form)
    create table a ( a int primary key , b char(30) ) ;
    create table b ( a int primary key , b char(30) ) ;
    create view vw_a as
    select *
    from a
    union all
    select *
    from b ;
    ALTER VIEW vw_a ADD (
    PRIMARY KEY
    (a) DISABLE);
    DROP TRIGGER TRG_IO_U_ALL_AB;
    CREATE OR REPLACE trigger TRG_IO_U_ALL_AB
    instead of update ON vw_a
    for each row
    begin
    update a targ
    set b = :new.b
    where targ.a = :new.a
    if SQL%ROWCOUNT = 0
    then
         update b targ
         set b      = :new.b
         where targ.a = :new.a
    end if ;
    end ;
    insert into a values (1,'one');
    insert into a values (2,'two');
    insert into a values (3,'three');
    insert into b values (4,'quatre');
    insert into b values (5,'cinq');
    insert into b values (6,'six');
    commit;
    create table c as select a + 3 as a, b from a ;
    commit;
    merge into vw_a targ
    using (select * from c ) src
    on ( targ.a = src.a )
    when matched
    then update
    set targ.b = src. b
    select * from vw_a ;
    rollback ;
    update vw_a b
    set b = ( select c.b from c where b.a = c.a )
    where exists ( select c.b from c where b.a = c.a ) ;
    select * from vw_a ;
    rollback ;

  • Using collection as a stored proc. parameter

    I have a requirement of a using a stored proc ('in') parameter as a collection and using it futher in the where clause of a sql query. What are my options here ? I am currently trying with a nested table, getting errors in using with sql query.
    What are my options here ?

    sql>create or replace type NumberTable as table of number;
      2  /
    Type created.
    sql>create or replace procedure p_test
      2    (p_list in NumberTable)
      3  is
      4    v_count pls_integer;
      5  begin
      6    select count(*)
      7      into v_count
      8      from table(p_list);
      9    dbms_output.put_line( 'Count: ' || v_count );
    10  end;
    11  /
    Procedure created.
    sql>declare
      2    v_list NumberTable := NumberTable(1, 2, 3, 4, 5);
      3  begin
      4    p_test(v_list);
      5  end;
      6  /
    Count: 5
    PL/SQL procedure successfully completed.There are some cases where you need to use CAST with the TABLE function:
    table(cast(p_list as NumberTable))

  • Migrating 7.3.4 to 8.1.7 - whitespace? issue

    We are migrating 7.3.4 to 8.1.7. We are aware of the need to ltrim/rtrim varchars, etc. I am looking for the Oracle documentation of the change that requires these changes. Can anyone point me to the text of this change? Is the migration guide on-line?
    thanks.

    found the original document on this bug fix -
    WebIV:View NOTE:130132.1     
    Article-ID: <Note:130132.1>
    Circulation: REVIEW_CHANGES (EXTERNAL)
    Folder: PLSQL
    Topic: Problem and Solution Articles
    Title: ORA-06502 Encountered When Converting Character to Number
    Open-Remarks: See <RemarksOn:NOTE:130132.1>
    Document-Type: PROBLEM
    Impact: MEDIUM
    Skill-Level: ACCOMPLISHED
    Updated-Date: 04-APR-2001 15:08:15
    References: <<BUG:571545>>
    Shared-Refs:
    Authors: MMCLAUGH.US
    Attachments: NONE
    Content-Type: TEXT/PLAIN
    Products: 11/PLSQL;
    Platforms: GENERIC;
    This article is being delivered in Draft form and may contain
    errors. Please use the MetaLink "Feedback" button to advise
    Oracle of any issues related to this article.
    Problem Description
    You have just upgraded from Oracle7 or Oracle8 to Oracle8i (8.1.6 or higher)
    and your PL/SQL code is failing with the following error:
    Error Messages:
    Potential Error #1:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    ORA-06512: at line 46
    Potential Error #2:
    ORA-01722: invalid number
    Sample Code to Generate the Error
    -- Enable serverout to display DBMS_OUTPUT package calls.
    SET SERVEROUTPUT ON SIZE 1000000
    -- Drop test table.
    DROP TABLE caste;
    -- Create test table to support example program cursor.
    CREATE TABLE caste (variable_number NUMBER);
    -- Insert one row into the test table.
    INSERT INTO caste VALUES (1);
    -- An anonymous block PL/SQL program to test problem.
    -- The program works in releases prior to Oracle8i (8.1.6).
    DECLARE
    || Declare a VARCHAR2 datatype and initialize it with a whitespace
    || and a NUMBER datatype to store output of a NUMBER datatype
    || stored in the database.
    var_in VARCHAR2(30) := ' ';
    var_out NUMBER;
    || Declare a cursor that accepts a NUMBER datatype as a parameter.
    CURSOR testing (var_in NUMBER) IS
    SELECT NVL(variable_number,8) value_in
    FROM caste
    WHERE variable_number = var_in;
    BEGIN
    || Display counts of the var_in variable as a whitespace.
    DBMS_OUTPUT.PUT_LINE('var_char <'||var_in||'>');
    || Declare a FOR-LOOP and pass the VARCHAR2 datatype with a whitespace
    || into the CURSOR testing that is defined as accepting a NUMBER
    || datatype.
    FOR i IN testing (var_in) LOOP
    var_out := i.value_in;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('var_out is <'||var_out||'>');
    END;
    Sample code output in Oracle7 and Oracle8:
    var_char < >
    var_out is <>
    Sample code output in Oracle8i (8.1.6 or newer):
    DECLARE
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    ORA-06512: at line 35
    Solution Description
    1. Rewrite all code to pass a null, or '' value into a VARCHAR2 datatype
    that will pass a value to a NUMBER datatype.
    2. Redesign your PL/SQL programs so that strong datatyping principles
    are used and do not pass VARCHAR2 datatype by design into NUMBER
    type by implicit casting, use explicit casting with the TO_NUMBER()
    and TO_CHAR() functions, as described in Chapter 2 of the PL/SQL
    User's Guide for versions newer than PL/SQL 2.0.
    3. If your intent is to caste a VARCHAR2 null to a zero, then you can
    use the following assignment to a NUMBER datatype variable named
    "p_converted" from a VARCHAR2 datatype name "p_unconverted":
    p_converted := TO_NUMBER(NVL(p_unconverted,0));
    Explanation
    Prior to Oracle8i (8.1.6), you could assign a whitespace in a VARCHAR2 datatype
    to a NUMBER datatype without encountering an error because the whitespace would
    be implicitly caste to a null. Unfortunately, the behavior that allowed this
    implicit caste caused a TO_NUMBER() function call to return a zero instead of
    raise an "ORA-01722: invalid number" error, as described in <BUG:571545>.
    Therefore, customers upgrading from Oracle7 or Oracle8 to Oracle8i will find
    that code that previously did not raise an exception will now raise and
    exception becasue passing a VARCHAR2 datatype with a whitespace value into a
    NUMBER datatype is in appropriate and calling the TO_NUMBER() function to
    return a zero from a whitespace is incorrect.
    References
    <Bug:571545

  • Performance of Collection Types

    Hiya,
    We are having severe performance problems using collections in one part of our system. I was hoping that someone may have some suggestions re init.ora parameters, memory allocation etc etc.
    The situation is - we have a form which is based on a view. This view in turn is based on a collection within a package specification on the database. This collection is populated before the user enters the form by a call to code on the database, let us call this create_collection. The create_collection code runs a SQL statement which does a CAST( MULTISET and SELECTs from 3 inline views, each of which itself joins to another collection via TABLE(CAST. It should be noted that one of the inline views is joining to a table of size 9 and a half million rows, which is large for our application. Having said that, I have explain planned the code and the execution plan is correctly using the appropriate indexes when you remove the TABLE( CASTS from the from clause of the SQL.
    As a temporary solution we could change the view to be based on a series of temporary tables ( which is populated for each user on a session by session basis ). Having benchmarked this we found that performance changed from 90 seconds to query the view using collections, to 0.4 second to query the view when all collections are removed and temporary tables subsituted instead.
    Obviously this is a good solution, however the changes required across our system would be numerous to say the least. We use collections extensively elsewhere within the system and have not encountered this performance issue before, having said that nowhere else do we use CAST( MULTISET and TABLE(CAST within the same SQL statement.
    So, my question is - does anyone have any tips for increasing the performance of collections when the underlying SQL is processing large volumes of data.
    Cheers
    Chris

    No. Java handles memory alignment internally, you should not be worrying about that yourself. Whatever you think you can do, Java does it better. A lot better. Write dumb code in stead to help the JVM optimize.
    http://java.sun.com/developer/technicalArticles/Interviews/devinsight_1/

  • Display Null when the column has a particular date value

    Experts,
    I have write the below query in Date column,
    CASE WHEN Table.Column='Bad A'
    THEN CAST(Null as "Table"."Date")
    WHEN Table.Column='Bad b'
    THEN CAST(Null as "Table"."Date")
    ELSE "Table"."Date"END
    but I am getting *" Invalid Alias Format : Table_name.Column_name required"*
    Please let me know where I did mistake.
    Thanks in Advance.
    Thanks,
    Balaa...

    Is that Table withe data column that you are using to replace the values in the main column using the case statement is an alias table or physical table? If it is alias table, you might want to try to use physical table instead.
    Thanks,
    -Amith

  • How to hide a VIEW script

    TRUE or FALSE?
    We do not have any utility (10g) to hide (CREATE VEW ....) script
    like Wrapping PL/SQL Code with wrap Utility.
    Thanks.

    I see nothing in the documentation to indicate that you can, so I'll say... TRUE
    however, if it's really important, you could create wrapped code which
    returns a refcursor
    returns an array which is cast with a TABLE() call (this can be pipelined or not).
    then the nosy user would only see something like this in USER_VIEWS
    select * from table( wrapped_package.haha )
    of course, passing parameters becomes an issue since a where clause against the view won't automatically be used when building the plan.
    you can use context variables to pass arguments to the view, but it might not be worth the hassle
    create view X as
    select * from table( wrapped_package.haha( pkg_context.get_context('MY_VAR') );
    select * from X where pkg_context.set_context('MY_VAR') = 'ABC'
    (search the forum for "pkg_context" to find the source)

  • How to join two arrays together?

    I have the following type
        type TVarcharArr is table of varchar(4000) index by binary_integer;I have a procedure that passes in two separate arrays as:
        p_account_number                 in TVarcharArr,
        p_product_system_code          in TVarcharArrThese arrays are related (they will have the same number of elements), the contents would be as follows:
        Account Number    Product System Code
        123                      ABC
        456                      DEF
        789                      GHII can use TABLE(CAST to turn each of these arrays into a table, but how do I join these two arrays together so that they become a single table with two columns? Or if I CAST them as TABLEs, how can I join these two tables together - is there some way of using the index to facilitate the join?
    Cheers
    Richard

    You are right, I do need to convert the arrays first to use TABLE(CAST, and I do have my concerns about the use of rownum.
    Here's the test case I built to test what I'm doing, incorporating the rownum solution:
    declare
        type TVarcharArr is table of varchar(4000) index by binary_integer;
        v_arr   TVarcharArr;
        v_tab  tchartab := tchartab();
        v_arr2   TVarcharArr;
        v_tab2  tchartab := tchartab();   
    begin
        v_arr(1) := 'ABC';
        v_arr(2) := 'DEF';
        v_arr(3) := 'GHI';
        v_arr2(1) := '123';
        v_arr2(2) := '456';
        v_arr2(3) := '789';   
        v_tab.extend(v_arr.Count);   
        for i in v_arr.first .. v_arr.last
        loop
            v_tab(i) := v_arr(i);
        end loop;   
        v_tab2.extend(v_arr2.Count);   
        for i in v_arr2.first .. v_arr2.last
        loop
            v_tab2(i) := v_arr2(i);
        end loop;   
        for rec in (with w_acct as
                    (select rownum rn, a.column_value acol
                    from table(cast(v_tab as tchartab)) a
                         w_prod as
                    (select rownum rn, b.column_value bcol
                    from table(cast(v_tab2 as tchartab)) b
                    select acol,bcol
                    from w_acct a,
                         w_prod b
                    where a.rn = b.rn) loop
            DBMS_OUTPUT.PUT_LINE ( 'rec = ' || rec.acol || '|'|| rec.bcol );
            null;
        end loop;
    end;It does return the correct result - but can it be trusted to be consistent - does the rownum in an array suffer the same problems as the rownum from a regular select? I'm guessing it's too risky to find out.
    In essence, I'm getting two arrays and I'm trying to join them together so that I can CAST them as a table. (And I know the real question is why isn't it just one array of records with two elements - but sometimes you have to work with what you're given)

Maybe you are looking for