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

Similar Messages

  • 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;

  • Creating a form with variable table name(s)

    Hi,
    I am building a form that will allow user(s) switch to other user
    (s) dynamically. I have been able able to do this by creating a
    non-database table and use record group to read from the base
    table of each user.(All the tables in question have the same
    structure).
    Record group is a read only, and I want to be able to do data
    maninpulation with this form.
    The questions are
    (1) It possible to do data manipulation with record group and if
    it is, how?
    (2) Is it possible to build a form with a variable table name?
    if possible, how?
    Somebody pls help.
    Thanks,
    Olutunde.
    null

    Olutunde Babarinsa (guest) wrote:
    : Hi,
    : I am building a form that will allow user(s) switch to other
    user
    : (s) dynamically. I have been able able to do this by creating a
    : non-database table and use record group to read from the base
    : table of each user.(All the tables in question have the same
    : structure).
    : Record group is a read only, and I want to be able to do data
    : maninpulation with this form.
    : The questions are
    : (1) It possible to do data manipulation with record group and
    if
    : it is, how?
    : (2) Is it possible to build a form with a variable table name?
    : if possible, how?
    : Somebody pls help.
    : Thanks,
    : Olutunde.
    Hi,
    you can create and manipulate record groups at runtime(see Forms
    Reference 'Create_Group' and 'Add_Group_Row') don't use
    Create_Group_from_Query. For your purpose it's better to build a
    cursor loop on your Query and add your datas after
    manipulating with 'Add_Group_Row' to your Record Group.
    It's possible to SET_BLOCK_PROPERTY(QUERY_DATA_SOURCE_NAME) but
    it's not possible to change the item property 'Column Name'.
    Therefor I would suggest to build a non database block and
    populate these block by a programm unit, which works with a
    pl/sql cursor loop and the 'create record' to populate these
    block.
    null

  • Cursor using variable table name

    I'm new to Oracle, and am wondering if I can create a cursor that can take a variable name as the table it's selecting from. I am working on an application that is loading data to 1 of 3 tables. The table name is stored as a variable and the loads are done using dymanic sql to constuct the insert statement. At the end, I want to select and process some specific info from the table that's been loaded by cycling thru a cursor on whichever of the 3 tables was populated. I could create 3 cursors, one for each table, test the table_name variable, and then reference the specific cursor that way, but I thought there must be another way to do this. I want to be able to do something like this:
    CURSOR loaded_table is select distinct(process_key) from 'v_tablename' (where v_tablename is either TABLE2, TABLE2 or TABLE3)
    Any suggestions would be greatly appreciated.
    Tks...MCR

    It's possible to use dynamic SQL for something like this. If we're only talking about three tables, though, my hunch is that you'll be much happier defining three different cursors. Dynamic SQL is significantly harder to write, debug, and maintain than static SQL, so you're better off resorting to it only when there are so many tables that static SQL is impractical.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • Variable table name in the select statment ?

    data: h_itab like hier_out occurs 0 with header line,
          table_name(30) type C.
    here i declare h_itab as the variable for the table name
    itab_name = input_name
    input_name is imported
    select * from table_name
           into table h_itab
           where OBJVERS = 'A'.
    it does not allow me to use table_name in the select statement i get the error 'table_name is not defined i the abap dictionary as a table, projection view or database view'.
    Any suggestions are highly appreciated.
    Thanks in advance,
    BWer

    Hi,
    You must enclose the name of the table in braces to let the compiler know that the value will be supplied at run time.
    For example -
    tables mara.
    data table_name(30) type c.
    table_name = 'MARA'.
    SELECT *
      FROM (table_name)
    endselect.
    Regards,
    Anand Mandalika.

  • 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.

  • 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

  • Variable table name

    Hi all,
    I tried to execute the statement below inside a push button on forms 6i
    select count(*) into :global.temp from *:variable_table_name* where rownum=1;
    but it fails to compile because it only accepts a static table name....I need such statement because i wanna check empty table that is to be selected by user
    from list item (variable_table_name ) that contain table names
    Any help or advice ? thanks

    Hi,
    You can not use statement like this in forms. You will have to use EXECUTE IMMEDIATE or DBMS_SQL
    One example through EXECUTE IMMEDIATE.
    Create one function in database as below...
    CREATE OR REPLACE FUNCTION EXEC_STR(vStr IN VARCHAR2) RETURN NUMBER IS
      vCnt NUMBER;
    BEGIN
      EXECUTE IMMEDIATE vStr INTO vCnt;
      RETURN vCnt;
    END;and then from your form you can use like below...
    :GLOBAL.temp:=EXEC_STR('SELECT COUNT(*) FROM '||:variable_table_name);-Ammad

  • INNER join with dynamic table name ?

    Hi,
    I have a problem with this statement.
    DATA: g_dso_bic_dofr TYPE tabname.
    SELECT t1~/bic/ziparomr
           t2~/bic/zifremom
    INTO (wa_rater_paromr-/bic/ziparomr,
           wa_rater_paromr-/bic/zifremom)
    *   FROM /bic/azd0bfr5100 AS t1     "equivalent to the dynamic statement below
    " this is the  problem
        FROM (g_dso_bic_dofr )AS t1
        INNER JOIN /bic/pzifremom AS t2
          ON t1~/bic/ziparomr = t2~/bic/ziparomr
    " --- to here
        WHERE t1~/bic/zikom     =  v_kommune
    The compile check doesnt work when i use the variable table name.
    I get
    "Wrong expression "INNER" in FROM clause. WHERE condition."
    Can anyone help me.
    Br Rasmus.

    " this is the  problem
    *    FROM (g_dso_bic_dofr )AS t1   "<<--- check spaces in here
        FROM (g_dso_bic_dofr) AS t1    "<<--- and here
        INNER JOIN /bic/pzifremom AS t2
          ON t1~/bic/ziparomr = t2~/bic/ziparomr
    " --- to here
    I think there's the problem, the space behind the parenthesis.
    Regards

  • Variable Table

    Hi
    Using Apex 3.2
    I have a cascading select box problem I hope you can help with:
    The first select box dynamically displays a list of Oracle Views, constructed based on a specific pattern and strips out the sever name as the display value and holds the View Name as the return value. This works fine.
    The second select box is supposed to return a list of distinct owners from the "owner" column in this view (same column for display and return values). This does not work!!
    The cascade is supposed to work by reading the view name from select box 1 and using this in the "From" clause to specify the view to run the select from.
    If I hard code a View name from the first select box into the second process it works ok.
    So 2 questions:
    1) Is it possible to pass a variable table name eg "select * from :var_name", If it is possible how can I fix this?
    2) Is there an alternative way to select from different tables/views based on user selection?
    Thanks in anticipation
    Edited by: DarrenG on Nov 30, 2010 10:03 AM
    Edited by: DarrenG on Nov 30, 2010 10:33 AM

    Hi Darren,
    What tables/views are you using to get the data for the lists?
    Have you tried ALL_VIEWS? This gives you all of the view names and their owners.
    I don't think that you can directly use PL/SQL type statements for a select list - but you can use Ajax to get the information and that does use PL/SQL and accepts variables.
    However, your SQL statement - "SELECT * FROM :var_name" - implies that you want to generate a report from the selected view? If so, that can be done using a PL/SQL region of type: SQL Query (PL/SQL function body returning a SQL query). The source for that would be something like:
    DECLARE
    vSQL VARCHAR2(100);
    BEGIN
    vSQL := "SELECT * FROM " || :var_name;
    RETURN vSQL;
    END;and make sure that you use the "Use Generic Column Names (parse query at runtime only)" option underneath that so that column names are handled correctly.
    Andy

  • How to use table name as variable in insert statement

    Hi,
    I want to insert data from the cursor into the table and I want to submit table name as a variable. I tried the code below but it's not working. Any ideas how to solve this problem? Thx
    DECLARE
    v_new_table_name VARCHAR2(30) := 'test';
    --open cursor   
    CURSOR ACM IS
    SELECT *
    FROM DWH.CLI_DIMENSION@SLSPDW CLI
    WHERE where_clause
    FROM some_table;
    BEGIN
    FOR REC_ACM IN ACM LOOP
    EXECUTE IMMEDIATE 'INSERT INTO ' || v_new_table_name || ' VALUES REC_ACM'; --table name as a variable in which the data from cursor will be inserted
    V_ROWCOUNT := V_ROWCOUNT + 1;
    IF MOD(V_ROWCOUNT, 100) = 0 THEN --this feature commits after 100 rows.
    COMMIT;
    END IF;
    END LOOP;
    COMMIT;
    DBMS_OUTPUT.PUT_LINE('Number of inserted records:' || V_ROWCOUNT);
    END;

    Try this and let me know if it works. I have not tested it so I can not say for sure.
    DECLARE
      v_new_table_name VARCHAR2(30) := 'test';
      CURSOR ACM IS
        SELECT * FROM DWH.CLI_DIMENSION@SLSPDW CLI
                WHERE where_clause
                FROM some_table;
      BEGIN
      loop
       fetch ACM INTO REC_ACM
       exit when ACM%NOTFOUND;
       EXECUTE IMMEDIATE 'INSERT INTO ' || v_new_table_name || ' VALUES REC_ACM';
       V_ROWCOUNT := V_ROWCOUNT + 1;
       IF MOD(V_ROWCOUNT, 100) = 0 THEN
        COMMIT;
       END IF;
      end loop;
      COMMIT;
      DBMS_OUTPUT.PUT_LINE('Number of inserted records:' || V_ROWCOUNT);
      END;

  • 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.

  • Create table where table name is a variable

    I need to be able to create tables where the table name is a variable . Using PL/SQL in Oracle 9. Also need to insert and query the table.
    THANK YOU

    Use 'execute immediate' in pl/sql:
    execute immediate 'create table '||var_tablename||'...';

  • Bug in PL/SQL - Does not update Table if table name & variable name same in

    Dear All,
    If tabale name & vairable name is same in a Stored Procedure, UPDATE to table does not take place.
    For example run following 2 procedures. First procedure does the insert properly to table but second procedure does not update the table.
    create or replace procedure BugDemo1
    as
    LAST_NAME VARCHAR2(30);
    FIRST_NAME VARCHAR2(30);
    Begin
    LAST_NAME := 'Prasad';
    FIRST_NAME := 'Raghnandan';
    Insert into com_people (id,Roles, LAST_NAME, FIRST_NAME) values (77777,'Patient', LAST_NAME, FIRST_NAME);
    end;
    create or replace procedure BugDemo2
    as
    LAST_NAME VARCHAR2(30);
    FIRST_NAME VARCHAR2(30);
    Begin
    LAST_NAME := 'Pra';
    FIRST_NAME := 'Raghu';
    Update com_people set
    LAST_NAME = LAST_NAME,
    FIRST_NAME = FIRST_NAME
    where id = 77777 ;
    end;
    ------------------------------------------

    Hi,
    It is not a bug. Oracle is updating the records. Here Oracle is treating the variable name as COLUMN_NAME. Since priority is higher for a COLUMN on variable so each column is getting updated by itself resulting no change in data.
    SQL> CREATE TABLE com_people
      2  (
      3  id NUMBER (5),
      4  Roles VARCHAR2(20),
      5  LAST_NAME  VARCHAR2(20),
      6  FIRST_NAME VARCHAR2(20)
      7  )
      8  ;
    Table created
    SQL> Insert into com_people (id,Roles, LAST_NAME, FIRST_NAME) values (77777,'Patient', 'LAST_NAME', 'FIRST_NAME');
    1 row inserted
    SQL> COMMIT;
    Commit complete
    SQL>
    SQL> create or replace procedure BugDemo2
      2  as
      3  LAST_NAME VARCHAR2(20);
      4  FIRST_NAME VARCHAR2(20);
      5  Begin
      6  LAST_NAME := 'Pra';
      7  FIRST_NAME := 'Raghu';
      8 
      9  Update com_people set
    10  LAST_NAME = LAST_NAME,
    11  FIRST_NAME = FIRST_NAME
    12  where id = 77777 ;
    13 
    14  DBMS_OUTPUT.PUT_LINE('UPDATED ROWS ='||SQL%ROWCOUNT);
    15  end;
    16  /
    Procedure created
    SQL> set serveroutput on
    SQL> execute BugDemo2;
    UPDATED ROWS =1
    PL/SQL procedure successfully completed
    SQL> Regards

  • Passing table names through variables

    Hi All,
    Is it possible to pass the table name in a query using a variable.
    For example - can we perform a select on a table where the table name is passed using a variable.
    Pl assist. Thanks.

    Hello,
    Are you wanting to do this in a procedure? Say the table name being passed in as Input Parameter?
    We can do that using Dynamic SQL:
    CREATE PROCEDURE "PROC_01"
    (IN v_IN_Var1 NVARCHAR)
    LANGUAGE SQLSCRIPT AS
    BEGIN
        DECLARE ABC NVARCHAR(300) := NULL;
        ABC := 'SELECT * FROM ' || :v_IN_Var1;
        EXEC (:ABC);
    END;
    CALL PROC_01 ('DUMMY');
    But the only thing is you'll not be able to see the result set directly.
    You might wan2 fire the select to insert the data into a different table.

Maybe you are looking for

  • Recovering lost data from a very old backup (disaster recovery)

    Hi all, I am trying to restore and recover data from an old DAT-72 cassette. All I know is the date when the backup was taken, that is back in November 2006. I do not know the DBID or anything else except for the date. To recover this, I bought an in

  • How to hadle the errors in sturts

    hi, How to handle the error messages in struts. please any one can help me. regards,

  • How to find invalid objects in specific schema?

    Please let me know hoe to find invalid objects in specific schema such as SYS? Please help and guide Thanks, Waheed.

  • 100% disk Activity

    https://onedrive.live.com/redir?resid=839C8B756498A91A!249&authkey=!AITa4iG_A7PSKII&ithint=file%2c.etl I have erased my drive and put a clean installation of Windows 8.1 on it twice. Both times my disk usage spikes to 100% every time I start a new pr

  • New game preview n8 and c7

    please talk about new game preview for n8 and c7....games very low foe these mobile phone