Dynamic 'from' Clause in Native SQL

Hi All,
While running a select query in ORACLE, we can put the table name in '<i>from</i>' clause at the runtime-Seletion Screen Parameter .
But I am not able to do so in SAP using Native Sql. Does SAP has any  restrictions regarding this?
It might be possible that ,by using Embedded SQL (C/C++ precompiler ),we may be able to achive this.
Can any body please throw light on this.
Its Urgent.
Thanks in Advance.
Regards,
Gaurav

Hi
<u>Assuming you can also use Open SQL.</u>
Macroman's suggestion is OK.  in Open SQL (this is SQL of ABAP platform) but a query statement can be constituted using some dynamic clauses. Although macro coding has some restrictions it will be less time consuming using it than a dynamic query.
<u>An example SELECT statement with dynamic clauses:</u>
SELECT (fields) FROM (table_name_variable)
INTO <target_fields>
WHERE (conditions_tab) .
For more information:
<a href="http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3983358411d1829f0000e829fbfe/frameset.htm">Open SQL -Reading Data</a>
*--Serdar

Similar Messages

  • SQL Dev Child Reports - Dynamic From Clause Possible?

    Hi All,
    Trying to figure out this problem:
    Master Report SQL:
    select TABLE_NAME from USER_TAB_COLS where COLUMN_NAME = 'CREATION_DATE'
    Results with some table names. Now I want to use the table name to formulate my child query
    Child SQL:
    select * from :TABLE_NAME where CREATION_DATE >= SYSDATE-7
    or whatever.....but I want to somehow use the table_name dynamically.
    Thanks!
    -Brent

    I doubt that you can get dynamic from clause for Child Report if its style is table.
    But you can get dynamic one in child with style script:
    Say you have :
    Master report for list tables which select owner and table name by some condition (I omit this):
    SQL :     select owner, table_name from all_tables ..So Child Report
    SQL is follow:
        COLUMN TN NEW_VALUE TNAME ;
        select :OWNER||'.'||:TABLE_NAME as TN  from dual;
        select '&&TNAME' as tab_NAME, count(1) from &&TNAME;Hope it help.
    Edited by: K_Serge on Jan 5, 2013 5:10 AM
    Edited by: K_Serge on Jan 5, 2013 5:20 AM

  • Dynamic table name in native SQL

    Hi,
    How can i use dynamic table name in native SQL?
    My req is to select data from a external database table , but the table name will be only poulated during runtime.
    How can i acheive this?
    Regards,
    Arun.

    It should work OK - see demo below.
    Jonathan
    report zsdn_jc_adbc_test.
    start-of-selection.
      perform demo_lookup.
    form demo_lookup.
      data:
        l_error_msg          type string,
        ls_t001              type t001, "Company
        ls_t003              type t003. "Doc types
      perform dynamic_lookup
        using
          'T001'
        changing
          ls_t001
          l_error_msg.
      write: / l_error_msg.
      perform dynamic_lookup
        using
          'T003'
        changing
          ls_t003
          l_error_msg.
      write: / l_error_msg.
    endform.
    form dynamic_lookup
      using
        i_tabname            type tabname
      changing
        os_data              type any
        o_error_msg          type string.
    * Use ADBC to select data
      data:
        l_mandt_ref          type ref to data,
        l_result_ref         type ref to data,
        l_mandt              type symandt,
        l_tabname            type tabname,
        l_sql_statement      type string,
        lo_cx_root           type ref to cx_root,
        lo_cx_sql            type ref to cx_sql_exception,
        lo_connection        type ref to cl_sql_connection,
        lo_statement         type ref to cl_sql_statement,
        lo_result_set        type ref to cl_sql_result_set.
      clear: os_data, o_error_msg.
      get reference of l_mandt into l_mandt_ref.
      get reference of os_data into l_result_ref.
      l_mandt   = '222'.   "i.e. select from client 222
      l_tabname = i_tabname.
      try.
          lo_connection = cl_sql_connection=>get_connection( ).
          lo_statement  = lo_connection->create_statement( ).
    * Set criteria for select:
          lo_statement->set_param( l_mandt_ref ).
          concatenate
            'select * from' l_tabname
            'where mandt = ?'
            into l_sql_statement separated by space.
    * Execute
          call method lo_statement->execute_query
            exporting
              statement   = l_sql_statement
              hold_cursor = space
            receiving
              result_set  = lo_result_set.
    * Get the data from the resultset.
          lo_result_set->set_param_struct( l_result_ref ).
          while lo_result_set->next( ) > 0.
            write: / os_data.
          endwhile.
    * Tidy up:
          lo_result_set->close( ).
          lo_connection->close( ).
        catch cx_sql_exception into lo_cx_sql.
          o_error_msg = lo_cx_sql->get_text( ).
        catch cx_root into lo_cx_root.
          o_error_msg = lo_cx_root->get_text( ).
      endtry.
    endform.

  • How to add a dynamic where clause for a sql based VO with group by query?

    Hi,
    Here is my case, I have a sql query based VO with the query like "select status, count(*) StatusCount from my_table group by status". Now I used the following java code trying to dynamically add the where clause to my VO to filter the rows based the type attribute in my DB table.
    vo.setWhereClause("type='MyType1' ");
    vo.executeQuery();
    Then I got the sql syntax error. Looks like the ADF has added the where clause to the end of my sql so my sql becomes "select status, count(*) StatusCount from my_table group by status where type='MyType1' ". But what I expected was the correct syntax "select status, count(*) StatusCount from my_table where type='MyType1' group by status".
    Does anyone know if this is an ADF bug? Or is there any other way to achieve my goal?
    Thanks,
    Chunyang
    Edited by: Chunyang on Dec 13, 2012 9:09 PM

    Hi,
    When you use setWhereClause on the VO, it is applied on top of the VO query. I.e, assume your VO has the following query.
    select empno, ename from empNow, if you apply the where clause programatically, only the two attributes that you are using in the select statement could be used. I.e
    select * from (select empno, ename from emp) where ename='KING' - VALID
    select * from (select empno, ename from emp) where deptno=10  - INVALID (because the inner query - the one you've defined as query for your vo does not have deptno attribute selected)If you would need to set a dynamic where clause, you need to make them available in your select statement / use bind variables.
    -Arun

  • Need help with writing a query with dynamic FROM clause

    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'Simply sticking the later query in the first query does not work.
    Any pointers will be appreciated.
    Thanks
    rogers42

    Hi,
    rogers42 wrote:
    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'
    Remember that anything inside quotes is case-sensitive. Is the owner really "Schema_Name" with a capital S and a capital N, and 8 lower-case letters?
    Simply sticking the later query in the first query does not work.Right; the table name must be given when you compile the query. It's not an expression that you can generate in the query itself.
    Any pointers will be appreciated.In SQL*Plus, you can do something like the query bleow.
    Say you want to count the rows in scott.emp, but you're not certain that the name is emp; it could be emp_2011 or emp_august, or anything else that starts with e. (And the name could change every day, so you can't just look it up now and hard-code it in a query that you want to run in the future.)
    Typically, how dynamic SQL works is that some code (such as a preliminary query) gets some of the information you need to write the query first, and you use that information in a SQL statement that is compiled and run after that. For example:
    -- Preliminary Query:
    COLUMN     my_table_name_col     NEW_VALUE my_table_name
    SELECT     table_name     AS my_table_name_col
    FROM     all_tables
    WHERE     owner          = 'SCOTT'
    AND     table_name     LIKE 'E%';
    -- Main Query:
    SELECT     COUNT (*)     AS cnt
    FROM     scott.&my_table_name
    ;This assumes that the preliminary query will find exactly one row; that is, it assumes that SCOTT has exactly one table whose name starts with E. Could you have 0 tables in the schema, or more than 1? If so, what results would you want? Give a concrete example, preferably suing commonly available tables (like those in the SCOTT schema) so that the poepl who want to help you can re-create the problem and test their ideas.
    Edited by: Frank Kulash on Aug 11, 2011 2:30 PM

  • TIME_OUT when accessing Oracle table from SAP using native SQL

    Hi,
    I have a problem in one of my native SQL statement. It takes a long time accessing the table considering that the number of records to be retrieved is only small.
    Something happened on the Oracle system. But, stilll to be confirmed. Looking further at the issue, it seems that when the value in the where clause equated is a literal (meaning the value is not declared in DATA or CONSTANTS in the ABAP Program)
    Example
    1.
    EXEC.
    WHERE FIELD = '1'
    ENDEXEC.
    instead of
    2.
    CONSTANTS: c_1 value '1'.
    EXEC.
    WHERE FIELD = c_1
    ENDEXEC.
    i found that when the way of coding is same as Example 1, a time-out error occurs. But when in Example 2, no issue.
    Can someone explain this?
    Thanks!

    Repetitively asking the same question again and again is against the forum rules.
    Please post an explain of the SQL statement on the remote machine.
    Markus

  • Dynamic Update Statement in Native SQL

    Hi Experts,
    I want to dynamically pass the field in Update statement in Native SQL. For eg.
    data: str1 type string.
    str1 = 'MARKETS'.
    EXEC SQL.
          UPDATE PRDT.TBVEHDS4 SET (str1) = :'U'
          WHERE  VEH_NO       =  :'K1WK-54520'
          AND    SEGMENT_NO   =  :'01'
    ENDEXEC.
    But this is not taking (str1) as MARKETS field to update as U , its taking STR1 itself, Giving native SQL exception as Invalid Token as we are using DB2 as external DB system.
    I checked with field-symbols also, but nothing helped.
    Please help, thanks in Advance.
    Regards,
    Abhishek

    Hi,
    Check this demo program in SE38  ADBC_DEMO, take as example to construct your own dynamic native sql
    Regards,
    Felipe

  • "Select * into table internal_table from database_table" in native SQL

    Dear All,
    Is it possible to insert into internal table from database table in native sql instead of open sql? Regarding single values it's clear, just to use ":variable_name". But how to map internal table? RDBMS Oracle version > 9. If it's possible and you know how to do it, please, give some code example.
    Thank you,
    Pavel

    Hi ,
    Here is the code snippet for the native sql .
    select * from zwf_role into table i_wfroles." where role_id ='CAO'.
      loop at i_wfroles into wa_wfroles.
        EXEC sql.
          insert into   ROLES_MASTER_SAP
                 values (:wa_wfroles-ROLE_ID,:wa_wfroles-ROLE_NM,
                        :wa_wfroles-ROLE_DESC,:wa_wfroles-PAR_ROLE_ID,
                        :wa_wfroles-WF_ROLE_ORDER,:wa_wfroles-ROLE_TYPE )
        ENDEXEC.
        if sy-subrc = 0 .
          suc_rec_cnt = suc_rec_cnt + 1.
        else.
          fail_rec_cnt = fail_rec_cnt + 1.
        endif.
    *              ( ROLE_ID,ROLE_NAME, ROLE_DESC,PARENT_ROLE_ID,ROLE_ORDER,
    *                  ROLE_TYPE )
      endloop.
    zwf_role database table has the same files
    Regards
    Girish

  • How to programmatically count from a dynamic from clause ?

    Hi all,
    My report contains a user-parameter , say :from_clause, which will receive the from clause of a query from a forms application. We can have for example :from_clause = "from t_table where column_1 = value_1 order by column_2". The "from" keeword is included in the parameter value. In the before report trigger I want to make a count based on that from clause. How to achieve this goal ?
    Thank you very much indeed.

    Hi,
    It won't work. You need a control flow case, unless you want to use a hack (internal API) with OutcomeUtils.getActivityRequestOutcome(activityId).
    FacesContext context = FacesContext.getCurrentInstance();
    NavigationHandler handler = context.getApplication().getNavigationHandler();
    handler.handleNavigation(context, null, OutcomeUtils.getActivityRequestOutcome("YourViewId"));
    context.renderResponse();Regards,
    ~ Simon

  • Dynamic FROM clause

    Hi, I am needing to use a dynamic "<font color="blue">FROM (insert table name here)</font>" as well. From reading several posts, it seems like I need to do this using dynamic SQL. I can pass the name of the table into the stored procedure, but I am getting confused as to how to turn the SELECT statement part of this function into dynamic SQL since the SELECT statement is already inside a cursor itself. Thank you -
    <br><br><b>FUNCTION getDni4wImmStartInterface(p_board_group_id NUMBER)   RETURN interface_cnt_tbl PIPELINED
    IS
    --fill the cursor with available interfaces for the board_group_id passed in
    CURSOR gc_intf IS
       SELECT interface
       FROM TABLE(ipfinterfaces.getinterfaceslist(p_board_group_id))
       WHERE interface NOT IN (SELECT interface FROM physical_interface WHERE board_group_id = p_board_group_id);
    l_count NUMBER(10);
    l_max   NUMBER(10);
    BEGIN
    --fetch the max # of interfaces allowed for the board group type
    --passed in
    SELECT bgt.max_interfaces
    INTO l_max
    FROM board_group_type bgt, board_groups bg
    WHERE bg.board_group_id = p_board_group_id
    AND bg.board_group_type_id = bgt.board_group_type_id;
    --for interface in the cursor, check to see if there is an interface
    --with the same C-S-G in the database that is 1 greater than the one in the cursor
    FOR gc_rec IN gc_intf LOOP
    SELECT count(*)
    INTO l_count
    "<font color="blue">FROM INT_DNI_4W_IMM c</font>
      , VIRTUAL_INTERFACE vi
      , BOARD_GROUPS bg
      , PHYSICAL_INTERFACE  pi
      , BOARD b
      WHERE b.BOARD_ID = bg.BOARD_ID
      AND b.SYSTEM_ID = vi.SYSTEM_ID
      AND vi.PHYSICAL_INTERFACE_ID = pi.PHYSICAL_INTERFACE_ID
      AND pi.SYSTEM_ID =  vi. SYSTEM_ID
      AND pi.BOARD_GROUP_ID = bg.BOARD_GROUP_ID
      AND vi.SYSTEM_ID =  bg.SYSTEM_ID
      AND c.VIRTUAL_INTERFACE_ID = vi.VIRTUAL_INTERFACE_ID
      AND bg.BOARD_GROUP_ID = p_board_group_id
      AND pi.Interface = TO_NUMBER(gc_rec.Interface) + 1;
    --if there is not interface 1 greater than the one passed in, and if
    --the interface passed in is not the max interface, pipe the row back.
         IF l_count = 0 AND (TO_NUMBER(gc_rec.interface) != l_max)
           THEN PIPE ROW (interface_cnt_obj (TO_NUMBER(gc_rec.interface), TO_NUMBER(l_count)));
         END IF;
    END LOOP;
    RETURN;
    END getDni4wImmStartInterface;
    </b>

    Hi Vikas,
    Sorry, I didn't think I could assign p_table_name to l_table_name like that. When I try to implement your suggestion, I get these errors (Is my DECLARE out of place?):<br><br>
    Line # = 469 Column # = 1 Error Text = PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following: begin function package pragma procedure subtype type use <an identifier> <a double-quoted delimited-identifier> form current cursor The symbol "begin" was substituted for "DECLARE" to continue. <br><br>
    Line # = 474 Column # = 14 Error Text = PLS-00103: Encountered the symbol "=" when expecting one of the following: constant exception <an identifier> <a double-quoted delimited-identifier> table LONG_ double ref char time timestamp interval date binary national character nchar The symbol "<an identifier>" was substituted for "=" to continue.
    <br><br>
    Line # = 491 Column # = 51 Error Text = PLS-00103: Encountered the symbol "C" when expecting one of the following: * & = - + ; < / > at in is mod remainder not rem <an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_ between || multiset member SUBMULTISET_
    <br><br>
    Line # = 496 Column # = 3 Error Text = PLS-00103: Encountered the symbol "WHERE" when expecting one of the following: , from into bulk
    <br><br>
    Line # = 503 Column # = 27 Error Text = PLS-00049: bad bind variable 'B1'
    <br><br>
    Line # = 506 Column # = 3 Error Text = PLS-00103: Encountered the symbol "EXECUTE"
    <br><br>
    Here's my current code:<br><br><b>FUNCTION getDni4wImmStartInterface(p_board_group_id NUMBER, p_table_name VARCHAR2)   RETURN interface_cnt_tbl PIPELINED
    IS
    --fill the cursor with available interfaces for the board_group_id passed in
    CURSOR gc_intf IS
       SELECT interface
       FROM TABLE(ipfinterfaces.getinterfaceslist(p_board_group_id))
       WHERE interface NOT IN (SELECT interface FROM physical_interface WHERE board_group_id = p_board_group_id);
    DECLARE
    l_count NUMBER(10);
    l_max   NUMBER(10);
    l_sql   LONG;
    l_count NUMBER;
    l_table_name := p_table_name;
    BEGIN
    --fetch the max # of interfaces allowed for the board group type
    --passed in
    SELECT bgt.max_interfaces
    INTO l_max
    FROM board_group_type bgt, board_groups bg
    WHERE bg.board_group_id = p_board_group_id
    AND bg.board_group_type_id = bgt.board_group_type_id;
    --for interface in the cursor, check to see if there is an interface
    --with the same C-S-G in the database that is 1 greater than the one in the cursor
    FOR gc_rec IN gc_intf LOOP
    l_sql := 'SELECT count(*) FROM ||l_table_name||' c
      , VIRTUAL_INTERFACE vi
      , BOARD_GROUPS bg
      , PHYSICAL_INTERFACE  pi
      , BOARD b
      WHERE b.BOARD_ID = bg.BOARD_ID
      AND b.SYSTEM_ID = vi.SYSTEM_ID
      AND vi.PHYSICAL_INTERFACE_ID = pi.PHYSICAL_INTERFACE_ID
      AND pi.SYSTEM_ID =  vi. SYSTEM_ID
      AND pi.BOARD_GROUP_ID = bg.BOARD_GROUP_ID
      AND vi.SYSTEM_ID =  bg.SYSTEM_ID
      AND c.VIRTUAL_INTERFACE_ID = vi.VIRTUAL_INTERFACE_ID
      AND bg.BOARD_GROUP_ID = :b1
      AND pi.Interface = TO_NUMBER(gc_rec.Interface) + 1;
      EXECUTE IMMEDIATE l_sql INTO l_count USING p_board_group_id;
    <br><br></b>Message was edited by:
    The Fabulous LB

  • Dynamic table name in native sql query

    Can i pass a dynamic table name in this query ---
                EXEC SQL PERFORMING APPEND_MTO.
                  SELECT          
                               LTOG_QUANTITY_TYPE,
                               FCONO,
                              WBSELEMENT,
                             PROJECT
                  INTO   :IMTO
                  FROM  RWORKS.MTO_ISO_V2
                  WHERE LTOD_DATE > TO_DATE(:MAXD,'YYYYMMDDHH24MISS')
                ENDEXEC.
    How can i pass this table name RWORKS.MTO_ISO_V2  dynamically in the query
    Edited by: Madhukar Shetty on Nov 26, 2009 2:40 PM

    Can i pass a dynamic table name in this query ---
                EXEC SQL PERFORMING APPEND_MTO.
                  SELECT          
                               LTOG_QUANTITY_TYPE,
                               FCONO,
                              WBSELEMENT,
                             PROJECT
                  INTO   :IMTO
                  FROM  RWORKS.MTO_ISO_V2
                  WHERE LTOD_DATE > TO_DATE(:MAXD,'YYYYMMDDHH24MISS')
                ENDEXEC.
    How can i pass this table name RWORKS.MTO_ISO_V2  dynamically in the query
    Edited by: Madhukar Shetty on Nov 26, 2009 2:40 PM

  • Dynamic WHERE clause logic in SQL based on ITEM value

    Hi,
    I have a report based on following SQL query.
       select dept_no,
           dept_name,
           dept_loc
      from dept
    where dept_loc = :P1_DEPT_LOC
       // If P1_DEPT_LOC is not null, I want the WHERE clause and IF  P1_DEPT_LOC is null, then I don't need the WHERE clause.
       // how can I build this logic in same SQLThanks,
    Deepak
    Edited by: Deepak_J on Mar 11, 2010 4:37 PM

    Deepak,
    If p1_dept_loc were a LOV, this would work.
    SELECT deptno,
    dname,
    loc
    FROM dept
    WHERE ( :p1_dept_loc = '%null%' OR loc LIKE '%' || :p1_dept_loc || '%' )
    Jeff

  • How to get data from Oracle using Native SQL in SAP.. Problem with date

    Hi Masters.
    I'm trying to get data from an Oracle DB. I was able to connect to Oracle using tcode DBCO. The connetion works fine
    I wrote this code and it works fine without the statement of where date > '01-09-2010'
    But i need that statement on the select. I read a lot about this issue, but no answer.
    My code is (this code is in SAP ECC 6.0)
    DATA: BEGIN OF datos OCCURS 0,
          id_numeric(10),
          component_name(40),
          comuna(10),
          record_id(10),
          status,
          sampled_date(10),
          END OF datos.
    DATA: c TYPE cursor.
    EXEC SQL.
      connect to 'LIM' as 'MYDB'
    ENDEXEC.
    EXEC SQL.
      SET CONNECTION 'MYDB'
    ENDEXEC.
    EXEC SQL PERFORMING loop_output.
      SELECT ID_NUMERIC, COMPONENT_NAME, COMUNA, RECORD_ID, STATUS, SAMPLED_DATE
      into :datos from lims.SAMP_TEST_RESULT
      where     date > '01-09-2010'
    ENDEXEC.
    EXEC SQL.
      disconnect 'MYDB'
    ENDEXEC.
    How can i get the data from that date?? If i delete the where statemet, the program works well, it takes 30 mins and show all the data, I just need the data from that date.
    Any help
    Regards

    Please refer the example in this link which deals with Oracle date format.
    You can finnd a command DECODE which is used for date formats. If you have a look at whole theory then you will get an idea.
    Link:[Bulk insert SQL command to transfer data from SAP to Oracle|http://sap.ittoolbox.com/groups/technical-functional/sap-dev/bulk-insert-sql-command-to-transfer-data-from-sap-to-oracle-cl_sql_connection-3780804]

  • Create view with dynamic from-clause

    Dear all,
    you might have some ideas to help me out of my issue that i just "created myself" ;-)
    i have a unknown and non-constant amount of tables using the the same table-structure and i do have a master table
    that contains all names of these kind of tables. I now want to create a single view that contains all columns of each table
    and an additional column name containing the name of the corresponding table.
    I found a solution for this but only if I knew all table names while creating my view.
    Here's what I currently have:
    master_table:
    ID TABLENAME
    1 table_01
    2 table_02
    table_01:
    ID NAME
    1 eins
    2 zwei
    3 drei
    table_02:
    ID NAME
    1 one
    2 two
    3 three
    my view "tab1tab2" on these 2 table looks like this:
    ID NAME TABLENAME
    1 eins table_01
    2 zwei table_01
    3 drei table_01
    1 one table_02
    2 two table_02
    3 three table_02
    i achieved this view by using:
    CREATE OR REPLACE VIEW TAB1TAB2 ("ID", "NAME", "TABLENAME")
    AS
    SELECT id,name, 'table_01' AS tablename FROM table_01
    UNION
    SELECT id,name, 'table_02' AS tablename FROM table_02;
    Is there a way to create as many select and union statements as i do have entries (tablenames) in my master_table to achive the same results as my hardcoded view ?
    Many thanks in advance for your help
    Best regards
    majo

    Is there a way to create as many select and union statements as i do have entries (tablenames) in my master_table to achive the same results as my hardcoded view ?You can achieve this also with some xml facilities as e.g. in
    SQL> create table t1 as select empno, ename from emp where rownum <= 3
    Table created.
    SQL> create table t2 as select deptno empno, dname ename from dept
    Table created.
    SQL> create table master as (select 1 id, 't1' table_name from dual union all
                                       select 2 id, 't2' table_name from dual)
    Table created.
    SQL> create or replace view v_t
    as
    select table_name, x.*
      from (select table_name, 'ora:view("' || table_name || '")' tabs from master),
           xmltable (tabs columns id int path 'EMPNO', ename varchar2(20) path 'ENAME') x
    View created.
    SQL> select * from v_t
    TABLE_NAME              ID ENAME              
    t1                    7369 SMITH              
    t1                    7499 ALLEN              
    t1                    7521 WARD               
    t2                      10 ACCOUNTING         
    t2                      20 RESEARCH           
    t2                      30 SALES              
    t2                      40 OPERATIONS         
    t2                      50 SALES              
    8 rows selected.
    SQL> create table t3 as select object_id empno, object_name ename from user_objects where rownum <= 3
    Table created.
    SQL> insert into master values (3, 't3')
    1 row created.
    SQL> select * from v_t
    TABLE_NAME              ID ENAME              
    t1                    7369 SMITH              
    t1                    7499 ALLEN              
    t1                    7521 WARD               
    t2                      10 ACCOUNTING         
    t2                      20 RESEARCH           
    t2                      30 SALES              
    t2                      40 OPERATIONS         
    t2                      50 SALES              
    t3                  187449 ABC                
    t3                  187448 ADDRESSES_EXT_TAB  
    t3                  187446 ADDRESSES_EXT_TYP  
    11 rows selected.Note: above will work only in 11g.

  • Dynamic SQL Select String VS non-dynamic USING Clause

    This isn’t a question, I just wanted to share a solution to a problem I have encountered several times.
    e.g. You have ‘n’ number of variables, of which any combination could be used in a SQL string. But it’s difficult to execute the SQL string with USING without an unpleasant CASE statement.
    Solution: Reference all ‘n’ bind variables in the FROM clause of the SQL in an in-line-view. And specify all variables in the USING Clause.
    When building the SQL String, specify the view.variable rather than directly referencing bind variables
    This eliminates the requirement to check which variables have been populated.
    <h6>
    t_select := ‘SELECT tab.cola, tab.colb’;
    t_from := ‘FROM (SELECT :1 cola, :2 colb, :3 colc, :4 cold, :5 cole) parms, tablea tab’;
    t_where := ‘WHERE tab.cola = parms.cola’;
    OPEN c t_select||t_from||t_where USING v1, v2, v3, v4, v5;
    </h6>
    I hope this is useful to someone...
    PeteD

    Interesting approach.. but I would still prefer creating a DBMS_SQL cursor instead - as there the binding can be fully controlled at run-time.
    If this has to return a ref cursor (caller is an external process), then I would rather use conditional processing logic (as that is what PL is about) in PL/SQL and build a "+proper+" SQL statement (with only the required bind variables) at run-time. Features like polymorphism makes this easy - and the call interface that is provided to the client is a lot cleaner.

