Table name change in procedure dynamically

create table tab1(x number);
create table dynamic_table (x number);
insert into tab1 values (1);
insert into dynamic_table values (1);
commit;
create procedure proc1
is
v_x number;
begin
execute immediate 'create table mytab
as select tab1.*
from tab1, tabc
where tab1.x = dynamic_table.x';
end;
begin
proc1;
end;
/dynamic_table --> should be dynamically replaced in the procedure
There are two more tables in this scenario - tabe and tabf, In the above procedure, I have to dynamically replace dynamic_table first with tabe, call it, then then replace with tabf and execute procedure again
Is there a way I can do that ? any dynamic sql that will prompt me to call proc1 twice, 1st time replace dynamic_table with tabe, then with tabf
the structure of tabe and tabf is the same, I am currently passing a parameter to the procedure and replacing dynamic_table with the input parameter, and then
calling the procedure twice by passing the table names, wanted to follow a better approach
Currently, I am doing somethig like this:
create procedure proc1 (i_param in varchar2)
is
v_x number;
begin
execute immediate 'create table mytab
as select tab1.*
from tab1, tabc
where tab1.x = i_param.x';
end;
begin
proc1('tabe');
proc1('tabf');
end;
/

Why are you trying to do this?
Good database design practice means that you don't create tables dynamically within your code.
Why do you have tables of the same structure with different names?
Dynamic table names are not a good idea because it means all your code has to be dynamic.
So whilst it's perfectly possible to do what you are asking, showing you how to do it would be like me showing you how to fly a plane into the ground, i.e. not something that's clever or wise.
So, better you explain what problem you are trying to solve rather than ask us how to improve on the poor code you are already trying to do.

