Using variables such as table names. Ideas for alternative designs

Hello

I am the design of an application that uses synonyms to pull information from the 'client' DBs via links from DB. Synonyms are created with a DB_ID in name (example: CUSTOMER_100, CUSTOMER_200... where the 100 and 200 are DB IDs of 2 separate DBs customer.)

I have a procedure that selects data in the synonym based on what DB_ID is passed to the procedure. I want to be able to perform this procedure for any entered DB_ID. I know now I can't use variable for the table names names and using EXECUTE IMMEDIATE does not seem suitable for what I'm trying to do.

Does anyone have suggestions or re-design options, I could use to achieve this generic procedure which will select a certain synonym based on the information of DB input parameters? Thank you.

CREATE or REPLACE PROCEDURE CUSTOMER_TEST (p_host IN VARCHAR2, p_db_name IN VARCHAR2, p_schema in VARCHAR)

IS

v_hostname VARCHAR2 (50): = UPPER (p_host);

v_instance VARCHAR2 (50): = UPPER (p_db_name);

v_schema VARCHAR2 (50): = UPPER (p_schema);

v_db_id NUMBER;

v_synonym VARCHAR2 (50);

CURSOR insert_customer

IS

SELECT

c.customer_fname,

c.customer_lname

OF v_synonym_name c;

BEGIN

-MADE BASED ON INPUT PARAMETERS DB_ID

Select d.db_id

in v_db_id

of t_mv_db_accounts ac.

t_mv_db_instances I,.

t_mv_dbs d,

t_mv_hosts h

where ac.db_ID = d.db_ID

and i.db_ID = d.db_ID

and i.HOST_ID = h.host_id

and upper (H.HOST_NAME) = v_hostname

and upper (D.DB_NAME) = v_instance

and upper (Ac.ACCOUNT_NAME) = v_schema;

-ADD DB_ID TO NAME SYNOYNM

v_synonym: = 'CUSTOMER_ | v_db_id;

FOR cust_rec IN insert_customer

LOOP

INSERT INTO CUSTOMER_RESULTS (First_Name, Last_Name)

VALUES (cust_rec.customer_fname, cust_rec.customer_lname);

END LOOP;

COMMIT;

END;

/

RGS,

Rob

EXECUTE IMMEDIATE ' INSERT IN CUSTOMER_RESULTS (First_Name, Last_Name) SELECT customer_fname, customer_lname FROM ' | v_synonym;

Tags: Database