Maybe you are looking for

  • Importing xml file from FCP 7.0 to 6.0

    Hi all. I am sure many of you have figured this out, but after a few grey hairs today, I was finally able to open a clients project done in FCP 7.0 into my 6.0. In text editor you need to open the xml file and change: <xmel version= "5"> to "4". Then

  • Transcode produces black bars on side in Encore but not AME

    I am Transcoding 1920x1080 footage to NTSC widescreen DVD's. If I transcode the footage in Apple Compressor, or Adobe Media Encoder(with 12px top/bottom crop) it comes out correct. If I transcode in Encore, I cannot get rid of the thin black bars on

  • BPS_WB Chart Help

    Hi guys, i need help, for a Applications Web with BPS_WB(T Code). the problem is when i configured chart, generate and display i can't see the chart, (typical symbol error cross red, such as image no find in the page web) i have configurated the layo

  • Po not created on the basis of Req Number

    Hello guys, I need ur help, I want to find all those requisition numbers which are not used for creation of PO. plz guide me & give the script & link of tables. Thanks ab...

  • BPC for Excel Option Missing from Launch Page

    We have a user that does not have the BPC for Excel option on the Launch Page when logging in.  I've removed BPC and reinstalled several times sucessfully, but "BPC For Excel" doesn't show up.  The launch page doesn't recognize the software has alrea