How to use Oracle Table Type values in Select Statement.

Hi,
I am fetching initial set of values into Oracle Table of Records Type and want to use list of values in the Select statement.
For example, try something like the following:
TYPE t_record IS RECORD (
ID TABLEA.ID%type,
NO TABLEA.NO%type,
v_record t_record;
TYPE t_table IS TABLE OF v_record%TYPE;
v_table t_table;
-- Code to populate the values in v_table here.
SELEC ID,NO, BULK COLLECT INTO <some other table variabes here> FROM TABLEA
WHERE ID IN v_table(i).ID;
I want to know how to use the values from Oracle Table Type in the Select Statement.

Something like this:
create or replace type t_record as  object (
id number,
no number
CREATE or replace type t_table AS TABLE OF t_record;
set serveroutput on
declare
  v_table t_table := t_table();
  v_t1 t_table := t_table();
begin
  v_table.extend(1);
  v_table(1).ID := 1;
  v_table(1).No := 10;
  v_table.extend(1);
  v_table(2).ID := 2;
  v_table(2).ID := 20;
  SELEC t_record (ID,NO) BULK COLLECT INTO v_t1
  from TableA
  FROM TABLEA
  WHERE ID IN (select t.ID from table(v_Table) t);
  for i in 1..v_t1.count loop
    dbms_output.put_line(v_t1(i).ID);
    dbms_output.put_line(v_t1(i).No);
  end loop;
end;
/Untested!
P;
Edited by: bluefrog on Mar 5, 2010 5:08 PM

Similar Messages

  • How to use a table name in the select statement using a variable?

    Hi Everybody,
                       I got a internal table which has a field or a variable that gets me some tables names. Now I need to retrieve the data from all these tables in that field dynamically at runtime. So could you suggest me a way out to use the select query which uses this variable as a table ?
    Regards,
    Mallik.

    Hi all,
    Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?
    for ex : select * from (tab_name) where....?
    Can we do inner join on such select statements? If so how?
    Thanks & Regards,
    Mallik.

  • How to use oracle collection type with JDBC?

    I try to use oracle collection type in java program. So I made some package and java program, however Java program was not found "package.collectiontype"(JDBC_ERP_IF_TEST.NUM_ARRAY) . please, show me how to use this.
    Java Version : Java 1.4
    JDBC Driver : Oracle Oci Driver
    DB: Oracle 9i
    No 1. Package
    ===========================================
    create or replace package JDBC_ERP_IF_TEST AS
    type NUM_ARRAY is table of number;
    procedure JDBC_ERP_IF_ARRAY_TEST(P_NUM_ARRAY IN NUM_ARRAY, ERR_NO OUT NUMBER, ERR_TEXT OUT VARCHAR2);
    procedure TEST(ABC IN NUMBER);
    END JDBC_ERP_IF_TEST;
    ==================================================
    No 2. Package Body
    ===============================================
    CREATE OR REPLACE package BODY JDBC_ERP_IF_TEST is
    procedure JDBC_ERP_IF_ARRAY_TEST(p_num_array IN NUM_ARRAY,
    ERR_NO OUT NUMBER,
    ERR_TEXT OUT VARCHAR2) is
    begin
    ERR_NO := 0;
    ERR_TEXT := '';
    dbms_output.enable;
    for i in 1 .. p_num_array.count() loop
    dbms_output.put_line(p_num_array(i));
    insert into emp (empno) values (p_num_array(i));
    commit;
    end loop;
    EXCEPTION
    WHEN OTHERS THEN
    ERR_NO := SQLCODE;
    ERR_TEXT := ERR_TEXT ||
    ' IN JDBC INTERFACE TEST FOR ORACLE ERP OPEN API..';
    ROLLBACK;
    RETURN;
    end JDBC_ERP_IF_ARRAY_TEST;
    procedure TEST(ABC IN NUMBER) IS
    begin
    insert into emp(empno) values (ABC);
    commit;
    end TEST;
    end JDBC_ERP_IF_TEST;
    ===============================================
    NO 3. Java Program
    ===============================================
    ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("JDBC_ERP_IF_TEST.NUM_ARRAY", getConnection());
    ARRAY array = new ARRAY(descriptor, getConnection(), arrs);
    cstmt = getConnection().prepareCall(LQueryFactory.getInstance().get("Meta/Basic/testJdbcErpArrayIf").getSql());
    cstmt.setArray(1, array);
    cstmt.registerOutParameter(2, Types.INTEGER);
    cstmt.registerOutParameter(3, Types.VARCHAR);
    ====================================================
    couldn't find this phase => JDBC_ERP_IF_TEST.NUM_ARRAY
    what can i do for this package and program? please help me..

    Something like this:
    create or replace type t_record as  object (
    id number,
    no number
    CREATE or replace type t_table AS TABLE OF t_record;
    set serveroutput on
    declare
      v_table t_table := t_table();
      v_t1 t_table := t_table();
    begin
      v_table.extend(1);
      v_table(1).ID := 1;
      v_table(1).No := 10;
      v_table.extend(1);
      v_table(2).ID := 2;
      v_table(2).ID := 20;
      SELEC t_record (ID,NO) BULK COLLECT INTO v_t1
      from TableA
      FROM TABLEA
      WHERE ID IN (select t.ID from table(v_Table) t);
      for i in 1..v_t1.count loop
        dbms_output.put_line(v_t1(i).ID);
        dbms_output.put_line(v_t1(i).No);
      end loop;
    end;
    /Untested!
    P;
    Edited by: bluefrog on Mar 5, 2010 5:08 PM

  • How to use nested table types with XDK

    Im using Oracles XDK (xml development kit) to create xml-documents from data in database.4
    Problem: I need to use nested tables but when trying to create nested table types I get error: A Table type may not contain a nested table type or VARRAY.
    Hope I make myself clear! Are there any solutions or workarounds to this problem?
    Help appreciated, thanks!

    Jesper,
    I asked similar question last year (search for Tapsell, you will see my posting). Under 8.1.7 the "nesting" seems restricted to one level down. Thus you cannot create a type using another object that itself includes a nested table. Under Oracle 9, against which most current examples seem based, this limitation is removed making things easier. Under 8.1.7 the workaround I have used is to use the CAST syntax. This is not as neat, but it works.

  • How to ask user to enter value in select statement

    Hi,
    Can anyone tell me syntax of select statement where i can ask user to enter value .
    for example i am trying to use belowthing but it displaying error
    select * from emp where empname=:empname
    SP2-0552: Bind variable "empname" not declared.
    2.Is there any data dictionary table to see all pl/sql procedures and corresponding code?
    Thanks,
    sri

    user632733 wrote:
    Can anyone tell me syntax of select statement where i can ask user to enter value .None. The SQL engine resides on the server. It is incapable of prompting for data entry on the client.
    The client interacts with the user. The client is suppose to:
    a) prompt for variable values
    b) send a SQL statement to Oracle
    c) bind values to bind variables in the SQL statement
    for example i am trying to use belowthing but it displaying error
    select * from emp where empname=:empnameIn SQL*Plus, you need to create a bind variable:
    SQL> var empname varchar2(200)
    And then assign a value to it:
    SQL> exec :empname := 'John Doe';
    Note that this is still not ideal - as the assignment is also done via the server and sends a PL block to the server. This block contains non-sharable code and this can lead to fragmentation of the server's Shared Pool.
    But it does illustrate the basic principle.

  • How to use column name as variable in select statement

    hi,
    i want to make a sql query where in select statement using variable as a column name. but its not working plz guide me how can i do this.
    select :m1 from table1;
    regards

    Hi,
    Is this what you want..
    SQL> select &m1 from dept;
    Enter value for m1: deptno
    old   1: select &m1 from dept
    new   1: select deptno from dept
        DEPTNO
            10
            20
            30
            40
    SQL> select &m1 from dept;
    Enter value for m1: dname
    old   1: select &m1 from dept
    new   1: select dname from dept
    DNAME
    ACCOUNTING
    RESEARCH
    SALES
    OPERATIONS
    SQL> select &&m1 from dept;
    Enter value for m1: loc
    old   1: select &&m1 from dept
    new   1: select loc from dept
    LOC
    NEW YORK
    DALLAS
    CHICAGO
    BOSTON
    SQL> select &&m1 from dept;
    old   1: select &&m1 from dept
    new   1: select loc from dept
    LOC
    NEW YORK
    DALLAS
    CHICAGO
    BOSTONIf you use single '&' then each time you fire the query, It will ask for the new value..
    But if you will use double '&&' the value of m1 will be persistent across the session..
    Twinkle

  • How to use Oracle Varray types in WLS 5.1

    The connection pool is created using the Oracle thin driver. The connection so obtained when passed to the ArrayDescriptor throws a
    ClassCastException at ArrayDescriptor.createDescriptor(connection con.
    While deployment,deployer throws an exception saying unresolved reference to oracle/sql/Datum, either include the class files for the same or remove the reference using the file.
    Would u kindly help me with this as urgently as possible.
    Thanking in anticipation.
    Kavita

    Thanks Sree.
    Is there something so called as the back-door approach to it.
    I read in the articles of Struct Objects and Connection that:
    If connection is obtained via:
    weblogic.jdbc.jts.connection jtsConn = getConnection();
    OracleConnection oracleConn = jtsConn.conn;
    And this should ideally work in WLS5.1,
    but still i wonder how did they obtain the connection.
    It would be obligatory if someone could help me with it.
    Thanks,
    Kavita
    "Sree Bodapati" <[email protected]> wrote:
    Hi Kavita,
    This is not possible to do this via a connection from the pool. Oracle
    implements non standard methods which require OracleConnection object
    instead of standard java.sql.Connection object which the pool returns.
    You
    have to use a direct connection using the thin driver.
    sree
    "Kavita Rajdeo" <[email protected]> wrote in message
    news:3c6fc1f5$[email protected]..
    The connection pool is created using the Oracle thin driver. The connection
    so obtained when passed to the ArrayDescriptor throws a
    ClassCastException at ArrayDescriptor.createDescriptor(connection con.
    While deployment,deployer throws an exception saying unresolved reference
    to
    oracle/sql/Datum, either include the class files for the same or remove
    the
    reference using the file.
    Would u kindly help me with this as urgently as possible.
    Thanking in anticipation.
    Kavita

  • How to use case to replace the & in select statement

    Oracle version : 11.1.0.6.0
    RHEL
    Hi,
    I want to get a list of all expired and locked users but want to replace the "&" with and here is my code but it isn't working.
    Please some guidance, thanks.
    SQL> select username,
    2 case (account_status like 'EXP%' then 'EXPIRED AND LOCKED'
    3 ELS 'no locked users'
    4 end) account_status
    5 from dba_users
    6 where account_status like 'EXPI%';
    case (account_status like 'EXP%' then 'EXPIRED AND LOCKED'
    ERROR at line 2:
    ORA-00907: missing right parenthesis

    798188 wrote:
    thanks for the comments I corrected the ELSE and 'EPX%' but still same error :
    EOH> select username,
    2 case (account_status like 'EXP%' then 'EXPIRED AND LOCKED'
    3 ELSE 'no locked users'
    4 end) account_status
    5 from dba_users
    6 where account_status like 'EXP%';
    case (account_status like 'EXP%' then 'EXPIRED AND LOCKED'
    ERROR at line 2:
    ORA-00907: missing right parenthesisFirst of all, you do not need a CASE statement.
    Did you see the where clause of your query??
    6 where account_status like 'EXP%';do you realise that your query will always return those records for which value of account_status column starts with 'EXP'?
    Why use CASE when it could be simply written like this :
    SELECT username,
           'EXPIRED AND LOCKED'
    FROM   dba_users
    WHERE  account_status LIKE 'EXP%'

  • How to use temporarly table wid record type

    Hi,
    how to use temporarly table wid the record type wid this example
    declare
    type empcurtyp is ref cursor;
    type rectype is record (veid t.emp_id%type, vename t.ename%type);
    TYPE tabtype IS TABLE OF rectype;
    empcv empcurtyp;
    vtab tabtype;
    begin
    open empcv for select emp_id,ename from t;
    loop
    fetch empcv into vtab;
    exit when empcv%notfound;
    dbms_output.put_line(vtab.vename||vtab.veid);
    end loop;
    close empcv;
    end;
    here we hav table t and i m taking only two fields of the table t which r emp_id and ename.

    Try this
    declare
    type rectype is record (veid t.emp_id%type, vename t.ename%type);
    type empcurtyp is ref cursor return rectype;
    TYPE tabtype IS TABLE OF rectype;
    empcv empcurtyp;
    vtab empcv%rowtype;
    begin
    open empcv for select emp_id,ename from t;
    loop
    fetch empcv into vtab;
    exit when empcv%notfound;
    dbms_output.put_line(vtab.vename||vtab.veid);
    end loop;
    close empcv;
    end;

  • How to Use a table UI for input ?

    Hi All ,
    I just want to ask how to use a Table UI in webdynpro ABAP to insert , change and delete rows ?? and can we give a drop down facility in table columns ? . This is really urgent .
    Thanks in advance.
    Regards,
    LAS

    Hi LAS,
    Everything is possible. I am providing the logic here which will help you a lot.
    For insert, Change, Delete: 
       Just get the all the elements into temp internal table and get the lead slected index. Now instrt one row in the lead selected index position. then again bind the temporary internal table to your table node. Thats all it works like inserting the row.
    In the same way you can do the change and delete rows also.
    For Dropdown:
      Here i am providing the code for Dropdown. It will help you out.
      Just create the Dropdown view for the columns for which you want dropdown. And do the coding for that.
      Here in my scenario IT is the Table node which holds the information. And i am providing the dorpdown key for the column "BSCHL".
      If you have any dobts just reply to me . i will respond it.
    Code:
      data : ls_outtab               type /kyk/s_fb01_line,
             lt_outtab               type table of /kyk/s_fb01_line,
             lv_node_sd              type ref to if_wd_context_node,
             lv_node_it              type ref to if_wd_context_node,
             lv_node_info            type ref to if_wd_context_node_info,
             lv_node_sapmf05a_0106   type ref to if_wd_context_node,
             lv_node_waers           type ref to if_wd_context_node,
             lv_node_layout          type ref to if_wd_context_node,
             lv_rowcount             type i,
             lv_buzei                type i,
             lv_waers        type waers,
             lt_bschl_set    type wdy_key_value_table,
             bschl_key_item  type wdy_key_value.
    bind to context
      lv_node_sd      = wd_context->get_child_node( name = 'SD' ).
      lv_node_it      = lv_node_sd->get_child_node( name = 'IT' ).
      call method lv_node_it->bind_table
        EXPORTING
          new_items = lt_outtab.
    fill Dropdown Help for posting Key
      bschl_key_item-key    = '40'.
      bschl_key_item-value  = cl_wd_utilities=>get_otr_text_by_alias( '/KYK/FIN_FI/DEBIT_GL_ACCOUNT' ).
      insert bschl_key_item into table lt_bschl_set.
      bschl_key_item-key    = '50'.
      bschl_key_item-value  = cl_wd_utilities=>get_otr_text_by_alias( '/KYK/FIN_FI/CREDIT_GL_ACCOUNT' ).
      insert bschl_key_item into table lt_bschl_set.
      bschl_key_item-key    = '21'.
      bschl_key_item-value  = cl_wd_utilities=>get_otr_text_by_alias( '/KYK/FIN_FI/DEBITVENDOR' ).
      insert bschl_key_item into table lt_bschl_set.
      bschl_key_item-key    = '31'.
      bschl_key_item-value  = cl_wd_utilities=>get_otr_text_by_alias( '/KYK/FIN_FI/CREDITVENDOR' ).
      insert bschl_key_item into table lt_bschl_set.
      lv_node_info = lv_node_it->get_node_info( ).
      lv_node_info->set_attribute_value_set( name = 'BSCHL' value_set = lt_bschl_set ).
    Warm Regards,
    Vijay

  • How to use Temporary Table in PL-SQL

    In MySQL there is no Temporary table concept.
    So for intermediate calculation I have created a table as below
    create table SequenceTempTable
    SessionId VARCHAR(50),
    Sequence VARCHAR(500),
    CreatedDate DATE
    ) ENGINE=MEMORY;
    Whenever I invoke a SP, I load the data into SequenceTempTable using Session Id as below
    CREATE PROCEDURE `GetSequence`(
    IN Start_Date VARCHAR(25),
    IN End_Date VARCHAR(25)
    BEGIN
    SELECT UUID() INTO v_SessionId;
    INSERT INTO SequenceTempTable values (v_SessionId,'1,2,5,3',now());
    required code
    DELETE FROM SequenceTempTable WHERE SessionId = v_SessionId;
    COMMIT;
    END;
    i.e. I have created a table as temporary table (created once),
    and load the data using Session Id and once session specific intermediate computation done,
    I deleted the session specific data.
    Could you give me examples of How to use Temporary table in PL-SQL code with respect to my above example.
    Because I have gone through creating Temporary table but I stuck with use in PL-SQL. I mean to say Is there any need of creating table in advance before invoking SP.
    And one more thing as in MySQL temp table I created which is using MEMORY engine i.e. this table will always be in MEMORY so there is no need of writing data on disk.
    Regards
    Sanjeev

    Hi Sanjeev
    Read about GTT here
    http://www.oracle-base.com/articles/8i/TemporaryTables.php
    GTT always contains just session specific data. \
    In case you want to use the GTT in the same session again you can use option
    ON COMMIT PRESERVE ROWS;
    Or if it is used just once in the session use can use
    ON COMMIT DELETE ROWS;
    Do remember that for GTT the data of one session can not be accessed in other session.
    Also you can go away with Delete from GTT if not used again in same session.
    Regards
    Arun

  • Managing statistics for object collections used as table types in SQL

    Hi All,
    Is there a way to manage statistics for collections used as table types in SQL.
    Below is my test case
    Oracle Version :
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    SQL> Original Query :
    SELECT
         9999,
         tbl_typ.FILE_ID,
         tf.FILE_NM ,
         tf.MIME_TYPE ,
         dbms_lob.getlength(tfd.FILE_DATA)
    FROM
         TG_FILE tf,
         TG_FILE_DATA tfd,
              SELECT
              FROM
                   TABLE
                        SELECT
                             CAST(TABLE_ESC_ATTACH(OBJ_ESC_ATTACH( 9999, 99991, 'file1.png', NULL, NULL, NULL),
                             OBJ_ESC_ATTACH( 9999, 99992, 'file2.png', NULL, NULL, NULL)) AS TABLE_ESC_ATTACH)
                        FROM
                             dual
         )     tbl_typ
    WHERE
         tf.FILE_ID     = tfd.FILE_ID
    AND tf.FILE_ID  = tbl_typ.FILE_ID
    AND tfd.FILE_ID = tbl_typ.FILE_ID;
    Elapsed: 00:00:02.90
    Execution Plan
    Plan hash value: 3970072279
    | Id  | Operation                                | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                         |              |     1 |   194 |  4567   (2)| 00:00:55 |
    |*  1 |  HASH JOIN                               |              |     1 |   194 |  4567   (2)| 00:00:55 |
    |*  2 |   HASH JOIN                              |              |  8168 |   287K|   695   (3)| 00:00:09 |
    |   3 |    VIEW                                  |              |  8168 |   103K|    29   (0)| 00:00:01 |
    |   4 |     COLLECTION ITERATOR CONSTRUCTOR FETCH|              |  8168 | 16336 |    29   (0)| 00:00:01 |
    |   5 |      FAST DUAL                           |              |     1 |       |     2   (0)| 00:00:01 |
    |   6 |    TABLE ACCESS FULL                     | TG_FILE      |   565K|    12M|   659   (2)| 00:00:08 |
    |   7 |   TABLE ACCESS FULL                      | TG_FILE_DATA |   852K|   128M|  3863   (1)| 00:00:47 |
    Predicate Information (identified by operation id):
       1 - access("TF"."FILE_ID"="TFD"."FILE_ID" AND "TFD"."FILE_ID"="TBL_TYP"."FILE_ID")
       2 - access("TF"."FILE_ID"="TBL_TYP"."FILE_ID")
    Statistics
              7  recursive calls
              0  db block gets
          16783  consistent gets
          16779  physical reads
              0  redo size
            916  bytes sent via SQL*Net to client
            524  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              2  rows processed Indexes are present in both the tables ( TG_FILE, TG_FILE_DATA ) on column FILE_ID.
    select
         index_name,blevel,leaf_blocks,DISTINCT_KEYS,clustering_factor,num_rows,sample_size
    from
         all_indexes
    where table_name in ('TG_FILE','TG_FILE_DATA');
    INDEX_NAME                     BLEVEL LEAF_BLOCKS DISTINCT_KEYS CLUSTERING_FACTOR     NUM_ROWS SAMPLE_SIZE
    TG_FILE_PK                          2        2160        552842             21401       552842      285428
    TG_FILE_DATA_PK                     2        3544        852297             61437       852297      852297 Ideally the view should have used NESTED LOOP, to use the indexes since the no. of rows coming from object collection is only 2.
    But it is taking default as 8168, leading to HASH join between the tables..leading to FULL TABLE access.
    So my question is, is there any way by which I can change the statistics while using collections in SQL ?
    I can use hints to use indexes but planning to avoid it as of now. Currently the time shown in explain plan is not accurate
    Modified query with hints :
    SELECT    
        /*+ index(tf TG_FILE_PK ) index(tfd TG_FILE_DATA_PK) */
        9999,
        tbl_typ.FILE_ID,
        tf.FILE_NM ,
        tf.MIME_TYPE ,
        dbms_lob.getlength(tfd.FILE_DATA)
    FROM
        TG_FILE tf,
        TG_FILE_DATA tfd,
            SELECT
            FROM
                TABLE
                        SELECT
                             CAST(TABLE_ESC_ATTACH(OBJ_ESC_ATTACH( 9999, 99991, 'file1.png', NULL, NULL, NULL),
                             OBJ_ESC_ATTACH( 9999, 99992, 'file2.png', NULL, NULL, NULL)) AS TABLE_ESC_ATTACH)
                        FROM
                             dual
        tbl_typ
    WHERE
        tf.FILE_ID     = tfd.FILE_ID
    AND tf.FILE_ID  = tbl_typ.FILE_ID
    AND tfd.FILE_ID = tbl_typ.FILE_ID;
    Elapsed: 00:00:00.01
    Execution Plan
    Plan hash value: 1670128954
    | Id  | Operation                                 | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                          |                 |     1 |   194 | 29978   (1)| 00:06:00 |
    |   1 |  NESTED LOOPS                             |                 |       |       |            |          |
    |   2 |   NESTED LOOPS                            |                 |     1 |   194 | 29978   (1)| 00:06:00 |
    |   3 |    NESTED LOOPS                           |                 |  8168 |  1363K| 16379   (1)| 00:03:17 |
    |   4 |     VIEW                                  |                 |  8168 |   103K|    29   (0)| 00:00:01 |
    |   5 |      COLLECTION ITERATOR CONSTRUCTOR FETCH|                 |  8168 | 16336 |    29   (0)| 00:00:01 |
    |   6 |       FAST DUAL                           |                 |     1 |       |     2   (0)| 00:00:01 |
    |   7 |     TABLE ACCESS BY INDEX ROWID           | TG_FILE_DATA    |     1 |   158 |     2   (0)| 00:00:01 |
    |*  8 |      INDEX UNIQUE SCAN                    | TG_FILE_DATA_PK |     1 |       |     1   (0)| 00:00:01 |
    |*  9 |    INDEX UNIQUE SCAN                      | TG_FILE_PK      |     1 |       |     1   (0)| 00:00:01 |
    |  10 |   TABLE ACCESS BY INDEX ROWID             | TG_FILE         |     1 |    23 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       8 - access("TFD"."FILE_ID"="TBL_TYP"."FILE_ID")
       9 - access("TF"."FILE_ID"="TBL_TYP"."FILE_ID")
           filter("TF"."FILE_ID"="TFD"."FILE_ID")
    Statistics
              0  recursive calls
              0  db block gets
             16  consistent gets
              8  physical reads
              0  redo size
            916  bytes sent via SQL*Net to client
            524  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              2  rows processed
    Thanks,
    B

    Thanks Tubby,
    While searching I had found out that we can use CARDINALITY hint to set statistics for TABLE funtion.
    But I preferred not to say, as it is currently undocumented hint. I now think I should have mentioned it while posting for the first time
    http://www.oracle-developer.net/display.php?id=427
    If we go across the document, it has mentioned in total 3 hints to set statistics :
    1) CARDINALITY (Undocumented)
    2) OPT_ESTIMATE ( Undocumented )
    3) DYNAMIC_SAMPLING ( Documented )
    4) Extensible Optimiser
    Tried it out with different hints and it is working as expected.
    i.e. cardinality and opt_estimate are taking the default set value
    But using dynamic_sampling hint provides the most correct estimate of the rows ( which is 2 in this particular case )
    With CARDINALITY hint
    SELECT
        /*+ cardinality( e, 5) */*
    FROM
         TABLE
              SELECT
                   CAST(TABLE_ESC_ATTACH(OBJ_ESC_ATTACH( 9999, 99991, 'file1.png', NULL, NULL, NULL),
                   OBJ_ESC_ATTACH( 9999, 99992, 'file2.png', NULL, NULL, NULL)) AS TABLE_ESC_ATTACH)
              FROM
                   dual
         ) e ;
    Elapsed: 00:00:00.00
    Execution Plan
    Plan hash value: 1467416936
    | Id  | Operation                             | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                      |      |     5 |    10 |    29   (0)| 00:00:01 |
    |   1 |  COLLECTION ITERATOR CONSTRUCTOR FETCH|      |     5 |    10 |    29   (0)| 00:00:01 |
    |   2 |   FAST DUAL                           |      |     1 |       |     2   (0)| 00:00:01 |
    With OPT_ESTIMATE hint
    SELECT
         /*+ opt_estimate(table, e, scale_rows=0.0006) */*
    FROM
         TABLE
              SELECT
                   CAST(TABLE_ESC_ATTACH(OBJ_ESC_ATTACH( 9999, 99991, 'file1.png', NULL, NULL, NULL),
                   OBJ_ESC_ATTACH( 9999, 99992, 'file2.png', NULL, NULL, NULL)) AS TABLE_ESC_ATTACH)
              FROM
                   dual
         ) e ;
    Execution Plan
    Plan hash value: 4043204977
    | Id  | Operation                              | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                       |      |     5 |   485 |    29   (0)| 00:00:01 |
    |   1 |  VIEW                                  |      |     5 |   485 |    29   (0)| 00:00:01 |
    |   2 |   COLLECTION ITERATOR CONSTRUCTOR FETCH|      |     5 |    10 |    29   (0)| 00:00:01 |
    |   3 |    FAST DUAL                           |      |     1 |       |     2   (0)| 00:00:01 |
    With DYNAMIC_SAMPLING hint
    SELECT
        /*+ dynamic_sampling( e, 5) */*
    FROM
         TABLE
              SELECT
                   CAST(TABLE_ESC_ATTACH(OBJ_ESC_ATTACH( 9999, 99991, 'file1.png', NULL, NULL, NULL),
                   OBJ_ESC_ATTACH( 9999, 99992, 'file2.png', NULL, NULL, NULL)) AS TABLE_ESC_ATTACH)
              FROM
                   dual
         ) e ;
    Elapsed: 00:00:00.00
    Execution Plan
    Plan hash value: 1467416936
    | Id  | Operation                             | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                      |      |     2 |     4 |    11   (0)| 00:00:01 |
    |   1 |  COLLECTION ITERATOR CONSTRUCTOR FETCH|      |     2 |     4 |    11   (0)| 00:00:01 |
    |   2 |   FAST DUAL                           |      |     1 |       |     2   (0)| 00:00:01 |
    Note
       - dynamic sampling used for this statement (level=2)I will be testing the last option "Extensible Optimizer" and put my findings here .
    I hope oracle in future releases, improve the statistics gathering for collections which can be used in DML and not just use the default block size.
    By the way, are you aware why it uses the default block size ? Is it because it is the smallest granular unit which oracle provides ?
    Regards,
    B

  • How to export oracle table?

    Does anybody knows how to export oracle table into sql format? I know by using PL/SQL Developer can do it,but I have a table,it contains a column,it's type is LONG,PL/SQL can't export it! How to export long type table into sql format?
    Any idea will be appreciated!

    My table structure is follows:
    create table MyDates
    COL1 LONG,
    COL2 VARCHAR2(20)
    In column col1,I store some date in it,then I want to export this table,but I don't want to export this table into dmp file,I only want to export this table' structure and export it into SQL File,such export filename is mydata.sql
    I don't know how to export this table's structure? Because it contains LONG type column.How to export it? By the way,would you tell me how to export other type table,such as it contains column type is blob?

  • How to create Text Tables and Value Tables ?

    Hi all,
    How we can create the Text Table ? Step by Step
    How we can create the Value Table ? Step by Step
    Note : I am not asking about the creation of simple transparant table ...
    Thanks In advance.
    How to use Text tables ?
    With Example Please..
    Thanks in advance.
    Regards.
    Raj

    Hi Raj,
    Table A is a text table of table B if the key of A comprises the key of B and an additional language key field (field of data type LANG). Table A may therefore contain explanatory text in several languages for each key entry of B.
    To link the key entries with the text, text table A must be linked with table B using a foreign key. Key fields of a text table must be selected here for the type of foreign key fields
    If table B is the check table of a field, the existing key entries of table B are displayed as possible input values when the input help (F4) is pressed. The explanatory text (contents of the first character-like non-key-field of text table A) is also displayed in the user's logon language for each key value in table B.
    Only one text table can be created for table B! The system checks this when you attempt to activate a table with text foreign keys for B.
    Regards
    Aneesh.

  • How to use the table maintenance events for validating the input entries..?

    Hi,
    I have created a Z table with 6 fields in which all are KEY fields. All are of CHAR type. I have created the Table Maintenance Generator for the same. While maintaining the entries in the table, even though I maintain a blank entry for a field it is saving the entry. But, I don't want that way. All the fields are mandatory in my table. One should enter all the fields. Otherwise it should not allow to save the entry. So, I think it can be done using the Table Maintenance Events. can someone tell me how to use the Table Maintenance Events. and which event to use for my reuqirement and what is the logic to be written.
    Or Is there any other way to solve my problem.
    Please share your inputs. Thanks in advance.
    Best regards,
    paddu.

    In the table maintenance generator, Environment --> Modifications --> Events then a screen will be appear here,we need to create the Events.In the EVENTS screen, press new Entries, there give 01(Before Saving the Data in the Database) and give a name(This will become a PERFORM), then click the Editor pushbutton, this will be there at the right side of the entry, then a popup will be appear, you can create an include program, there inside of the include program write ur code.
    Here is documentation for Event 01(Before Saving the Data in the Database )
    Event 01: Before Saving the Data in the Database
    Use
    This event occurs before new, changed or deleted entries are written to the database. Other activities can be performed, for example:
    hidden entry processing
    fill hidden fields
    flag data to be written to hidden tables after the database change.
    To have the changes saved by the central maintenance dialog routines, SY-SUBRC must be set to 0 at the end of the routine.
    Realization
    This event has no standard routine. The following global data is available for the realization of the user routine:
    internal table TOTAL
    field symbols
    field symbols <ACTION> and <ACTION_TEXT>
    <STATUS>-UPD_FLAG
    If internal table data are to be changed before saving, t he changes should be made in both the internal table TOTAL and in the internal table EXTRACT.
    FORM abc.
    DATA: F_INDEX LIKE SY-TABIX. "Index to note the lines found
    LOOP AT TOTAL.
    IF <ACTION> = desired constant.
    READ TABLE EXTRACT WITH KEY <vim_xtotal_key>.
    IF SY-SUBRC EQ 0.
    F_INDEX = SY-TABIX.
    ELSE.
    CLEAR F_INDX.
    ENDIF.
    (make desired changes to the line TOTAL)
    MODIFY TOTAL.
    CHECK F_INDX GT 0.
    EXTRACT = TOTAL.
    MODIFY EXTRACT INDEX F_INDX.
    ENDIF.
    ENDLOOP.
    SY-SUBRC = 0.
    ENDFORM.
    Regards,
    Joy.

Maybe you are looking for