Similar Questions

  • How to use a value in a variable as a table name in a query?

    I fetch a value in a variable like:

    < select application_short_name in the fnd_application l_appl_nm where application_id =: p_appl_id >

    Now, I need to use the value retrieved in the variable "l_appl_nm" as a name of partition table in the following query.

    Anyone can guide me please on this concept.

    Expected answers as soon as possible!

    Create dynamic SQL statements with your variable, and then run this SQL with the "EXECUTE IMMEDIATE" command.

    Thank you

    Lokesh

  • Table names are stored in a separate table; How can I use the domain as table name?

    Dear Experts,

    My version of oracle is,

    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production

    PL/SQL Release 9.2.0.1.0 - Production

    CORE 9.2.0.1.0-Production

    AMT for 32-bit Windows: Version 9.2.0.1.0 - Production

    NLSRTL Version 9.2.0.1.0 - Production

    I stored the table names in a separate table as

    Table name: all_table

    Fields are: table_id, table_name, desc

    record of the sample: 1, EMP, EMPLOYMENT DETAILS

    Now I want to select all the contents of a perticular table, his name is all_table.

    (ie)

    Select * from (select table_name from all_table where table_id = 1);

    But it is not listing the details of the EMP table.  Its poster simply the name of the field "EMP".

    Please help me in this regard.

    Hello

    Whenever you make dynamic SQL statements, you must place the dynamic whole statement in a single string variable.  When debugging, display this string before running it.  If you get a runtime error that will show you the statement he makes, which often made the obvious cause.  For example:

    DECLARE

    CURSOR c IS

    SELECT table_name

    From user_tables;

    CNT NUMBER;

    sql_txt VARCHAR2 (1000);

    BEGIN

    FOR ut IN t

    LOOP

    sql_txt: = 'SELECT COUNT (*).

    || « DE » ' || t.table_name | '"';

    dbms_output.put_line (sql_txt |) "= sql_txt"); -For debugging

    EXECUTE IMMEDIATE sql_txt INTO cnt;

    dbms_output.put_line (' Table: ')

    || t.table_name

    || ' ('

    || CNT

    || "lines)"

    );

    END LOOP;

    END;

    /

    You can comment the put_line extra call when you are convinced that sylvie statement works.

    If you have non-standard table names (for example, names that contain spaces) you must place the names of the tables in double - quotes, as I did above.

  • attachMovie using variable target and source names

    I have frequently used the names of variables for the target, but is it not possible to do this:

    holder.attachMovie (["mcButton" + i], ['zone' + i + '_btn'], this.getNextHighestDepth () * 200, {_x: arrBtnX [i], FLF: arrBtnY [i]});

    I can't make it work and I was not able to find an example.  It does work without the square brackets either.

    Thank you

    Marion

    If trace (btnHldr ["box" + i + "_btn"] ._x) is set during each loop, btnHldr ['box' + i + '_btn'] exists, at least, in each loop.

    the fact that you don't see all the btnHldr ['box' + i + "_btn"], means either:

    1. they are not visible for a variety of reasons or,

    2. you're crushing your depths and movieclips previously created are deleted.

    to debug, use:

    trace (btnHldr ["box" + i + "_btn"] .getDepth ())

    in your loop for to see what you're doing.

  • How to set a variable in a table to grid 'for' loop

    I'm afraid I'm stuck again!

    The next step in the animation I'm working on, is to set up a Boolean value, 'pierced = false', so that all instances of the attachMovie ("openCircle") have a Boolean "drilled = false' associated with them." Then when someone clicks on one of the instances of the attachMovie ("openCircle"), the Boolean value becomes "pierced = true', but only for that instance was clicked."

    What I've done is to set the (Boolean) variable (highlighted in bold below) in the two 'for' loops through the table in the grid, but it returns an undefined value. Do I need to configure a separate table? (see code below):-

    set up the grid for solid table

    spacing: var number = 5.75;

    Var CDL: number = 20; the number of columns in the grid

    var rows: number = 20; number of grid lines

    var leftMargin:Number = 154;

    var topMargin:Number = 169;

    depth: var number = 100; starting point for the depth

    var drilled: Boolean;

    for (i = 1; I < = lines; i ++) {}

    for (j = 1; j < = cols; j ++) {}

    drilled [rows, cols] = false;

    trace (drilled);

    current = attachMovie ("openCircle_mc", "openCircle_mc" + i + "_" + j, depth ++);

    Current._x = leftMargin + ((i-1) * (spacing + current._width));

    Current._y = topMargin + ((j-1) * (spacing + current._height));

    Current.Row = i;

    Current.Col = j;

    Current.Oil = Math.floor (Math.random () * 1.1);  about 1/10 objects have oil = 1, 9/10 oil = 0

    Open the circle initially invisible, visible on rollover

    Current._alpha = 0;

    {current.onRelease = function ()}

    trace (this.row + "" + this.col);

    current.drilled = true;

    }

    current.onRollOver = function() {}

    This ._alpha = 100;

    }

    current.onRollOut = function() {}

    This ._alpha = 0;

    }

    }

    }

    I would be grateful for any help. Thank you.

    Then, create a two dimension table named drilled so that it exists when you try to fill...

    var drilled: Array = new Array (new Array();

    There might be a problem that you're missing setting the values of the [0, #] components of the table - paintings begin with an index of 0.

  • Still no radio buttons or checkboxes in the new form widget? Good ideas for alternatives?

    Hey everybody,

    I just found out that there is still no can add radio buttons very basic or checkboxes using the form of Muse-widget! Without these features, the form widget has no use for me is it possible to include these characteristics with some other vendors?

    I am really disappointed that the new version does not have these features, because they are so simple and really necessary for good form-widget!

    Please please please add in the next update - other features such as the calendar and the time fields are also required to make the current widget form is becoming an tool full!

    See you soon!

    An update was released today which includes radio and checkbox button groups.

    Please update to the latest version.

    Thank you

    Sanjit

  • Creating a table of Storyboard for web design

    I was wondering, what is the best program of adobe to create a table of Storyboard (wired) for planning of web design?

    Take a look at Adobe experience design CC

    It is available for Mac only now.

    User experience, prototyping app | CC Adobe experience design

  • ideas for web design?

    How everyone becomes with the design of web sites?-personally, I think it's great, so simple, but nevertheless, I would like to hear from anyone who has ideas on improving my skills?

    very well, I have so many skills that I could spend on phone you me until a certain time, you should have my number

  • Variables in the table of contents, glossary and Index

    RoboHelp can use variables in the table of contents, glossary and Index.
    My project needs variables both in terms and definitions (glossary and Index).

    Hi OLH

    That is right. But who knows what will happen in the next version. Currently you can use conditional tags for the table of contents and Index, but not of variables. From a development perspective, there are a lot of problems with the help of the variables of table of contents, glossary and Index, it is not as simple as adding variables to the content of the main .htm file. But it would be a great improvement for the next version.

    Don't forget to submit an enhancement request and play your part by Adobe to aware of these issues.

    http://www.Adobe.com/cfusion/mmForm/index.cfm?name=wishform

    Kind regards
    Craig

  • using the function - how to use the values of the input variables on the table select statement names

    Hello community, I have a problem when creating a function. The purpose of this function is to check the table of weather gave yesterday or not. We must check this on different tables on different sachems. We are creating a function with input variables.

    CREATE OR REPLACE FUNCTION IN_SCHEMA.IS_YDAYDATA_TO_TABLE

    (

    in_schema IN VARCHAR2,

    in_tablename IN VARCHAR2,

    in_datefield IN VARCHAR2,

    )

    RETURNS INTEGER

    AS

    -Declaring variables

    v_is_true INTEGER.

    BEGIN

    SELECT

    CASE

    WHEN MAX (in_datefield) = TRUNC(SYSDATE-1)

    THEN 1

    ON THE OTHER

    0

    END

    IN

    v_is_true

    Of

    in_schema.in_tablename

    ;

    RETURN v_is_true;

    END;

    /

    When creating, I got error: [error] ORA-00942 (44:19): PL/SQL: ORA-00942: table or view does not exist

    How to use the values of the input variables on the table select statement names?

    Hello

    Here's a way you can use dynamic SQL statements for this task:

    CREATE OR REPLACE FUNCTION IS_YDAYDATA_TO_TABLE

    (

    in_schema IN VARCHAR2,

    in_tablename IN VARCHAR2,

    in_datefield IN VARCHAR2,

    in_first_date DATE DEFAULT SYSDATE - 1,.

    in_last_date DATE by DEFAULT NULL

    )

    RETURNS INTEGER

    AS

    -IS_YDAYDATA_TO_TABLE returns 1 if in_schema.in_tablename.in_datefield

    -contains all the dates in the in_first_date of the range through included in_last_date

    - and it returns 0 if there is no such lines.

    -If in_last_date is omitted, the search only the data on in_first_date.

    -If in_first_date is omitted, it defaults to yesterday.

    -Time parts of the in_first_date and in_last_date are ignored.

    -Declaring variables

    sql_txt VARCHAR2 (1000);

    v_is_true INTEGER.

    BEGIN

    sql_txt: = 'SELECT COUNT (*).

    || 'FROM ' | in_schema | '.' || in_tablename

    || 'WHERE ' | in_datefield | ' > =: d1'

    || «AND» | in_datefield | '< >

    || 'AND ROWNUM = 1';

    dbms_output.put_line (sql_txt |) '= sql_txt in IS_YDAYDATA_TO_TABLE");  -For debugging

    Sql_txt EXECUTE IMMEDIATE

    IN v_is_true

    With the HELP of TRUNC (in_first_date) - d1

    TRUNC (NVL (in_last_date

    in_first_date

    )

    ) + 1                -- d2

    ;

    RETURN v_is_true;

    END is_ydaydata_to_table;

    /

    DISPLAY ERRORS

    If you must use dynamic SQL statements, put all the SQL statement in a single string variable, such as sql_txt in the example above.  In this way, you can easily see exactly what will be executed.  Comment out the call to dbms_output under test is completed.

    Try to write functions that will address not only the question that you have now, but similar questions that you may have in the future.  For example, now that interest you only to the verification of the data of yesterday, but later, you might want to check another day or range of days.  The above function combines the convenience of a function simple (looks like yesterday data if you don't tell him otherwise) with the power of a more complex function (you can use the same function to check any day or range of days).

  • using the variable as a field name in a query

    Oracle 10G


    Hi all

    I have a table like:

    TEST_MSL
    CID NUMBER (10),
    TEST_1 VARCHAR2,
    TEST_2 VARCHAR2

    Now, I want to use a procedure such as:

    create or replace procedure TEST
    (VARIABLE_1 IN VARCHAR2) Possible values (TEST_1, TEST_2)
    as
    BEGIN

    declare
    cursor c1 is
    Select the CID
    where VARIABLE_1 = 'BLAH '.

    My problem is:

    How can I use this variable as a domain name?

    Kind regards

    Menk Slot

    Published by: Menk slot on June 3, 2010 10:46

    If you know that there are only two possibilities so preferable to use as static SQL statements

    procedure test(v_cloumn_name varchar2) IS
    IF v_column_name='TEST_1' THEN
    SELECT CID INTO var where TEST_1='BLABLA';
    ELSE
    SELECT CID INTO var where TEST_2='BLABLA';
    END;
    

    Otherwise, use Ref cursour as

    declare
    v_sql_stm varchar2(200);
    refcur sys_refcursor;
    begin
    v_sql_stm:='SELECT CID FROM TEST_MSL WHERE '||v_cloumn_name||' = ''BLABLA''';
    open refcur for v_sql_stm;
    
  • Variably to change a 2D table name

    Hello world

    So I have this VI I had created and someone here helped it vamp big time. Thanks again for this. I ran into a snag with my program. So I have this VI that takes in the tables and places them in an xml file. I use teststand to control a SigGen, PowerMeter and matrix switching, so I can take a lot of measures of the table and place them in a singke XML. My problem is that my (once the test is completed) xml file will have on the tables of 200 or more in it. So I was hoping I could do the name of the 2D array in a variable so that I can do every single table in my xml file. This way I can possibly create an another VI that takes the xml file and view the desired table. Did someone knows how the name of the 2D array in a variable, so I can change it to what I want of teststand? My VI is attached below.

    Thank you

    dlovell

    I didn't actually test the version previously displayed.

    I think that my entry to the search function are not good.

    The line break seems to be screwing.

    Try to use

    Table 2D

    for the search string

    and

    %s\n

    as the analysis based on the string.

    I test a subset of this and it worked for me.

  • How to use the global variable in the table target?

    Hello

    I am trying to load several files into a single interface. the data is loaded successfully. 92. the files are there. for this I used variables and package.

    My requrement is 92 files of data loaded into the target table. I want to know what data from file.

    to this I added a column (filename) to the existing target table.

    If I used joints (not same condition), its totally wrong. all file names are coming.

    Please see the following screenshots.

    err27.jpg

    exit; target table.

    err26.jpg

    in fact in the target table. first 10 lines are coming from file.i.e first _ACCOUNT_LIMIT_511.TXT. but all the files names are coming.

    I'm confuse. After the first data file inserted then insert second data file. in that all file names are coming. Please help me.

    I thought that the global variable is preferable to identify the data came from which file.

    to do this, the global variable is used in the target table. I don't always have my exit.

    Please help me.

    Thanks in advance.

    err25.jpg

    Hello

    You can use the same way, how you use the project variable, just you have to do a thin is #GLOBAL.variable_name for example: #GLOBAL. SMART_AL_FILE_NAME_S

    Note: Make sure you that while you use one variable overall in interface, indicator should be staged as you chose above the screen

    hope this helps you

    Kind regards

    Phanikanth

  • Use of the staging of prepareBulk table name parameter / completeBulk functions.

    I try to load 1.6 billion triple in a semantic graph RDF instance. I use the prepareBulk / completeBulk approach described in "7.12 Bulk loading Using RDF graphic semantic support for Apache Jena. I loaded the triplets of. TTL.gz files in an intermediate table with prepareBulk according to the "example 7-10 loading data into the staging (prepareBulk) Table.

    Example 7-10, I used "null" for the parameter "staged by the name of the table" at prepareBulk. I then ran a separate program to run completeBulk according to the "example 7-11 loading data into the table of staging in semantic networks (completeBulk). 7-11 watch also the use of "null" as default value for the parameter "staged by the name of the table. PrepareBulk operations seem to have executed successfully with a null value, staging table name. However, null does not seem to be a valid entry for the staging of completeBulktable name parameter. "CompleteBulk (null, null);" run displays the following error message:

    Hit the exception ORA-00942: table or view does not exist

    What is the relationship between "staged by the name of the table" Settings prepareBulk and completeBulk? Is null, a valid value for this parameter to prepareBulk, and if so what should be the corresponding value passed to completeBulk?

    Hello

    This seems odd. We have a test for this case. We will try this. By default, the intermediate table created is under the same user schema and table name would be "RDFB_" followed by the name of model.

    Can you please verify the existence of such a table in your schema? There must be 1 b + lines. If so, you can directly proceed to the name of the table.

    Since you are dealing with a good amount of data, the following should be helpful for performance:

    (1) remove the indexes on the table of the application before you run the completeBulk call;
    2) enable parallel DML before the call: oracle.executeSQL ("alter session enable dml parallel");

    (3) use the parallel load options. An example is the following. Degree of parallelism is set to 4, and you will need to customize it to your own configuration.

    "PARSE PARALLEL PARALLEL_CREATE_INDEX = 4 mbv_method = shadow"

    Thank you

    Zhe Wu

  • I am trying to add images such as tables, podium, stage, cake table, to a floor plan for a wedding?  Can offer you some advice?

    I am trying to add images such as tables, podium, stage, cake table, to a floor plan for a wedding?  Can offer you some advice?

    Absolutely, do not start with a PDF file. It is quite unsuitable for this type of installation. Use a graphical tool, preferably one designed for floor plans.

Maybe you are looking for