How to use a table name in the select statement using a variable?

Hi Everybody,
                   I got a internal table which has a field or a variable that gets me some tables names. Now I need to retrieve the data from all these tables in that field dynamically at runtime. So could you suggest me a way out to use the select query which uses this variable as a table ?
Regards,
Mallik.

Hi all,
Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?
for ex : select * from (tab_name) where....?
Can we do inner join on such select statements? If so how?
Thanks & Regards,
Mallik.

Similar Messages

  • How can i pass a variable instead of a table name in the Select statement.

    Dear all
    how can i pass a variable instead of a table name in a select statement ?
    Example :-
    Begin
    P_get_procedure_tname (aap_name,otable_name);--It will take an application name and will return a table name
    Select col1 into ocol1
    from  ---- here i want to pass the variable OTABLE_NAME
    End;How can i pass this ?

    Hi,
    You can use dynamic sql.
    EXECUTE IMMEDIATE 'SELECT COL1 INTO ' || OCOL1 || ' FROM " || OTABLE_NAME;
    {code}
    cheers
    VT                                                                                                                                                                                                                                                                                                   

  • * table name in the select statements

    Hi,
      I have come across a select Statement as below.
    Select * into *nast from nast where <conditions>.. End select.
    what does this *nast represents and when is it used. why do we need to call a Table  with *<Table Name>
    Kind Regards,
    Usha

    hi,
    select statement will always points to a database table so we have to give database table name and it gets data from that table. for storing that data we have to use internal tables must have same structure of database table.
    so select statement has the following form as........
    select * from [dbtable] into table [internal table]
    endselect.
    in sap select will act as a loop so that we hav to use end sleect. select has different varities in sap. for some types no need of end select.
    for ex:
    select single *
    select * ..................... into table [internal table name].....
    if helpful reward some points.
    with regards,
    suresh.

  • Create Dynamic table name in the select statement.

    I use oracle reports 6i to make myrep.rdf , this report created using certain select query Q1, I created a formula column in this report,
    in the formula column  I write pl/sql block statements to select the data from certain table depends on the output of a column in Q1,
    I want to make the pl/sql block dynamically enough to change the user which I select the data from depends on the connected user
    Ex: if I connected with user = 'KAM14'
    the pl/sql block will be
    select x into v_value from kam13.bil_file where .....;
    and if  I connected with user = 'KAM13'
    the pl/sql block will be
    select x into v_value from kam12.bil_file where .....;
    and so on
    how can I do this in the pl/sql block ...
    Thanks in Advance.

    I am not sure I understood properly, but I think you should create bil_file table under a different user and create synonyms  under KAM1x users.
    Regards

  • How to use Oracle Table Type values in Select Statement.

    Hi,
    I am fetching initial set of values into Oracle Table of Records Type and want to use list of values in the Select statement.
    For example, try something like the following:
    TYPE t_record IS RECORD (
    ID TABLEA.ID%type,
    NO TABLEA.NO%type,
    v_record t_record;
    TYPE t_table IS TABLE OF v_record%TYPE;
    v_table t_table;
    -- Code to populate the values in v_table here.
    SELEC ID,NO, BULK COLLECT INTO <some other table variabes here> FROM TABLEA
    WHERE ID IN v_table(i).ID;
    I want to know how to use the values from Oracle Table Type in the Select Statement.

    Something like this:
    create or replace type t_record as  object (
    id number,
    no number
    CREATE or replace type t_table AS TABLE OF t_record;
    set serveroutput on
    declare
      v_table t_table := t_table();
      v_t1 t_table := t_table();
    begin
      v_table.extend(1);
      v_table(1).ID := 1;
      v_table(1).No := 10;
      v_table.extend(1);
      v_table(2).ID := 2;
      v_table(2).ID := 20;
      SELEC t_record (ID,NO) BULK COLLECT INTO v_t1
      from TableA
      FROM TABLEA
      WHERE ID IN (select t.ID from table(v_Table) t);
      for i in 1..v_t1.count loop
        dbms_output.put_line(v_t1(i).ID);
        dbms_output.put_line(v_t1(i).No);
      end loop;
    end;
    /Untested!
    P;
    Edited by: bluefrog on Mar 5, 2010 5:08 PM

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

  • Using dymanic table name for running select queries

    Hi there. Currently got a problem with performing the following task:
         Perform fulltext search on all tables that have created fulltext indexes in specific schema. Result should look like this:
              <TABLE_NAME1>                <ID_FROM_TABLE>
              <TABLE_NAME1>                <ID_FROM_TABLE>
              <TABLE_NAME2>                <ID_FROM_TABLE>
              <TABLE_NAME2>                <ID_FROM_TABLE>
         At the moment all tables have the same ID column UOI_ID.
    What I've tried so far is the following:
    PROCEDURE "tuser"."dam.test.db.procedures::textSearch" ( in keyword NVARCHAR(300), out search_results "tuser"."dam.test.db::tuser.procedures.tt_search_results" )
      LANGUAGE SQLSCRIPT
      SQL SECURITY INVOKER
      DEFAULT SCHEMA "tuser"
      AS
    BEGIN
      Write your procedure logic
      DECLARE counter Integer := 1;
      DECLARE row_count Integer;
      DECLARE table_name NVARCHAR(300);
      DECLARE schema_name NVARCHAR(300) := 'tuser';
      indexed_tables = SELECT row_number() OVER (ORDER BY "TABLE_NAME") AS ROW_NUMBER, "TABLE_NAME"
           FROM (
                SELECT DISTINCT "TABLE_NAME"
                     FROM "SYS"."FULLTEXT_INDEXES"
                          WHERE "SCHEMA_NAME" = :schema_name
      SELECT COUNT(*) INTO row_count FROM :indexed_tables;
      WHILE counter < row_count + 1 DO
           SELECT '"tuser"."'||"TABLE_NAME"||'"' INTO table_name FROM :indexed_tables WHERE "ROW_NUMBER" = :counter;
           temporary_results = SELECT :table_name AS TABLE_NAME, "OUI_ID" AS ID
                FROM :table_name
                     WHERE contains(*, :keyword, fuzzy(0.5));
           search_results = CE_UNION_ALL(:search_results, :temporary_results);
           counter := counter + 1;
      END WHILE;
    END;
    At this point it's impossible to perform the:
    ... FROM :table_name ...
    The error is:
    Could not create catalog object: scalar type is not allowed
    Tried doing it with CE functions.
    temporary_table = CE_COLUMN_TABLE(table_name);
    The error is:
    Dependent object not found: SqlScript; tuser.TABLE_NAME
    So the question is: How to dynamically put table name into "FROM ..." statement?

    Hello. Thx for response.
    I have tried something like
    exec 'INSERT INTO "tuser"."dam.test.db::tuser.procedures.search_result" SELECT '''||table_name||''' AS TABLE_NAME, '||column_name||' AS ID, SCORE() AS SCORE  FROM '||table_name||' WHERE contains(*, '''||keyword||''', fuzzy(0.5))';
    but here i have "tuser"."dam.test.db::tuser.procedures.search_result" created before the execution. What i really want is to make it as a local variable. Something like:
    DECLARE schema_name NVARCHAR(300) := 'tuser';
    indexed_tables = SELECT DISTINCT "TABLE_NAME" FROM "SYS"."FULLTEXT_INDEXES" WHERE "SCHEMA_NAME" = :schema_name ;
    but i can not transform the top 'exec ...' statement into 'result = SELECT ...' because it always says that it can not pass the scalar value into the 'FROM ...' part.

  • Run time Column Name in the Select Statement

    Hi there,
    I face problem while writing sql statment for report in the Oracle reports.
    The prom is I want to bound the where clause column name with the value stored in a variable e.g.
    Select * from emp
    where Column_Name = 'XYZ' ;
    where the variable Column_Name have different values at different times, e.g.
    At a time the value of Column_Name is Dept then
    Select * from emp
    where Dept = 'XYZ' ;
    At other time value of Column_Name is City then
    Select * from emp
    where City = 'XYZ' ;
    Waiting for the response .
    Regards,
    Hafeez

    Hi,
    U can use lexical parameters for the solutions.U must be aware of it, but still i describe how to work it out.
    1)In your datamodel in object navigator create a parameter under User parameter node.Name the parameter, for eg. p_clause.
    set data type of parameter to character.
    2)write a select query eg.
    select * from emp &p_clause; --(THIS IS THE PARAMETER WE CREATED ABOVE)
    3)Now run your report
    Now in your parameter form pass the value for p_clause parameter.
    eg: where name='JACK';
    or
    where city='NEWYORK';
    or where deptno=10;
    But do it in steps as above mentioned.
    Do tell me if it works or not via mail on [email protected]
    Enjoy.......
    navneet jain
    [email protected]

  • How to find out table name for the field in the webUI

    Hi.
    I am in CRM2007.
    So i go to the transaction code    BSP_WD_CMPWB
    In that i provide the component name as CRM_UI_FRAME.
    I press the Test button.
    So, it opend the WebUI.
    I want how to find out table of the particular input field?
    I mean from which table the data is retrived how to find out?
    When i enter some thing in the input field how to find out in which table that data is stored?
    By pressing F2 on the input field it opend View and Component Name.
    I want find out table of that particular field. How to find it?
    If anybody know about this explain it with Screen shorts if possible.
    Thank You.
    Krishna. B.

    hi
    goto tx genil_model_browser. Suppose you want to find fields reated to your order header eg sold to name. In component set write all and press F8. Then goto access object and in access object click on node BTAdminH. Click on attribute structure. Here you will find structure and attributes. If you click relationship then you will see all the relationship wrt btadminh. open any r/s that you require. and click on other object and attribute. You will get to know the structure.
    Best regards
    Pankaj kumar

  • How to display a table name in the report

    Hi,
    I have a requirment about the display of pivot table. When we drag a column to see its result, we always see his column name, now what I want to show are both table name and column name..
    like:
    District_D
    Region District
    China Beijing
    India Chennai
    Regards,
    Anne
    Edited by: anne on Oct 25, 2011 2:39 AM

    Hi Anne,
    If you want to implement Dpka's solution (hardcoding table and column values in column heading and add line break in between), you will need to add the below entry in instanceconfig.xml file. Refer http://gerardnico.com/wiki/dat/obiee/hardenxss
    <HardenXSS>false</HardenXSS>
    This will enable the HTML elements to be treated as HTML and not plain text. After adding the above entry in the xml, restart your presentation services and test your solution.
    Thanks

  • Passing of internal table values to the select statement as SETS

    Hi All,
    Is there any way that i can restrict the values of a internal table to be passed to a select statement set by set..
    say for eg: if a itab has 1000 entries i want the first 500 to be going out in a select statement as a comparision for all entries and then the next set of 500 to go out..
    Please let me know.. this is very urgent..

    <b>Appending Several Lines</b>
    You can also append internal tables to index tables using the following statement:
    APPEND LINES OF <itab1> TO <itab2>.
    This statement appends the whole of ITAB1 to ITAB2. ITAB1 can be any type of table, but its line type must be convertible into the line type of ITAB2.
    When you append an index table to another index table, you can specify the lines to be appended as follows:
    APPEND LINES OF <itab1> [FROM <n1>] [TO <n 2>] TO <itab2>.
    <n 1 > and <n 2 > specify the indexes of the first and last lines of ITAB1 that you want to append to ITAB2.
    This method of appending lines of one table to another is about 3 to 4 times faster than appending them line by line in a loop. After the APPEND statement, the system field SY-TABIX contains the index of the last line appended. When you append several lines to a sorted table, you  must respect the unique key (if defined), and not violate the sort order. Otherwise, a runtime error will occur.
    Then u can use <b> FOR ALL ENTRIES</b> in select query.
    regards
    vinod

  • How to print .sql file name in the same file using sqlplus

    Oracle 10g on Linux platform.
    I am trying to print the name of .sql script file in that file but could not. Following is the file:
    test.sql
    select '&0' from dual;But instead of printing, it is asking for input:
    SQL> @test.sql
    Enter value for 0: Can any body give me a hint as how can i print the file name.

    Use this
    SELECT FNAME_KRBMSFT AS name FROM X$KRBMSFT
    and see
    SQL> create or replace procedure get_dir_list
    2 (p_directory varchar2)
    3 is
    4 l_null varchar2(100);
    5 l_directory varchar2(100);
    6 BEGIN
    7 l_directory := p_directory;
    8 sys.dbms_backup_restore.searchfiles(l_directory, l_null);
    9 FOR x IN (select fname_krbmsft fname from x$krbmsft) LOOP
    10 dbms_output.put_line(x.fname);
    11 END LOOP;
    12
    13 END;
    14 /
    Edited by: HuaMin Chen on Jun 26, 2012 12:26 PM

  • How to know the select stmt used in creating a table?

    Hi,
    If we create a table by selecting some records form another table, can we see the select statement used to create that table.
    example: Create table emp2 as select * from emp where deptno=20;
    is there any data dictionary table which stores select * from emp where deptno=20
    Thanks in advance.
    Edited by: 805791 on Jul 28, 2012 9:01 PM

    No. The SELECT statement is not associated with the table in the data dictionary.
    If the statement was executed recently, you may find the entire CREATE TABLE in the V$SQL view. Or, if you have licensed the AWR, you may find it in the DBA_HIST_SQLTEXT view. But there is no guarantee that the query will be in either view.
    Justin
    Edited by: Justin Cave on Jul 29, 2012 3:46 AM
    Additionally, this question doesn't appear to relate to the Oracle Call Interface so it should probably have been asked in a different forum. The General Questions forum or the SQL and PL/SQL forum would have been more appropriate.

  • How to pull only column names from a SELECT query without running it

    How to pull only column names from a SELECT statement without executing it? It seems there is getMetaData() in Java to pull the column names while sql is being prepared and before it gets executed. I need to get the columns whether we run the sql or not.

    Maybe something like this is what you are looking for or at least will give you some ideas.
            public static DataSet MaterializeDataSet(string _connectionString, string _sqlSelect, bool _returnProviderSpecificTypes, bool _includeSchema, bool _fillTable)
                DataSet ds = null;
                using (OracleConnection _oraconn = new OracleConnection(_connectionString))
                    try
                        _oraconn.Open();
                        using (OracleCommand cmd = new OracleCommand(_sqlSelect, _oraconn))
                            cmd.CommandType = CommandType.Text;
                            using (OracleDataAdapter da = new OracleDataAdapter(cmd))
                                da.ReturnProviderSpecificTypes = _returnProviderSpecificTypes;
                                //da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                                if (_includeSchema == true)
                                    ds = new DataSet("SCHEMASUPPLIED");
                                    da.FillSchema(ds, SchemaType.Source);
                                    if (_fillTable == true)
                                        da.Fill(ds.Tables[0]);
                                else
                                    ds = new DataSet("SCHEMANOTSUPPLIED");
                                    if (_fillTable == true)
                                        da.Fill(ds);
                                ds.Tables[0].TableName = "Table";
                            }//using da
                        } //using cmd
                    catch (OracleException _oraEx)
                        throw (_oraEx); // Actually rethrow
                    catch (System.Exception _sysEx)
                        throw (_sysEx); // Actually rethrow
                    finally
                        if (_oraconn.State == ConnectionState.Broken || _oraconn.State == ConnectionState.Open)
                            _oraconn.Close();
                }//using oraconn
                if (ds != null)
                    if (ds.Tables != null && ds.Tables[0] != null)
                        return ds;
                    else
                        return null;
                else
                    return null;
            }r,
    dennis

  • How to find table name for the fields from Standard Extractor in CRM system

    How to find table name of fields from the standard extractor in CRM system ?
    e.g. We use LBWE TCode in R/3 system to find table name for the field from Extractor VCSCL(e.g.).
    Likewise is there any way to find table name for the fields from Standard extractor like 0CRM_LEAD_I.

    Hi ,
    Please find the link below for understanding BW CRM analysis.
    http://help.sap.com/bp_biv135/html/bw.htm
    activate the CRM DSs by scenario:
    1) Activate the application component hierarchy (tcode RSA9). Changes made to the application component hierarchy in the CRM system can be transferred to the BW using the "Edit Application Component Hierarchy" (SBIW - Postprocessing of DataSources).
    SAP Note 434886 must be implemented in CRM 3.0 before the application component hierarchy is activated.
    2) Activate the Business Content DataSources (tcode RSA5).
    Select/enter the application component and choose Execute (F8).
    To compare the shipped and active versions, choose the 'Select Delta' pushbutton. If there is no active version of the DataSource, it is selected automatically.
    To activate the shipped version, choose the 'Transfer DataSources' pushbutton.
    3) Management of the versions of the BW-Adapter metadata (tcode BWA5). All DataSources are displayed that are managed by the BW Adapter.
    As in transaction RSA5 (Service API Metadata Activation), the 'Select Delta' function can be used to select the inactive DataSources or compare shipped and active versions.
    You can also go directly to the screen for maintaining DataSources that are managed by the BW Adapter.
    The 'Compare Version' function makes a detailed comparison of the shipped and active versions.
    All BW-Adapter metadata is considered when versions are compared:
    Header information (Table SMOXHEAD)
    Mapping information (Table SMOXRELP)
    Global selection conditions (Table SMOXGSEL)
    Attribute key fields (Table SMOXAFLD)
    Hope this helps.
    Regards,
    csm reddy

Maybe you are looking for

  • Smartview 11.1.2.1 on Win 7 and Office 2010 32bit

    I installed 11.1.2.1 smartview on Win 7 and Office 2010 32 bit. The installation was successful but when I try to open Excel or Outlook I get the error that office encountered a serious problem with the add-in and disables the add-in to proceed. Any

  • Globals in crossdomain swf's (AS2)

    Hi, I have two domains (on the same server) each of the domains contains a crossdomain xml and swf's. The swf's have System.security.allowDomain("*") set. From 'domainOne' I start the main swf. This main swf loads (with a loader component) a swf from

  • Example code for video, many to many.

    I want to create an app that will allow multiple users to have the ability to see each other, is there any examples on how to do this?? Thanks, timgerr

  • Run two VI's simulateously?

    Hi, I was wondering is anyone has atip how I run two VI's simultaneously. The first VI is collecting data (through an instrument from HP) and I would like the second Vi to dislay the data while it is collected. I have seen some old VI's in a differen

  • Re: Satellite NB10T-A-101 - cannot boot from USB stick

    Hello, I bought a new Toshiba Satellite NB10T-A-101 and would like to boost performance by changing the HDD by a SSD and install windows 8.1 Pro. I'm however unable to boot from USB, it always mention: +Reboot and select proper Boot Device or insert