*Dynamic* Table Name in From Clause with input from cursor

Hello
I have a cursor say...
select table_name from dba_tables where <blah>
The result is
row1:: emp
rwo2:: emp_1 ---> Both the tables have same structure and entirely different data... please dont ask why... that's the way it is and we cant change it..
Now we need to run an Insert...
insert into tableX (col1,col2,...) select a,b,... from <o/p of the cursor> where <blah> ...
Note: The table name changes and it the cursor can o/p emp,emp_a and emp_b.
Am looking to do it parallel instead of doing it serially and with best performance ....no sql injection issues.
By parallel i mean
insert into tableX (col1,col2,...) select a,b,... from emp where <blah>
and insert into tableX (col1,col2,...) select a,b,... from emp_1 where <blah> statements to fire parallel/at the same time to the database. If you can share procedure if you guys already have with you.. is really appreciated
Thanks a lot for your time....
Edited by: user007009 on Apr 27, 2013 8:33 PM

Hello thanks for your time..
I tried to implement the chunk by sql parallel execution approach and it took 3.1 seconds to complete.. while the SP took around 0.042 seconds and the parallel process didn't throwed any errors and it didn't insert any data either... I am not sure what I am doing wrong... can you please let me know your thoughts...
Sample Data Creation::::::::::::::*
drop table table_ASERCARE purge;
drop table table_MEDCARE purge;
DROP TABLE TABLE_XYCARE PURGE;
DROP TABLE TABLE_TIME PURGE;
DROP TABLE TABLE_LOCATION PURGE;
drop table table_group purge;
drop table tablex purge;
-- select distinct TABLE_NAME from ALL_TAB_COLS where TABLE_NAME like 'EMP%';
create table table_asercare (time number(30), location_number number(5), value number(5),catg_id number(5));
insert into table_asercare values  (20110111, 01, 55, 1200);
insert into table_asercare values  (20110131, 01, 31, 1223);
insert into table_asercare values  (20120131, 15, 24,1224);
insert into table_ASERCARE values  (20130131, 03, 555,1200);
-- Truncate table table_MEDCARE
create table table_medcare (time number(30), location_number number(5), value number(5),catg_id number(5));
insert into table_medcare values  (20110113, 01, 23, 1200);
insert into table_medcare values  (20110128, 02, 78, 1223);
insert into table_medcare values  (20110130, 03, 100, 1224);
insert into table_medcare values  (20120111, 04, 57, 1200);
insert into table_medcare values  (20120221, 05, 64, 1223);
insert into table_MEDCARE values  (20130321, 15, 48, 1224);
create table table_xycare (time number(30), location_number number(5), value number(5),catg_id number(5));
insert into table_xycare values  (20100113, 01, 99, 1200);
insert into table_xycare values  (20110128, 02, 90, 1223);
insert into table_XYCARE values  (20130128, 03, 24, 1224);
create table table_LOCATION ( LOCATION_NUMBER number(5), LOCATION_NAME varchar2(50));
insert into table_LOCATION values  (01, 'atlanta1');
insert into table_LOCATION values  (02, 'atlanta2');
insert into table_LOCATION values  (03, 'atlanta3');
insert into table_LOCATION values  (04, 'atlanta4');
insert into table_LOCATION values  (05, 'atlanta5');
insert into table_location values  (15, 'atlanta15');
create table table_category (catg_id number(5), catg_name varchar2(30));
insert into table_category values (1200, 'EMS');
insert into table_category values (1223, 'LJM');
insert into table_category values (1224, 'LIO');
create table table_TIME (YEAR_MONTH_DATE number(30), YEAR_VAL number(4), MONTH_VAL number(2),DATE_VAL number(2));
insert into table_TIME values  (20110111, 2011, 01,11 );
insert into table_TIME values  (20110131, 2011, 01,31);
insert into table_TIME values  (20120131, 2012, 01,31);
insert into table_TIME values  (20130131, 2013, 01,31);
insert into table_TIME values  (20110128, 2011, 01,28 );
insert into table_TIME values  (20110130, 2011, 01,30 );
insert into table_TIME values  (20120111, 2012, 01,11 );
insert into table_TIME values  (20120221, 2012, 02,21 );
insert into table_TIME values  (20130321, 2013, 03,21 );
insert into table_TIME values  (20100113, 2010, 01,13 );
insert into table_TIME values  (20130128, 2013, 01,28 );
--Truncate table table_group
CREATE TABLE table_group (group_key number,table_name VARCHAR2(30), group_name VARCHAR2(30), catg_name varchar2(30));
insert into table_group values (1,'table_ASERCARE', 'GROUP_ONE','EMS');
insert into table_group values (2,'table_MEDCARE', 'GROUP_ONE','LJM');
INSERT INTO TABLE_GROUP VALUES (3,'table_XYCARE', 'GROUP_TWO','LIO');
create table TABLEX (YEAR_VAL number(4) ,LOCATION_NAME varchar2(50),tablename VARCHAR2(30), cnt number ); --> Proc data will be inserted into this...
Stored Procedure++++++++_
CREATE OR REPLACE
PROCEDURE ABC(
    GROUP_NAME_IN IN VARCHAR2 )
