Dynamic DB table name in insert statement

In the following command i was able to build <dyn_table> dynamically but how do we do that for <dyn_wa>. table name should be populated dynamically here.
for ex: pa0001, pa0002, .... and I have these names in an IT table
INSERT  <dyn_wa> FROM TABLE <dyn_table>
                          ACCEPTING DUPLICATE KEYS.
Pls help...Thanks

Take it as charater type.
This code works for me.
TABLES : ztest123.
DATA : tab_name(10) TYPE c.
tab_name = 'ZTEST123'.
DATA : wa LIKE ztest123.
wa-name = 'Mahesh'.
INSERT (tab_name) FROM wa.
Thanks
Mahesh

Similar Messages

  • Dynamically assigning table name in select statement

    how can i assign the table name dynamically in Select statement?
    i tried following code
    create or replace procedure proc1
    as
    x varchar2(100);
    y varchar2(10);
    begin
    x='UNIT_MASTER';
    execute immediate 'select unit_code into y from x where
    rownum=1';
    dbms_output.put_line(y);
    end;
    the procedure is created but when i execute the procedure the
    error is shown in the execute immediate statement

    Do the following :
    Create or replace procedure pro1 as
    x varchar2(100);
    y varchar2(10);
    begin
    x := 'UNIT_MASTER';
    EXECUTE IMMEDIATE 'select unit_code from '||x||' where rownum
    = 1' INTO y;
    dbms_output.put_line(y);

  • Concatenate of table name in insert Query

    Greetings,
    Oracle Version -  Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
    I want to write a procedure in which we can give table name in insert statement at run time through Cursor
    But problem is
    insert into  tra_temp
    select  * tra_smi23 from
    in above statement 23 must be dynamic like tra_smi||23
    below is my code but something is wrong
    Kindly Help
    create or replace procedure test as
    cursor c1 is
    select op_ID,OP_NAME from operators where OP_NAME like '%TRA'
    and OP_ID<>9;
    begin
    execute immediate 'truncate table tra_temp ';
    for rec in c1
    loop
    insert into tra_temp
    select * from tra_SMI||'rec.OP_ID';
    commit;
    exit when c1%notfound;
    end;

    Or can we take table name into variable like
    select 'tra_SMI' || rec.OP_ID into abc from dual;
    and can we use this variable as
    insert into  tra_temp 
    select * from &abc;

  • How to use bind variable value for table name in select statement.

    Hi everyone,
    I am having tough time to use value of bind variable for table name in select statement. I tried &p37_table_name. ,
    :p37_table_name or v('p37_table_name) but none worked.
    Following is the sql for interactive report:
    select * from v('p37_table_name') where key_loc = :P37_KEY_LOC and
    to_char(inspection_dte,'mm/dd/yyyy') = :P37_INSP_DT AND :p37_column_name is not null ;
    I am setting value of p37_table_name in previous page which is atm_state_day_insp.
    Following is error msg:
    "Query cannot be parsed, please check the syntax of your query. (ORA-00933: SQL command not properly ended) "
    Any help would be higly appreciated.
    Raj

    Interestingly enough I always had the same impression that you had to use a function to do this but found out from someone else that all you need to do is change the radio button from Use Query-Specific Column Names and Validate Query to Use Generic Column Names (parse query at runtime only). Apex will substitute your bind variable for you at run-time (something you can't normally do in pl/sql without using dynamic sql)

  • Using Table name in Read statement dynamically

    Hi Experts,
    I have the following requirement.
    Based on a country code say "A" , "B", "C" and based on this i have to read different internal tables lt_tabA, lt_tabB and lt_tabC.
    The table key can be given dynamically, but how can i use the internal table name dynamically without using if statements.
    Please help.
    Thanks!
    Best Regards,
    Gayathri

    Hi Gayathri,
    something like
    DATA:
        lt_t100 TYPE TABLE OF t100,
        lt_t000 TYPE TABLE OF t000.
      FIELD-SYMBOLS:
        <table> TYPE table,
        <rec>   TYPE ANY,
        <field> TYPE ANY.
      SELECT:
        * INTO CORRESPONDING FIELDS OF TABLE lt_t100 FROM t100 UP TO 10 ROWS,
        * INTO CORRESPONDING FIELDS OF TABLE lt_t000 FROM t000 UP TO 10 ROWS.
      CASE abap_true.
        WHEN space.
          ASSIGN  lt_t100 TO <table>.
        WHEN OTHERS.
          ASSIGN  lt_t000 TO <table>.
      ENDCASE.
      READ TABLE <table> with key ('MANDT') = sy-mandt ASSIGNING <rec>.
    Regards,
    Clemens

  • How to insert variable for table name in Select statement ?

    I am creating a stored procedure which will take two table names as IN parameters. Within the procedures I would like to use the parameters in the following manner;
         SELECT count(*)
         INTO v_target_cnt
         FROM TargetTable;
    TargetTable is one of the parameters passed in. When I do this however it does not recognize the parameter. I have tried assigning the parameter to a local variable and using the variable, with not luck.
    Any help....thanks

    Null,
    What you are describing is called a LEXICAL parameter, which is allowed (preceded by an ampersand) in sql but not in pl/sql because it would not be possible to compile it. That is why you need to use Andrew's suggestion to make the sql dynamic. In older versions you would need to use DBMS_SQL which is horrible and now thankfully redundant.

  • Dynamic physical table name vs. Cache

    Hello, Experts!
    I'm facing quite an interesting problem. I have two physical tables with the same structure but with a different data. Requirement is to show same reports with one or another table. Idea is to have dynamically changed physical table name with session variable usage. Session variable can be change in UI so it was working until cache was turned on. When cache is turned on logical statements sent to OBI backend are the same even for different values of session variable that stores physical table name. Once cache is populated every users will get values from cache. This is possible source of discrepancy because some users might run reports with tableA values and some with tableB values.
    Are there any options to set OBI to use data related to proper physical table name (i.e. accordingly to session variable value)? Model clone is not an option because it will be way to hard and complex to maintain both, beside same reports need to work sometimes with one table name and sometimes with other...
    PS. Cache is set to be common for all users.
    Lucas

    thank you, I've found another way to make it running. In fact there are two ways of doing it: filter LTS and have all data filtered from single table with session variable or use fragmentation content also with session variable.
    Now tricky part is to set variable from UI, currently I'm using issue raw sql: call NQSSetSessionValue( 'String SV_SIGNOFF=aaa;' ) but I have to figure out how to change session non system variable value without need of administrator user rights.
    There is GoURL method, but it's not working...
    2. Add In ORACLE_HOME/bifoundation/web/display/authenticationschemas.xml
    <RequestVariable source="url" type="informational" nameInSource="lang"
    biVariableName="NQ_SESSION.LOCALE" />
    inside the top <AuthenticationSchemaGroup> </AuthenticationSchemaGroup> tag

  • How user variable table names in select statement

    Dear all,
    I have three table gp1,gp2,g3. i want user variable table in sql query
    for example at oracle forms have a list table showing table names gp1,gp2,gp3
    at form i want user this query
    select gpno from :table where gpno=120;
    how i can specify table name Dynamicly in select query
    Thanks

    Forms_DDL is a one-way street: You can only pass DDL commands TO the database; you cannot get data back using Forms_DDL.
    Exec_SQL is the Forms package that enables dynamic sql within a form. But to retrieve data, you have to make a Exec_SQL call for every column in every row. So it is not a good thing to use, either.
    The ref cursor method should work. You could also retrieve the data into a record group using populate_group_with_query -- it also enables dynamic data retrieval.
    But if you already know you have three distinct tables and you know their names, I would keep it simple and just write three sql select statements.

  • Use table name in UPDATE statement as variable

    Hi All,
    I am using ORACLE 9i AIX base. I want to write following procedure:
    PROCEDURE update_header (
    p_care_msg_nbr IN NUMBER,
    p_care_msg_id IN NUMBER,
    p_care_msg_gkey IN NUMBER,
    p_old_status IN VARCHAR2,
    p_new_status IN VARCHAR2
    IS
    l_table varchar2(50);
    BEGIN
    l_table := 'CARE_EDI_MESSAGES';
    UPDATE '&l_table'
    SET status = p_new_status,
    changed = sysdate,
    changer = user
    WHERE care_msg_no = p_care_msg_nbr
    AND care_msg_id = p_care_msg_id
    AND gkey = p_care_msg_gkey
    AND status = p_old_status;
    END;
    I want to give the table name by passing value in a variable or parameter. Is it the write way or can I do this function in any other way.
    Pleae tell me in urgency.
    Thanks & Regards
    Hassan Raza

    This implies that you have several tables with identical or near identical structures, otherwise you will get errors if any of the mentioned columns do not exist in the table passed but ...
    You cannot use a substitution variable that way. Oracle will ask for a value when you try to create the procedure, and compile what ever value you supply into the procedure viz.
    SQL> CREATE PROCEDURE p AS
      2  l_id NUMBER;
      3  BEGIN
      4     SELECT id INTO l_id FROM &t;
      5  END;
      6  /
    Enter value for t: T
    old   4:    SELECT id INTO l_id FROM &t;
    new   4:    SELECT id INTO l_id FROM T;
    Procedure created.
    SQL> SELECT text FROM user_source WHERE name = 'P'
      2  ORDER BY line;
    TEXT
    PROCEDURE p AS
    l_id NUMBER;
    BEGIN
       SELECT id INTO l_id FROM T;
    END;Even if that is the effect you want, note that there are no quotes around the substitution variable in the CREATE statement.
    If you want to be able to pass the name of the table to the procedure, then you need to make the table name a parameter, then build the sql statement and execute it using EXECUTE IMMEDIATE. Something more like:
    PROCEDURE update_header (p_care_msg_nbr  IN NUMBER,
                             p_care_msg_id   IN NUMBER,
                             p_care_msg_gkey IN NUMBER,
                             p_old_status    IN VARCHAR2,
                             p_new_status    IN VARCHAR2,
                             p_table         IN VARCHAR2) IS
    l_sqlstr VARCHAR2(4000);
    BEGIN
       l_sqlstr := 'UPDATE '||p_table||' SET status = :b1 '||
                   'changed = sysdate, changer = user '||
                   'WHERE care_msg_no = :b1 and care_msg_id = :b3 and '||
                   'gkey = :b4 and status = :b5';
       EXECUTE IMMEDIATE l_sqlstr
          USING p_new_status, p_care_msg_nbr, p_care_msg_id, p_care_msg_gkey, p_old_status;
    END;HTH
    John

  • Variable as table name in update statement

    Hi everyone,
    I am trying to update a table whose name is based on bind variables in the form and is unknown until runtime. However, I haven't been able to find a way to do this. I'm currently trying the FORMS_DDL built-in, but no success here either. Has anyone ever done this?
    DECLARE
    matrix_temp_table VARCHAR2(50);
    BEGIN
    matrix_temp_table := 'TEMP_'||:mgmt_matrix_master.div_idkey||'_'||TO_CHAR(:mgmt_matrix_master.dept_idkey);
    FORMS_DDL('UPDATE '||matrix_temp_table||' SET create_date = :mgmt_matrix_master.create_date');
    END;

    You're right, issuing the statement using the table name itself only works outside of FORMS_DDL. After trudging through the documentation it seems the best way to accomplish what I am trying to do is by using the EXEC_SQL package. But, once again, I cant get this to work either. It seems to me what I am trying to do is a fairly simple thing, but apparently not. I'm now trying to use this code, but the table still isn't being updated.
    PROCEDURE update_matrix_temp_table IS
    matrix_temp_table VARCHAR2(50);
    update_connid EXEC_SQL.ConnType;
    update_cursor EXEC_SQL.CursType;
    ignore PLS_INTEGER;
    BEGIN
    matrix_temp_table := 'TEMP_'||:mgmt_matrix_master.div_idkey;
    update_connid := EXEC_SQL.CURR_CONNECTION;
    update_cursor := EXEC_SQL.OPEN_CURSOR(update_connid);
    EXEC_SQL.PARSE(update_connid, update_cursor, 'UPDATE '||matrix_temp_table||' SET emp_no = '||:mgmt_matrix_master.emp_no);
    ignore := EXEC_SQL.EXECUTE(update_connid, update_cursor);
    EXEC_SQL.PARSE(update_connid, update_cursor, 'COMMIT');
    ignore := EXEC_SQL.EXECUTE(update_connid, update_cursor);
    EXEC_SQL.CLOSE_CURSOR(update_cursor);
    EXCEPTION
         WHEN EXEC_SQL.PACKAGE_ERROR THEN
         IF EXEC_SQL.LAST_ERROR_CODE(update_connid) != 0 THEN
              Message('ERROR (source: ' ||TO_CHAR(EXEC_SQL.LAST_ERROR_CODE(update_connid))|| '): ' ||EXEC_SQL.LAST_ERROR_MESG(update_connid));
         END IF;
    END;

  • Variable table name in insert

    In forms i want to give variable as table name.
    e.g When_button_press
    Insert into :txt1 values (select * from abc1)
    return error on :txt1.
    how can i do this.

    There are examples in the forum that show how. Here are some of them:
    CAN I PASS A TABLE NAME AS A VARIABLE IN THE FROM CLAUSE?
    DML issue in Oracle forms
    Re: How to include variable on block's query
    How to use table name as variable

  • How to dynamic set table names

    In our application, the table name can be set at runtime by the customer. So is there a way in Toplink JPA to set table name at runtime (thru annotation or orm.xml) or programatically? Thanks.

    Our application will host several domains at once. Each domain will get its own set of database tables for each module it uses. We keep them seperate by using a unique prefix. An example would be domainA.com's blog post table would be called domainA_blogPost, while domainB.com's will be domainB_blogPost. Both tables are the same, except for the name. The name needs to be specified at runtime since the central service controller tells the rest of the application which domain it is servicing and thus which set of tables to use. We will be adding domains dynamically all the time and we can't afford to create new entity sets and recompile the back end for every domain we add. I have been looking at the API and wonder if this is as simple as implementing a solution in our application, or am I going to have to tweek the implementation of toplink?

  • Dynamically pass Table name, Column Name and rownum to function

    Hi Guys
    I wanted to pass the table name, column name and rownum to function and get the relevant value for it. Please guide me to achieve this task
    Thanking You
    Regards
    Lakmal

    Thanks,
    Here is my test function
    CREATE or replace FUNCTION GET_COLUMN_VALUE (tab_name VARCHAR2,column_name VARCHAR2) RETURN varchar2 AS
    strsql varchar2 (500);
    ColVal varchar2;
    BEGIN
    strsql:='select '||column_name||' from '||tab_name|| ' Where rownum = 1' ;
    EXECUTE IMMEDIATE strsql into ColVal;
    RETURN ColVal ;
    END;
    Message was edited by:
    Lakmal Marasinghe

  • Dynamic SQL substituting dynamic table name with slct statement having date

    Hello,
    I just wanted some help with the following PL block. My problem is whenever I try to run this block it ask for invoking values for 2 substitute variables, though no substitute variables present in the code. Please find the code below:
    Declare
    cursor C_1 is
    select unique table_name from gsi_daily_count;
    table_names varchar2(240);
    Begin
    Open C_1;
    Loop
    Fetch C_1 into table_names;
    EXIT WHEN C_1%NOTFOUND;
    EXECUTE IMMEDIATE' select last_extract_date,
    to_char(min(greatest(nvl(last_update_date,'||01-Jan-10||'),nvl(program_update_date,'||01-Jan-10||'))),'||DD-MON-YY HH24:MI:SS||') mi,
    to_char(max(greatest(nvl(last_update_date,'||01-Jan-10||'),nvl(program_update_date,'||01-Jan-10||'))),'||DD-MON-YY HH24:MI:SS||') ma
    from' || table_names ||'
    group by last_extract_date
    order by last_extract_date desc';
    End Loop;
    Close C_1;
    COMMIT;
    End;
    Please help.
    Thanks in advance.

    You cannot specify your dates the way you have since they are being intepreted as bind variables:
    Try this:
    Declare
      cursor C_1 is
        select unique table_name
        from gsi_daily_count;
        table_names varchar2(240);
    Begin
      Open C_1;
      Loop
        Fetch C_1 into table_names;
        EXIT WHEN C_1%NOTFOUND;
        EXECUTE IMMEDIATE' select last_extract_date,
                                  to_char(
                                          min(
                                                greatest(
                                                          nvl(last_update_date,to_date('''|| '01-Jan-10' ||''',''dd-Mon-yy''))
                                                         ,nvl(program_update_date,to_date('''|| '01-Jan-10' ||''',''dd-Mon-yy''))
                                             ),''DD-MON-YY HH24:MI:SS''
                                         ) mi
                                  to_char(
                                          max(
                                                greatest(
                                                          nvl(last_update_date,to_date('''|| '01-Jan-10' ||''',''dd-Mon-yy''))
                                                         ,nvl(program_update_date,to_date('''|| '01-Jan-10' ||''',''dd-Mon-yy''))
                                             ),''DD-MON-YY HH24:MI:SS''
                                         ) ma
                          from ' || table_names ||'
                          group by last_extract_date
                          order by last_extract_date desc';
      End Loop;
      Close C_1;
      COMMIT;
    End;
    / There is not way for me to test this, so you may have to play around with all the quotes!

  • Internal table name which hide statement uses

    Hi,
    To hide several variables, use chain HIDE statement.
    As soon as the user selects a line for which you stored HIDE fields, the system fills the variables in the program with the values stored.  A line can be selected.
    ¨      By an interactive event.
    For each interactive event, the HIDE fields of the line on which the cursor is positioned during the event are filled with the stored values.
    The HIDE area is a table, in which the system stores the names and values of all HIDE fields for each list and line number.  As soon as they are needed, the system reads the values from the table. 
    I want to know how can we find the name of that internal table.
    Regards,
    maqsood

    Hi,
    i think it is system defined.
    The HIDE Technique
    You use the HIDE technique while creating a list level to store line-specific information for later use. To do so, use the HIDE statement as follows:
    HIDE <f>.
    This statement places the contents of the variable <f> for the current output line (system field SY-LINNO) into the HIDE area. The variable <f> must not necessarily appear on the current line.
    To make your program more readable, always place the HIDE statement directly after the output statement for the variable <f> or after the last output statement for the current line.
    As soon as the user selects a line for which you stored HIDE fields, the system fills the variables in the program with the values stored. A line can be selected
    by an interactive event.
    For each interactive event, the HIDE fields of the line on which the cursor is positioned during the event are filled with the stored values.
    by the READ LINE statement.
    <b>You can think of the HIDE area as a table, in which the system stores the names and values of all HIDE fields for each list and line number. As soon as they are needed, the system reads the values from the table.</b>
    Thanks&Regards,
    Ruthra.R

Maybe you are looking for