Similar Messages

  • Passing table name to a procedure and then need to open a cursor ..

    Hi All,
    I have been out of touch in plsql for sometime and need to do something like :
    passing table name to a procedure while calling(fp_table_old captures this value) and then need to open a cursor for this table in 'for i in (select * from fp_table_old )', one of the ways I tried is : for i in (execute immediate Lv_sql_query ) but its not working for me, please find the code below for reference, I know I am sounding stupid but I have been very out of touch, please help.
    code :
    create procedure p_table_compare(fp_table_old in varchar2, fp_table_new in varchar2)
    as
    Lv_sql_query varchar2(2000);
    begin
         Lv_sql_query := 'select * from '||fp_table_old;
         for i in (Lv_sql_query)
         loop
              dbms_output.put_line(i.employee_id);
         end loop;
    end;
    Regards
    Rahul

    if I am doing something like this : for i in (execute immediate Lv_sql_query)
    I am getting an error which is :
    PLS-00103: Encountered the symbol "IMMEDIATE" when expecting one of the following:
    . ( ) , * @ % & | = - + < / > at in is mod remainder not
    range rem => .. <an exponent (**)> <> or != or ~= >=
    My code:
    create or replace procedure p_table_compare(fp_table_old in varchar2, fp_table_new in varchar2)
    as
    Lv_sql_query varchar2(2000);
    begin
         --dbms_output.put_line('Hello World');
         Lv_sql_query := 'select * from '||fp_table_old;
         for i in (execute immediate Lv_sql_query)
         loop
              dbms_output.put_line(i.employee_id);
         end loop;
    end;
    Please help.
    Regards
    Rahul

  • SAP BW structure/table name change issue with BODS Jobs promotion

    Dear All, One of my client has issue with promotion of BODS jobs from one environment to another. They move SAP BW projects/tables along with BODS jobs (separately) from DEV to QA to Prod.
    In SAP-BW the structures and tables get a different postfix when they are transported to the next environment.  The promotion in SAP-BW (transport) is an automated process and it is the BW deployment mechanism that causes the postfixes to change.  As a result with the transport from Dev to QA in SAP-BW we end up with table name changes (be they only suffixes), but this does mean that when we deploy our Data Services jobs we immediately have to change them for the target environments.
    Please let me know if someone has deployed some solution for this.
    Thanks

    This is an issue with SAP BW promotion process. SAP BASIS team should not turn on setting to suffix systemid with the table names during promotion.
    Thanks,

  • Invalid table name when pass in the table name as variable in dynamic sql

    Hi,
    I need to create a stored procedure which will return a list of data to my java application like the following.
    first, select the table name from the first table.
    For example : SELECT T_NAME FROM MDR_SMSTABLES
    second, select the data from the table which returned by first select statement
    For example : SELECT * FROM T_NAME.
    I use dynamic sql with cursor to select the data. But it returns "java.sql.SQLException: ORA-00903: invalid table name"
    I fetch the table name to varchar2. I think this might the cause it returns me the this error. But i don't know what type should i put for the table name other then varchar2.
    val2 VARCHAR2(200);
    OPEN cv FOR
    SELECT T_NAME FROM MDR_SMSTABLES WHERE T_DATE=d_dt_sent;
    FETCH cv INTO val2;
    WHILE cv%FOUND
    LOOP
    OPEN refcur FOR
    'SELECT * FROM :t WHERE MID = :m' USING val2, msg_id;
    EXIT WHEN refcur IS NOT NULL;
    FETCH cv INTO val2;
    END LOOP;
    As my stored procedure is quite long, so i just paste some of the code here. Hope the information is enough. Can anyone please help?
    Thanks

    DECLARE
    val2 VARCHAR2 (200);
    cv sys_refcursor;
    refcur sys_refcursor;
    BEGIN
    OPEN cv FOR
    SELECT table_name
    FROM user_tables
    WHERE table_name IN ('EMP', 'DEPT');
    FETCH cv INTO val2;
    WHILE cv%FOUND
    LOOP
    OPEN refcur FOR 'SELECT * FROM '||val2;
    EXIT WHEN refcur IS NOT NULL;
    FETCH cv INTO val2;
    END LOOP;
    END;

  • Passing Table Name to Stored Procedure for From Clause

    Is it possible to pass a table name to a stored procedure to be used in the From clause? I have the same task to perform with numerous tables and I'd like to use the same SP and just pass the table name in. Something like this:
    =======================================
    CREATE OR REPLACE PROCEDURE SP_TEST(
    in_TABLE IN VARCHAR2,
    AS
    V_TABLE VARCHAR2(10);
    BEGIN
    V_TABLE := 'st_' || in_TABLE; -- in_TABLE is 2-3 character string
    SELECT some_columns
    INTO some_variables
    FROM V_TABLE
    WHERE some_conditions...;
    END;
    =======================================
    I'm also using the passed table name to assign to variables in the Select and Where clauses. What I'm getting is an error that V_TABLE must be declared. When I hard code the table name, I don't get any errors, even though I'm also using the same method to assign values in the Select and Where clauses.
    Thanks,
    Ed Holloman

    You need to use dynamic SQL whenever you are swapping out object names (tables, columns).
    create or replace procedure sp_test
      (in_table in varchar2)
    is
      -- variables
    begin
      execute immediate 'select a, b, c from st_' || in_table || ' where x = :xval and y = :yval'
         into v_a, v_b, v_c using v_x, v_y;
    end;

  • Database "TABLE" name change is NOT reflecting on Designer Security

    Hi all members,
    version: BOXI 3.1
    I have change the table name in my Database for some particular reason.
    After changing the name from "A_Table" to "B_Table" it is updating the objects "select"  information correctly by itslef. BUT for security in (Manage Access Rights) old Table name is showing.
    Manaul correction is the only way for it? Can this be updated automatically.
    What is the way to achieve it through SDK.
    Kindly any member guide me.
    I have number of tables to change and each have number of securities applied in universe.
    Thanks in advance
    Regards,
    Izhar

    Universe access security is encapsulated separate from the Universe unv itself.
    Rather, it's a SI_KIND='Overload' InfoObject instance, accessible using the BusinessObjects Enterprise SDK.
    Sincerely,
    Ted Ueda

  • How to find table name(s) in a dynamic query

    In one of our (9iAS PORTAL)applications, any user can able to run their query statment and get output. All queries will be executed as dynamic SQL thru' a common shema/user who has 'SELECT' privilege on all tables but all users don't have this privilege on all tables. Now, before executing any query I need to find out what are the table name(s) used in this query to check the privilege for the respective user. How do I extract all table names being used in a dynamic query?.
    Thanks
    -Krishnamurthy

    I guess that his users log in to application first, then application uses one account to log in to database, so application are not direct database user since all users share the same account to database. If so, when a user lgins in, you may write it down from application to a database audit table, and you need to write down the dynamic query to the database audit table too, then you may query that audit table to find out. up to here, it looks that your application has to do more to assign what role to a user running the application, since database does not know what user is assessing it.

  • Table name changed in Reports 3.0

    My DBA asked me to change the table name from SA_AWARDS to SAFETY_AWARDS.
    I had already developed a report using table name SA_AWARDS.
    When I change the table name in my report to SAFETY_AWARDS, I get compilation errors.
    How can I fix it ?
    Thanks.
    Suresh

    Hi
    As i understand your problem , you have changed the table name in the query wizard and then tried to compile and it is giving errors ....
    well anytime you modify the sql (even add a space) the column names are renamed ... ie if you originaly had column Customer_name it would be renamed as customer_name1 ....
    now if in the original report you are using the columns for any computation etc it will not find the old column and will give compilaiton errors .... one way is to change the column names back to original names ... or better modify the sql once more by adding space and you will get back the original names most of the times .....
    the best way to avoid this is give alias name in the sql first time around , so it dosnt create problems ....
    once you take care of this i think your problem should be solved .....
    if not do let me know in more detail
    bye
    sudhir

  • 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

  • Table Name-Changes in SO

    Dear All,
    As we all know that any changes done in Sales order, we can see them by going to Va02-->Environment -->Changes...
    According to our client's requirement, we need to generate a report which can show all the changes done to a SO. For this I want to know the TABLE name in which the changes that we have done to the SO are going to be stored.(Kindly let me know if there is any Standard Report exists in SAP R/3 for this kind of requirement)
    Points assured for Helpful answers
    Thanks & regards
    Krishna Chaitanya

    Hi,
    Please refer the following tables.
    Header : CDHDR
    Item: CDPOS
    Reward points
    Regards,
    Govind.

  • Handling table name changes

    Hi,
    Because of a change in naming convention, all our source table names are changing (only the prefix: The rest of the name and the table structures will remain the same). We already have developed a significant number of OWB mappings based on the old naming convention. What is the OWB equivalent of doing a global search replace of table names ? Is there a script available for doing this ?
    Thanks in advance.
    Regards,
    Biswa.

    The name changing part should be relatively simple to handle. I have included a script that should do the renaming with the prefix 'WH_'. The reconcile will have to be done by you. The script should go something like this (please test your scripts in a test environment as I will not provide support for this).
    Regards:
    Igor
    # Update the connection information here.
    # The connect string format is repository_user/repository_pwd@hostname:port:service_name
    # Connecting to the repository:
    OMBCONNECT owb/owb@localhost:1521:ora9201
    puts "Connected to repository."
    # Setting the project and prefix variables (set project name here):
    set MProject MY_PROJECT
    # Everything will be prefixed by WH_:
    set wh WH_
    #Open the project
    # Entering into the Project (CC = Changing Context):
    OMBCC '$MProject'
    set module_list [OMBLIST ORACLE_MODULES]
    # Loop to enter into each project module:
         foreach i in {$module_list}{
              puts "Working on module: $module_list ."
              OMBCC '$module_list'
              set table_list [OMBLIST TABLES]
    # Loop to prefix the name of each table in the current module:
                   foreach j in {$table_list}{
                        puts "     Working on table: $table_list ."
                        OMBALTER TABLE '$j'
                             RENAME TO '$wh$j'
    # Loop to prefix the name of each dimension in the current module:
              set dim_list [OMBLIST DIMENSION_TABLES]
                   foreach l in {$dim_list}{
                   puts "     Working on dimension: $dim_list ."
                        OMBALTER DIMENSION_TABLE '$l'
                             RENAME TO '$wh$l'
    # Loop to prefix the name of each cube in the current module:
              set cube_list [OMBLIST CUBE_TABLES]
                   foreach m in {$cube_list}{
                   puts "     Working on cube: $cube_list ."
                        OMBALTER CUBE_TABLE '$m'
                             RENAME TO '$wh$m'
    # Loop to prefix the name of each mapping in the current module:
              set mapping_list [OMBLIST MAPPINGS]
                   foreach k in {$mapping_list}{
                   puts "     Working on mapping: $mapping_list ."
    # Reconcile your mapping here by using OMBRECONCILE ...
    # this will have to be done by you...     
    puts "Done."
    # Saving the changes:
    OMBCOMMIT
    # Disconnecting from the repository:
    OMBDISCONNECT

  • How Discoverer Reports cope with table name changes

    I want to change the name of an oracle table that is queried by a number of Discoverer reports owned by various users.
    I have been told that Discoverer might have the smarts to handle this without manual intervention of users having to open their reports and repoint them to the new tablename. Would someone be able to enlighten me?

    Thanks Guys for help.
    Additionally I'd like to add for the purpose of the name change is business driven and therefore it is important that business (report writers) see the new name so.....
    For each simple folder in the EUL there are there 3 attributes you need to be aware of:
    (1) Folder Name (the name as seen in Discoverer)
    (2) Identifier
    (3) Physical Database Object name
    (1) and (2) are used by a Disco workbook to resolve back to the physical object name.
    Therefore, you can change either (1) or (2) [but not both] and still have the workbook resolving back to the physical object name on the folder (ie (3)).
    In summation, I changed (1) and (3) while leaving (2) unchanged to resolve the whole glorious mess....

  • Admin advice: table name changes, etc.

    Our Discoverer system is still evolving and there are instances when a change, say to a table name that users have build workbooks on, is required. Is there a way to scan the workbooks and make this change for the users?

    Hi
    No, this is not possible. You have to be extremely careful making changes to an EUL after workbooks exist. Mind you, just because you change a table name does not mean you need to change the folder name or identifier. You can change the table pointer without making any other changes, so long that is that the new table has the same data items and data types as the original. If it doesn't you could be in deep trouble.
    As a note, you do need to make sure that you correctly maintain both the folder name and the folder identifier and not allow these to take generic names and defaults such as NEWFOLDER1 etc. This is bad EUL design and you will end up with issues in the future.
    If you have a copy of my Oracle Discoverer 10g Handbook, available from good bookstores or amazon.com via http://learndiscoverer.com/books/books.htm, take a look at chapters 17 and 18 which describe in detail how to get going in and maintain business areas. In particular, pages 640 and 641 cover folder management and discuss the impact of changing names and / or identifiers.
    I hope this helps
    Best wishes
    Michael Armstrong-Smith
    URL: http://learndiscoverer.com
    Blog: http://learndiscoverer.blogspot.com

  • Urgent Help on Dynamic Table name change in query !!!!!!!!

    Hi Everyone,
    I'm having a repeating frame which displays table_name, count_validate and count_error. How can i dynamically change my table_name in formula column apllied on count_validate and count_error. I can do this with multiple elsif statement, which makes my report slow at runtime. Select statement is same , only change is table_name ?
    Kindly let me know......

    Try to use dynamic ref cursors (defined in a database package).
    This is not exactly what you need, but see:
    "Dynamic Table in the Second Query with Oracle Reports"
    http://www.quest-pipelines.com/pipelines/plsql/tips03.htm#JULY
    Regards,
    Zlatko Sirotic

  • Updated Table Name Changes Applescript Operation in Numbers 3.5

    I've been using Applescript in Numbers for some time to copy/paste data (set cell values) from one sheet table to another sheet table.
    My original script was heavily cribbed from something Yvan Koenig had posted 2-3 years ago.
    I recently updated to Yosemite and Numbers 3.5 after testing to ensure my original script remained functional (and it did).
    I subsequently updated my source data table by duplicating my old table and editing this new source.
    I then updated my Applescript to to reference the new source table.
    Testing yielded a good functional result, but Numbers changed its behavior by displaying its work while setting values in the target sheet table.
    This obviously slows the script down and adds measurable processing time given the amount of data being moved.
    Does anyone know how I can prevent this behavior from occurring?
    I don't believe I changed anything material in my original script so I'm really not sure why Numbers changed its behavior.
    I have included my script below.  Thanks very much for any help!
    property the_goods : {}
    property patient_name : {}
    property patient_count : {}
    property run_date : {}
    on run
      set sheet_source to "1500 EXPORT"
      set table_source to "OA Data"
      set column_source to 1
      set row_source to 2
      set sheet_destination to "CLEARING HOUSE EXPORT"
      set table_destination to "Export Table"
      set column_destination to 1
      set nb_rows to 0
      set nb_columns to 244
      set patient_sheet to "SESSION DB"
      set patient_source to "User Input Table"
      set patient_tracker to "Tracking Table"
      set source_column to 3
      set source_row to 2
      set destination_column to 2
      set date_column to 3
      set patient_count_column to 3
      set patient_count_row to 3
      set run_date_row to 5
      tell application "Numbers"
      set document_source to name of front document as string
      set document_destination to name of front document as string
      end tell
      tell application "Numbers"
      tell document document_source to tell sheet patient_sheet to tell table patient_source
      set patient_count to value of cell patient_count_column of row patient_count_row
      set run_date to value of cell patient_count_column of row run_date_row
      end tell
      end tell
      set row_destination to patient_count
      tell application "Numbers"
      tell document document_source to tell sheet sheet_source to tell table table_source
      set the_goods to value of cells column_source thru (column_source + nb_columns) of rows row_source thru (row_source + nb_rows)
      end tell
      tell document document_destination to tell sheet sheet_destination to tell table table_destination
      set r to 0
      repeat with one_row in the_goods
      tell row (row_destination + r)
      set c to 0
      repeat with one_value in one_row
      set value of cell (column_destination + c - 0) to one_value
      set c to c + 1
      end repeat
      end tell
      set r to r + 1
      end repeat
      end tell
      tell document document_destination to tell sheet patient_sheet to tell table patient_source
      activate
      end tell
      tell document document_destination to tell sheet patient_sheet to tell table patient_source
      set patient_name to value of cell source_column of row source_row
      end tell
      tell document document_destination to tell sheet patient_sheet to tell table patient_tracker
      set value of cell destination_column of row row_destination to patient_name
      set value of cell date_column of row row_destination to run_date
      end tell
      end tell
      set the_goods to {}
      set patient_name to {}
      set patient_count to {}
      set run_date to {}
    end run

    Here is a simple example that copies values from a source row 3 in Table 1 to a target row 5 in Table 2.
    On my aging MBA it was very fast (about a second) with 150 columns.
    In addition to speed, an advantage of this approach is that you don't have to code table dimensions;  the target table will expand automatically if needed.
    Save the script in a script folder (in my case ~/Library/Scripts/Applications/Numbers) and run it from there by choosing it from the script menu. (Running it from Script Editor will paste the values into Script Editor instead of into Numbers as you want).
    If keeping the original number format is important, substitute 'formatted value'  for 'value' in the script.
    SG
    property src : {d:1, s:"Sheet 1", t:"Table 1", r:3}
    property tgt : {d:1, s:1, t:"Table 2", r:5}
    tell application "Numbers"
      tell document (src's d)
      tell sheet (src's s)
      tell table (src's t)
      tell row (src's r)
      set vv to cells's value -- makes AppleScript list
      set the clipboard to my makeTSV(vv)
      end tell
      end tell
      end tell
      end tell
      tell document (tgt's d)
      tell sheet (tgt's s)
      tell table (tgt's t)
      set the selection range to row (tgt's r)'s cell 1
      tell application "Numbers" to activate
      tell application "System Events" to keystroke "v" using {option down, shift down, command down}
      end tell
      end tell
      end tell
    end tell
    to makeTSV(aLst) -- turns AppleScript list into tab-delimited string
      set oTID to AppleScript's text item delimiters
      set AppleScript's text item delimiters to tab
      set tsvStr to aLst as text
      set AppleScript's text item delimiters to oTID
      return tsvStr
    end makeTSV

Maybe you are looking for

  • Should Firefox 3.6.16 run properly on a Mac OSX 10.4.11?

    I use Yahoo, and I get the impression that they don't work together as well as they used to. Sometimes I lose a link or it's slow loading, and some times it's just plain slow. I'm about ready to switch to Safari. I have little knowledge of Java, plug

  • Creating 1080p Blu-Ray with Final Cut Pro 10.0.7?

    The latest version of Final Cut Pro (Vers 10.0.7) seems to share to Blu-Ray disk only at 720p resolution (1280X720) - not 1080P (1920X1200).  I know you can always use Compressor to create a 1080p Blu-Ray, but is there any way to create a 1080p Blu-R

  • Firefox 4 mobile was updated and now it doesn't open.

    It looks like FF 4.0 Mobile received an update and then hung. I restarted my Xoom and tried to startup FF. It hung again at the FF logo. There were no errors. I could not stop the process. FF was unusable and I needed to unistall it. I'm hesitant to

  • Fact table contains how many no. of Dim. ids and Key figures?

    Fact table contains how many no. of Dim. ids and Key figures?

  • Album previews: heads cut off...

    Is there any way to avoid heads etc. (all upright format pix) to be cut off in the (landscape format) album previews? This looks awful, especially if it's the first photo. Thanks a lot! Peter