is
type c1 is ref cursor;
    sql_stmt VARCHAR2(200);
    v_sql    VARCHAR2(30000);
    c1_cv c1;
    table_name_f VARCHAR2(30);
    c1_rec TABLE_GROUP%rowtype;
  BEGIN
    SQL_STMT := 'SELECT * FROM TABLE_GROUP WHERE GROUP_NAME = :i';
    OPEN c1_cv FOR SQL_STMT USING GROUP_NAME_IN ;
    loop
      fetch c1_cv  INTO c1_rec;
    exit when c1_cv%notfound;
--    forall i in c1_rec.FIRST ..c1_rec.last loop
    table_name_f := c1_rec.table_name;
--      END LOOP;
   EXECUTE immediate
   'INSERT  INTO tablex (YEAR_VAL,LOCATION_NAME, tablename, cnt)
SELECT
t.YEAR_VAL,l.location_name, :table_name, count(*) as cnt
FROM '
    ||table_name_f||
    ' variable_table
,table_time t
, table_location l
,table_group g
,table_category ctg
WHERE t.year_month_date = variable_table.TIME
and variable_table.location_number = l.location_number
and ctg.catg_id = variable_table.catg_id
--and ctg.catg_name = g.catg_name
GROUP BY t.YEAR_VAL,l.location_name,g.catg_name' USING table_name_f;
    --dbms_output.put_line ( 'The SQL is'|| v_sql);
    COMMIT;
    --dbms_output.put_line ( c1_rec.table_name||','||c1_rec.group_name );
    --dbms_output.put_line ( 'The table name is '|| c1_rec.table_name );
  end loop;
    CLOSE c1_cv;
  --null;
END ABC;
Parallel Execution Code++++++++++_
begin
begin
DBMS_PARALLEL_EXECUTE.DROP_TASK(task_name => 'TASK_NAME');
exception when others then null;
end;
DBMS_PARALLEL_EXECUTE.CREATE_TASK(task_name => 'TASK_NAME');
DBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_SQL(task_name => 'TASK_NAME', sql_stmt =>'select distinct group_key, group_key from table_group', by_rowid => false);
end;
begin
DBMS_PARALLEL_EXECUTE.RUN_TASK (task_name => 'TASK_NAME',
sql_stmt =>'declare
s varchar2(16000); vstart_id number := :start_id; vend_id number:= :end_id;
table_name varchar2(30);
begin
select table_name into table_name from group_table where group_key=vstart_id;
s:=''INSERT  INTO tablex (YEAR_VAL,LOCATION_NAME, tablename, cnt)
SELECT
t.YEAR_VAL,l.location_name, :table_name, count(*) as cnt
FROM ''||table_name||'' variable_table
,table_time t
, table_location l
,table_group g
,table_category ctg
WHERE t.year_month_date = variable_table.TIME
and variable_table.location_number = l.location_number
and ctg.catg_id = variable_table.catg_id
and ctg.catg_name = g.catg_name
and g.group_key =:vstart_id
GROUP BY t.YEAR_VAL,l.location_name,g.catg_name'';
execute immediate s using vstart_id;
commit;
end;',
language_flag => DBMS_SQL.NATIVE, parallel_level => 2 );
end;
/ thanks in advance for your time.
Edited by: user007009 on Apr 28, 2013 12:25 PM

Similar Messages

  • Problem with Dynamic Table Name

    Hello all,
    I am having trouble using a dynamic table name. I have the following code.....
    declare l_cur sys_refcursor;
    l_ID int;
    l_tableName varchar(30);
    BEGIN
    open l_cur for
    select hkc.ColumnID, mapping from &HKAPPDB_Schema_Name..doctablemapping ddm
    inner join &HKDB_Schema_Name..HKColumns hkc on hkc.doctablemappingid = ddm.id
    where ddm.id > 0;
    LOOP
         FETCH l_cur into l_ID, l_tableName;
         EXIT WHEN l_cur%notfound;
         -- update missing VerbID in DocumentDocMapping table
         UPDATE &HKAPPDB_Schema_Name..IndexedDocument
         SET VerbID = (SELECT t.VerbID
                             FROM (SELECT DocRef, VerbID, DateUpdated
                                  FROM &HKAPPDB_Schema_Name..l_tableName dd        - this is where the dynamic table name is used
                                  WHERE dd.VerbID is not NULL))
         WHERE HKColumnID = l_ID AND VerbID is NULL;
    END loop;
    end;
    /When I try to execute this i get an error
    ORA-00942: table or view does not exist
    What am I doing wrong?
    Regards,
    Toby

    redeye wrote:
    I only started about 6 weeks ago, with no tutorials and learning it on the fly; Same here.. only my introduction was to a 12 node Oracle OPS cluster all those years ago.. and required a whole new mind set after using SQL-Server extensively. But it was fun. Still is. :-)
    but thats what you get when a company throws you in at the deep end with a ridiculous time constraint to migrate a whole MSSQL DB.Migrating SQL-Server to Oracle is not a simple thing. A lot of best practices in SQL-Server are absolutely worse practices in Oracle - they are that different. Simple example is lock escalation - an issue in SQL-Server. In Oracle, the concept of a lock being escalated into a page lock simply does not exist.
    In terms of getting the migration done as quickly and painlessly as possible I try to reuse all the logic as it appears in the MSSQL code - in this case it was using dynamic table names. I do not doubt that i am probably shooting myself in the foot in the long run.....As long as you do not splatter too much blood on us here.. not a problem :D
    Seriously though - just keep in mind that what works in SQL-Server may not work as well (or even at all) in Oracle. So do not hesitate to refactor (from design to code to SQL) mercilessly when you think it is warranted.

  • Dynamic table name from Arguments in cfquery /

    I'm trying to use dynamic table names in a cfc but seem to
    have hit upon a wall as my calling methods from flash keep hitting
    my _error methods - Code attached to show what I'm trying to
    achieve; if anyone can give me some pointers it would be a great
    help. I've seen numerous by using the Form with the arguments but
    this is coming into a gateway used by a flash component and doesn't
    work no matter how much I fiddle the code.
    Thanks in advance

    There was a time when I needed a dynamic query such as this.
    BUT, it is very dangerous, which is why I took a few steps to make
    it more secure.
    1. Always use cfqueryparam and strict datatyping
    2. Use listFindNoCase for known table names in the database
    e.g
    <cfset variables.tableNames =
    "items,products,categories,blog" />
    <cfif
    listContainsNoCase(variables.tableNames,lCase(trim(arguments.tableName)),",")>
    query here
    <cfelse>
    Error: Unknown table requested
    </cfif>
    Mikey

  • How to set dynamic table name in sql query?

    I want set dynamic table name by parameter in sql query,just like:
    select * from :tbname
    but run report is error,BI P report table name is invalidation.
    What can i do? Thanks!

    Hi,
    that's only possible inside a data template with a lexical parameter.
    Regards
    Rainer

  • (Urgent) Dynamic Table Name

    Hi Fellows,
    Can I use dynamic table name in a loop? I have a problem that I want to use variable table in a cursor for example
    procedure check_rows as
    cursor c1 is
    select view_name
    from user_views;
    v_count number;
    v_view_name varchar2(35);
    begin
    for i in c1 loop
    select count(*)
    into v_count
    from i.view_name;
    if v_count = 0 THEN
    dbms_output.put_line ('The View '&#0124; &#0124;i.view_name&#0124; &#0124;' has no rows');
    end if;
    end loop;
    end;
    but i receive a message
    i.view_name must a name of a table to which the user has access.
    Can anybody solve my problem.
    Thanks in advance
    Mustafa

    Here is some codes I wrote with DBMS_SQL. I hope it will help you to start.
    PROCEDURE Get_record(p_select IN OUT select_rec, where_str IN OUT varchar2) IS
    my_keyblk varchar2(6);
    veh_id integer;
    ser_date date;
    succ_flag number;
    blk_route varchar2(4);
    blk_run integer;
    my_date_type integer;
    cur_blk_route INTEGER;
    rows_processed INTEGER;
    ignore integer;
    select_str varchar2(3000);
    First_date date;
    Last_date date;
    BEGIN
    begin
    select start_date, end_date into first_date, Last_date from change_date
    where current_next_code = 'CURRENT';
    exception when others then
    null;
    end;
    select_str := 'select keyblock, keycoach, proflag, pullout_date
    from logblock
    where (pullout_date between first_date and Last_date)
    and proflag = 0';
    cur_blk_route := dbms_sql.open_cursor;
    dbms_sql.parse(cur_blk_route, select_str, dbms_sql.v7);
    dbms_sql.define_column(cur_blk_route, 1, blk_route, 6);
    dbms_sql.define_column(cur_blk_route, 2, blk_run);
    dbms_sql.define_column(cur_blk_route, 3, veh_id);
    dbms_sql.define_column(cur_blk_route, 4, ser_date);
    ignore := dbms_sql.execute(cur_blk_route);
    LOOP
    if (dbms_sql.fetch_rows(cur_blk_route) > 0) then
    dbms_sql.column_value(cur_blk_route, 1, blk_route);
    dbms_sql.column_value(cur_blk_route, 2, blk_run);
    dbms_sql.column_value(cur_blk_route, 3, veh_id);
    dbms_sql.column_value(cur_blk_route, 4, ser_date);
    else
    dbms_output.put_line('ERROR ');
    end if;
    END LOOP;
    dbms_sql.close_cursor(cur_blk_route);
    END Get_record;
    end apc_block_assign;
    null

  • Analyse big data in Excel? Why the dynamic tables doesn't take all the data from the source table.

    Hi,
    I'm doing a internship in a production line.
    My job is to recover production data (input data) and test data (output data) using various types of software (excel, BusinessObject sap, etc).
    To this day, I have recovered hundreds of production data, and have also organized in excel but I need to analyze and plot them.
    I would like to know who can give me an idea of ​​how I could plot as much data and analysis.
    Now i trying to use dynamic charts and plot some data but I did not get acceptable answers.
    How could I compare, analyze and graph for example:
    Five columns of production (input) with five (5) columns tested (data output).
    After graphing.
    Someone can give me a technique to analyze data? ie I compare column by column?
    or some other technique? as a conglomerate could analyze data?
    o give you an idea of ​​the contect, now I perform an internship in a manufacturing turbines.
    My job is to analyze the input data (production) and to estimate the possible behavior of the turbines in the tests.
    As I said, use dynamic tables in excel, but i have not idea why the dynamic tables doesn't  take all the data from the source table.
    I appreciate your advice
    Thanks

    You can declare as PT source whole Columns [$A:$E], without rows number.
    Then You'll have all actually data.
    Oskar Shon, Office System MVP - www.VBATools.pl
    if Helpful; Answer when a problem solved

  • Table name for sales order with Customer info

    Hi Gurus,
    Could you please provide me table name for  sales order with customer no and customer name.
    I have list of sales order number (more than 1000 no's ) i need to identify customer number and customer name (ship to party and sold to party information). I am running this report every week. so i plan to create sqvi for this report.
    Thanks and regards,
    B.Deethya.

    Hello,
    Access Tables VBAK & VBAP.
    From the above tables you will get Solt to Party & Ship to Party Codes.
    For Customer names you have to pass the Customer Codes to Table - KNA1
    Hope this clarifies.
    Thanks,
    Jignesh Mehta

  • Dynamic table name in an inner join - select statement

    Hi,
    Please can you let me know if is possible to use a Dynamic table name in an inner join?
    Something like the statement below? (It works in a simple select statement but not in an inner join)
    SELECT  *
         INTO CORRESPONDING FIELDS OF <t_itab>
          FROM <Dynamic table name> INNER JOIN pa0050 ON
          ( <Dynamic table name>pernr =  pa0050pernr )
           WHERE <Dynamic table name>~pernr = it_pernr-l_pernr
           AND pa0050~bdegr = f_bdegr.
    Any help would be apprecited very much.
    Thanks & Regards.

    Hi,
    Check this link.
    [http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm]
    [Re: accessing dynamic internal table's fields??;
    hope it'll help u.
    Regards,
    Sneha.
    Edited by: sneha kumari on Jun 18, 2009 1:57 PM

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

  • 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 Table name in Inner Join in  4.6c

    data: tab1(10) type c value 'MARA',
            tab2(10) type c value 'MAKT'.
    data: dbtab1(10) type c,
             dbtab2(10) type c .
    dbtab1 = tab1. 
    dbtab2 = tab2. 
    DATA: BEGIN OF itab occurs 0,
               matnr TYPE mara-matnr,
               maktx type makt-maktx,
    END OF itab.
    DATA: column_syntax TYPE string,
                dbtab_syntax TYPE string.
    PARAMETERS: p_matnr TYPE mara-matnr.
    dbtab_syntax = '( (dbtab1) AS t1 '
    &' INNER JOIN (dbtab2) AS t4 ON t1MATNR = t4MATNR )'.
    SELECT  matnr maktx
    FROM (dbtab_syntax)
    INTO TABLE itab  WHERE t4~matnr   = p_matnr.
    Got the following error:
    "A table name, specified in an SQL command, is unknown"
    It seems not able to read dynamic table name in dbtab_syntax.
    thanks
    anya
    Moderation Message: Duplicate Post.
    Edited by: kishan P on Nov 29, 2010 11:17 AM

    Hi,
    Check this link.
    [http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm]
    [Re: accessing dynamic internal table's fields??;
    hope it'll help u.
    Regards,
    Sneha.
    Edited by: sneha kumari on Jun 18, 2009 1:57 PM

  • Passing dynamic table name in ADO. net destination

    I am new to SSIS and I have a requirement where i need to pass dynamic table name in ADO .net destination .
    My package contains an "Execute Sql task" in the control flow which computes the destination table name to be provided at run time and stores it in a variable expression
    "@[User::Table_name]"(which has a scope of full package). 
    Now, the problem I'm facing right now is that , I am unable to use this variable expression in the ADO .Net Destination .
    I need to pass this variable expression as the table name in ado .net destination.
    But, whenever I use this variable in place as the table name I keep on getting this error and my package fails:- 
    [ADO NET Destination [403]] Error: The Table or View name is not expected. \n\t If you are quoting the table name, please use the prefix " and the suffix " of your selected data provider for quotation. \n\t If you are using multipart name,
    please use at most three parts for the table name. 
    Although ,I am able to run my package when i am providing the existing(static) table name.So there is nothing wrong with the  package.
    Tried a lot of things still not working..Please help...

    I am having the result stored in the variable expression . I just need a way to be able to use it as the Destination table in ADO .net Destination.
    I am not sure if this will work for you, but I am able to store the table name in variable and use it dynamically (via data flow task expression property ) as shown.
    Thanks, hsbal
    Hi Adeep,
    Based on my further research, just as hsbal said, we can set a variable as ADO.NET Destination table via Expressions property in Data Flow Task.
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Dynamic table name - error

    After run (or test) of procedure
    create or replace procedure tmp_select_dymanic
    ( AInTable IN VARCHAR2,
    ACount OUT NUMBER
    ) as
    begin
    EXECUTE IMMEDIATE 'BEGIN SELECT count(*) INTO :Count FROM :InTable END;'
    USING ACount, AInTable;
    end tmp_select_dymanic;
    error message: invalid table name.
    I know the table exists and contains data. I can make SELECT in SQL (not dynamic).
    What a reason for error? May be privileges in database? But i make SELECT on my own table?
    How can i set dynamic table name in other way?
    My Oracle Version 10g.

    What you are asking can be done by REF_CURSOR;
    look this example and try your self the rest:
    CREATE OR REPLACE PROCEDURE insert_to_table_dinamic (
       table1   IN   VARCHAR2,
       table2   IN   VARCHAR2
    AS
       rc         sys_refcursor;
       v_sql      VARCHAR2 (2000);
       v_deptno   NUMBER;
    BEGIN
       v_sql :=
             'SELECT DEPTNO FROM '
          || table1
          || ' WHERE ROWNUM = 1 AND DEPTNO IS NOT NULL';
       OPEN rc FOR v_sql;
       LOOP
          FETCH rc
           INTO v_deptno;
          EXIT WHEN rc%NOTFOUND;
          v_sql :=
                'UPDATE '
             || table2
             || ' SET DEPTNO = '
             || v_deptno
             || ' WHERE DEPTNO IS NULL';
          EXECUTE IMMEDIATE v_sql;
       END LOOP;
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line (SQLCODE || SQLERRM);
    END insert_to_table_dinamic;when i give DEPT , EMP as my 2 parameters above code will set the deptno in EMP table where deptno is null;
    --Just a test proc.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Table name should be concatenated with month & year eg.product_may09

    hello all,
    I have to take a backup of table on monthly basis. for this table name should be concatenated with previous month and year eg., product_may09.. I tried with Create table stmnt its not working anyone please help.

    It would be very generous from you if you would provide us with versions, what you did and what's not working (maybe an error message?)...
    Anyway; If I got you right you want to create a backup table with the same structure and data as in your base table?
    maybe this:
    forms_ddl('create table product_'||to_char(sysdate, 'monyy')||' as select * from product');fits your requirement. This creates you a table with the same structure and data as your basetable (except the primary/foreign keys, indices and trigger you have on the basetable).
    But if you have to do this every month by hand I'd go for a database job which runs once a month with the above statement. In database procedures you have to use execute immediate instead of forms_ddl; usage is the same (except execute immediate raises intelligent exceptions in contrary to forms_ddl). take a look at http://tahiti.oracle.com and search after dbms_job or dbms_scheduler (depending the database version you use which you also didn't mention)
    regards

  • Table name for Invoice created with PO ref

    hi,
    I required Table name for Invoice created with PO ref.
    Regards,
    Ali

    HI,
    Check the table RSEG: Document Item: Incoming Invoice
    Look for the fields BELNR and EBELN
    Regards
    KK

Maybe you are looking for

  • Error in Reciever RFC Adapter

    Hi All, While working with JDBCXIRFC, the only error with Reciever RFC Adapter is as follows. ZBAPICUSTOMER_DETAILS: com.sap.aii.af.rfc.afcommunication.RfcAFWException: error while processing message to remote system:com.sap.aii.af.rfc.core.client.Rf

  • Replacement for defective iMac G5

    I've been offered a replacement for my Rev B iMac G5, after it was unsucessfully reapaired three times in its warranty for the same problem (inverter replaced once and logic board replaced twice for a video issue). Will I receive another iMac G5 or a

  • TFTP 'configuration update' from 5508 WLC fails stating reason as '%Error: Config file transfer failed – Unknown error –refer to log'

    Dear Experts, I have two WLCs and other management devices as part of same subnet. I am able to upload 'configs' from all the devices on to my TFTP server. However when I am attempting to do the same from one of my WLC, it is failing consistently sta

  • Sticky notes problem, Acrobat reader

    Hello, I was unable to find an answer to this question in old discussions therefore I have to ask it. I am preparing pdf file with multiple comments for print. On some pages I have more than one comment and I can't have them all open at the same time

  • Premier Pro CC 2014 Extremely slow in Rendering-No Hardware Utilization

    Hi, My name is Avinash and I am working as in-house Media production Specialist in BMC Software. Earlier we had MacBook Pro for all post production with adobe CC. we faced so many rendering issues during last year using mac, so we decided to switchov