CAN I PASS A TABLE NAME AS A VARIABLE IN THE FROM CLAUSE?

For some reason, I am trying to use a variable name containing the actual table name in the from clause and it won't allow me. I keep getting the error saying I need to declare the variable I'm using eventhough I've used it in another statement that is not the FROM clause.
Example
SELECT count(col1), sum(col2)
FROM v_table_name;
v_table_name was declared as:
v_tablename VARCHAR2(20);
v_tablename := real_table_name;
Is it not allowed to use variables in the FROM clause or am I missing something here?

You can use the Forms "From Clause Query" as the datasource for the data block. Then you can change the QUERY_DATA_SOURCE_NAME using set_block_property, so you can use any SQL statement you like. Of course you must name/alias the columns in a consistent manner so that the number of database items on the block matches those being queried.

Similar Messages

  • Can we pass IT table name dynamically to READ and SORT stmt

    Hello All,
      i have a requirement in which i am passing table name using a variable and want to read the same table: so my question is can we execute read and sort stmt with dynamic IT name. please see below for explaination.
    v_itname = <it_2>.
    now read using variable
    READ table ( v_itname ) with key <field>.
    and
    SORT ( v_itname ) by (otab).
    thanks
    Mani

    Hi ,
    This can be done. Please refer to the  codes below. Please note that the code will work if the itabs are of type standard table else it may dump.
    You just need to replace the variables form the values from your internal table.
    DATA: v_table1(10) TYPE c VALUE 'I_MARA',
          v_field(10)  TYPE c VALUE 'MATNR',
          i_mara TYPE STANDARD TABLE OF mara.
    FIELD-SYMBOLS : <fs_tab>   TYPE STANDARD TABLE,
                    <fs_field> TYPE ANY.
    DATA: otab TYPE abap_sortorder_tab,
    oline TYPE abap_sortorder.
    SELECT * UP TO 10 ROWS
      FROM  mara
      INTO TABLE i_mara.
    IF sy-subrc = 0.
      ASSIGN (v_table1) TO <fs_tab>.
      IF sy-subrc = 0.
        oline-name = v_field.
        APPEND oline TO otab.
        SORT <fs_tab> BY (otab).
        READ TABLE <fs_tab>
        WITH KEY (v_field) = '000000000020000989' "
        BINARY SEARCH
        TRANSPORTING NO FIELDS.
        IF sy-subrc = 0.
        ENDIF.
      ENDIF.
    ENDIF.
    Regards,
    Dev.

  • HOw can i show a table(name given in parameters) in a report program

    I made a report in which there is a paremeter asking for a table name ....
    PARAMETERS TBLLE_NAME(10) OBLIGATORY.
    Now when I enter the table namke then how can i show its values....
    HINT:- We have to use fiels symbols....AND THE USER CAN ENTER ANY DDIC TABLE NAME having some records ...........

    You can display the contents of the DB table inputted using ALV.
    Pass the Structure name as the DB table name inputted.
    Use CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE to create the dynamic table of the same structure as the DB table passed.
    Once the above steps are done, the internal table with data can be displayed using ALV.
    Reward points for all helpful answers.
    Thanks,
    Balaji

  • 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

  • Can we pass Internal tables to workflow container?

    workflow container has a size limitation, we need to pass any infotype to the workflow container, so can we pass internal tables to workflow container or is there any alternate solution?
    Thanks in Advance
    Hari

    Hi,
    Check the <a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/a6/9bac935f2c11d194a40000e82dec10/frameset.htm">Multiline Container Element Definition.</a>
    Regards
    <i><b>Raja Sekhar</b></i>

  • How to pass dynamically table name in my cursor declaration

    Hi:
    I am new. could you please let me know how to pass a table name dynamically in my cursor declaration? for instance I am declaring the following cursor in my pl/sql procedure:
    CURSOR crs_validate IS
    select * FROM <ACT_JUN_2006_LOB>;
    this ACT_JUN_2006_LOB table name, I should able to pass it when I open the cursor ... any help appreciated. thanks.
    srini

    Thanks all for the response. REFCURSOR does work: here is an example ... which I found on-line
    procedure emp_test(
    month varchar2,
    year varchar2)
    is
    type cur_typ is ref cursor;
    c cur_typ;
    query_str varchar2(200);
    emp_number number := 7900;
    salary number;
    name varchar2(30);
    Begin
    query_str := 'Select empno, ename, sal from emp_' || month ||'_'||year
    || ' where empno = :id';
    open c for query_str using emp_number;
    loop
    fetch c into emp_number, name, salary;
    exit when c%notfound;
    dbms_output.put_line(emp_number);
    end loop;
    close c;
    end;

  • Is it possible to create a view where table in the From clause changes name

    is it possible to create a view from a from a table like this
    create view my_view as select id, col1, col2, result from <<my_latest_cacahe_table>>;
    the table in the from clause changes the name .
    I have another table which indicates the the latest name of my cache tables. Always there are two records there. The latest one and previous one.
    select * from cache_table_def
    table_name cache_table_name refresh_date
    my_table cache_table245 1/23/2012
    my_table cache_table235 1/22/2012
    create table cache_table_def (table_name varchar2(25), cache_table_name varchar2(25), refresh_date date);
    insert into cache_table_def values( 'my_table','cache_table245','23-jan-2012');
    insert into cache_table_def values ( 'my_table','cache_table546','22-jan-2012');
    create table cache_table245 (id number, col1 varchar2(50), col2 varchar2(20), result number);
    insert into cache_table245 values(1, 'test123', 'test345',12.12);
    insert into cache_table245 values (2, 'test223', 'test245',112.12);
    create table cache_table235 (id number, col1 varchar2(50), col2 varchar2(20), result number);
    insert into cache_table235 values (1, 'test123', 'test345',92.12);
    insert into cache_table235 values (2, 'test223', 'test245',222.12);
    what I need to do is find the latest cache_table name for my_table and use that in my view defintion
    When user select from the the view it always reurns the data from the latest cache_table
    is it possible to do something like this in oracle 11g?
    I have no control on the cache tables names. that is why I need to use the latest name from the table.
    Any ideas really appreciated.

    I've worked up an example that does what you ask. It uses the SCOTT schema EMP table. Make two copies of the EMP table, EMP1 and EMP2. I deleted dept 20 from emp1 and deleted dept 30 from emp2 so I could see that the result set really came from a different table.
    -- create a context to hold an environment variable - this will be the table name we want the view to query from
    create or replace context VIEW_CTX using SET_VIEW_FLAG;
    -- create the procedure specified for the context
    - we will pass in the name of the table to query from
    create or replace procedure SET_VIEW_FLAG ( p_table_name in varchar2 default 'EMP')
      as
      begin
          dbms_session.set_context( 'VIEW_CTX', 'TABLE_NAME', upper(p_table_name));
      end;
    -- these are the three queries - one for each table - none of them will return data until you set the context variable.
    select * from emp where 'EMP' = sys_context( 'VIEW_CTX', 'TABLE_NAME' );
    select * from emp1 where 'EMP1' = sys_context( 'VIEW_CTX', 'TABLE_NAME' );
    select * from emp2 where 'EMP2' =  sys_context( 'VIEW_CTX', 'TABLE_NAME' )
    -- this is how you set the context variable depending on the table you want the view to query
    exec set_view_flag( p_table_name => 'EMP' );
    exec set_view_flag( p_table_name => 'EMP1' );
    exec set_view_flag( p_table_name => 'EMP2');
    -- this will show you the current value of the context variable
    SELECT sys_context( 'VIEW_CTX', 'TABLE_NAME' ) FROM DUAL
    -- this is the view definition - it does a UNION ALL of the three queries but only one will actually return data
    CREATE VIEW THREE_TABLE_EMP_VIEW AS
    select * from emp where 'EMP' = sys_context( 'VIEW_CTX', 'TABLE_NAME' )
    union all
    select * from emp1 where 'EMP1' = sys_context( 'VIEW_CTX', 'TABLE_NAME' )
    union all
    select * from emp2 where 'EMP2' =  sys_context( 'VIEW_CTX', 'TABLE_NAME' )
    -- first time - no data since context variable hasn't been set yet
    SELECT * FROM THREE_TABLE_EMP_VIEW
    -- get data from the EMP table
    exec set_view_flag( p_table_name => 'EMP' );
    SELECT * FROM THREE_TABLE_EMP_VIEW
    -- get data from the EMP2 table
    exec set_view_flag( p_table_name => 'EMP2');
    SELECT * FROM THREE_TABLE_EMP_VIEW
    For your use case you just have to call the context procedure whenever you want to switch tables. You can union all as many queries as you want and can even put WHERE clause conditions based on other filtering criteria if you want. I have used this approach with report views so that one view can be used to roll up report data different ways or for different regions, report periods (weekly, quarterly, etc). I usually use this in a stored procedure that returns a REF CURSOR to the client. The client requests a weekly report and provides a date, the procedure calculates the START/END date based on the one date provided and sets context variables that the view uses in the WHERE clause for filtering.
    For reporting it works great!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Table name by a variable

    Am trying to give a table name by a variable but its giving me errors can anyone plz help... resNr is a int!
    db2.insert("CREATE TABLE "+resNr+"(\n"+
    "ID int(11) NOT NULL auto_increment,\n"+
    "GAESTNR int(11) NOT NULL default '0',\n"+
    "VARENR int(11) NOT NULL default '0',\n"+
    "ANTAL int(11) NOT NULL default '0',\n"+
    "VAREBETEGNELSE tinytext NOT NULL,\n"+
    "PRIS int(11) NOT NULL default '0',\n"+
    "BEL�B int(11) NOT NULL default '0',\n"+
    "PRIMARY KEY (ID)\n"+
    ")TYPE=MyISAM");

    print out the statement to the java console (System.out.println) and type the command into the mysql console. I guess you are missing a space before the bracket:
    db2.insert("CREATE TABLE "+resNr+" (\n"+
    also, you must consider the naming conventions of mysql tables. a table cannot be named "1", "2", the name must start with a letter, I think.

  • The table name or tcode to count the number of Dimensions and Key Figures

    Hi all,
    Do you have an idea about the table name or tcode to count the number of Dimensions and Key Figures of an Infocube WITHOUT installing the cube from Business Content?
    Thanks in adv.
    Ajay

    Hi,
    You can't do that because there's no active table in the system for the Business Content since it hasn't been installed yet...
    One thing you could do is go to the Business Content Tab, select "Infoproviders by InfoArea" on the left side, look for the Cube or DSO you want to check, right click on it and select "Display Description".
    On the window that opens you'll have a list of all InfoObjects and Key Figures. You also have the option to Display it as Start Schema, where you can see the Dimensions, etc.
    Hope this helps.
    Luis

  • How to find table name which provide data for the DataSource

    Hi friends,
    How to find the Table name which providing data for the Business content DataSources (Master Data). Is there any table or Transation which give datasource and Table name at once.
    Thanks&Regards
    Revathi

    Hi Revathi...........
    1)If the datasource is extracting data from any table.................open the datasource using RSO2..........there u will get the table name......
    2) If the datasource is extracting data from any view.............go to RSA2..........copy the view name..........go to SE11 >> give the view name >> and check..........
    3) If Datasource is Function module based............then u hav to check in RSA2 >> give the datasource name >> execute >> there u will find the Extract structure name......Copy the Extract Structure name >> Go to SE11 >> in the Data Element field give the Extract structure name >> Display >> From the Entry Help/Check tab u can get the Table name............
    If u double click on the Extractor..............u will get the Function Module..............from there also u can check that the FM extracting data from which tables............
    For Other datasources also...........u can get the structure name from here........
    4) If the Datasources r LO datasources............then u can get the table name in LBWE.............LO extractor - goto transaction LBWE.................... Select the maintenance link for your datasource............
    here in the right hand pane.........in the drop down box, you can see the structures associated with this extractor ........ just remove the MC for the structure names to get the base table names. e.g. EKKO for MCEKKO.
    5) There is a pattern for the Extract structure name for LO datasources.............for an example..........
    DataSource 2LIS_11_VAITM ......Extract structure name is  MC11VA0ITM
    2LIS_11_VAHDR  >> MC11VA0HDR
    Hope this helps.........
    Regards,
    Debjani.......

  • Table name for shipping details for the given purchase order

    Hi,
    Table name for shipping details for the given purchase order
    regards,
    vijay

    Had anybody seen that this question was raised 5 years ago?
    And the question was about where are the shipping details of a purchase order stored.
    The discussion owner hat marked the the discussion a year ago as solved, but did not mark any correct answer and did not tell himself what the solution was.
    The correct answer was given by Amitkumar yesterday, it is EKPV
    I am locking the discussion to avoid that even more wrong answers are added to this particualr question

  • Unable to  use Table name in a variable

    Hi,
    I am trying to build a select statement which uses table name in a variable. Please help me in building such statements.
    Regards
    Kishore

    Hi,
    I am trying to build a select statement which uses table name in a variable. Please help me in building such statements.
    Regards
    Kishore

  • Create table where table name is a variable

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

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

  • Why is it that on a 5s you can by pass all security measures via Siri, where as the 4S asks for an unlock?

    On a 5s you can by pass all security measures via Siri, where as the 4S asks for an unlock.  Why?

    My daughter has had her Razr for about 9 months now.  About two weeks ago she picked up her phone in the morning on her way to school when she noticed two cracks, both starting at the camera lens. One goes completely to the bottom and the other goes sharply to the side. She has never dropped it and me and my husband went over it with a fine tooth comb. We looked under a magnifying glass and could no find any reason for the glass to crack. Not one ding, scratch or bang. Our daughter really takes good care of her stuff, but we still wanted to make sure before we sent it in for repairs. Well we did and we got a reply from Motorola with a picture of the cracks saying this was customer abuse and that it is not covered under warranty. Even though they did not find any physical damage to back it up. Well I e-mailed them back and told them I did a little research and found pages of people having the same problems. Well I did not hear from them until I received a notice from Fed Ex that they were sending the phone back. NOT FIXED!!! I went to look up why and guess what there is no case open any more for the phone. It has been wiped clean. I put in the RMA # it comes back not found, I put in the ID #, the SN# and all comes back not found. Yet a day earlier all the info was there. I know there is a lot more people like me and all of you, but they just don't want to be bothered so they pay to have it fix, just to have it do it again. Unless they have found the problem and only fixing it on a customer pay only set up. I am furious and will not be recommending this phone to anyone. And to think I was considering this phone for my next up grade! NOT!!!!

  • I want to use a dynamic schema name in the from clause but its not working.

    DECLARE
         vblQueryName VARCHAR2(20);
         vblSchemaName VARCHAR2(20);
    BEGIN
         SELECT CurrentSchemaName INTO vblSchemaName FROM HR_989_SCHEMA;
         vblQueryName:='060_525_020';
         INSERT /*+ APPEND(HP_ELIGIBILITIES,4) */ INTO HP_ELIGIBILITIES
              LVL1ID,
              LVL1Desc,
              LVL2ID,
              LVL2Desc,
              LVL3ID,
              LVL3Desc,
              LVL4ID,
              LVL4Desc
         SELECT /*+ PARALLEL(a,4) */
              LVL1ID,
              LVL1Desc,
              LVL2ID,
              LVL2Desc,
              LVL3ID,
              LVL3Desc,
              LVL4ID,
              LVL4Desc
         FROM
         bold     vblSchemaName.HP_ELIGIBILITIES a
         WHERE
              UPPER(LVL2ID) = 'XX' ;
         COMMIT;
    DBMS_OUTPUT.PUT_LINE( 'Query Executed: ' || vblqueryName);
    INSERT INTO HP_QUERYEXECLOG(QueryName) VALUES(vblQueryName);
    EXCEPTION WHEN NO_DATA_FOUND THEN NULL;
    END;
    I want to create a rules table so that the schema name in front of the table name in the from clause can be controlled by a separate table that is maintained but its not working . Help and your valuable inputs needed for this issue

    I want to use a dynamic schema name in the from clauseyou can alternatively set the current schema as e.g. in:
    declare
       vblqueryname    varchar2 (20);
       vblschemaname   varchar2 (20);
    begin
       select currentschemaname into vblschemaname from hr_989_schema;
       vblqueryname := '060_525_020';
       execute immediate 'alter session set current_schema=' || vblschemaname;
       insert /*+ APPEND(HP_ELIGIBILITIES,4) */
             into hp_eligibilities (lvl1id,
                                    lvl1desc,
                                    lvl2id,
                                    lvl2desc,
                                    lvl3id,
                                    lvl3desc,
                                    lvl4id,
                                    lvl4desc
          select /*+ PARALLEL(a,4) */
                lvl1id,
                 lvl1desc,
                 lvl2id,
                 lvl2desc,
                 lvl3id,
                 lvl3desc,
                 lvl4id,
                 lvl4desc
            from hp_eligibilities a
           where upper (lvl2id) = 'XX';
       commit;
       dbms_output.put_line ('Query Executed: ' || vblqueryname);
       insert into hp_queryexeclog (queryname)
       values (vblqueryname);
    exception
       when no_data_found
       then
          null;
    end;

Maybe you are looking for

  • Dead iMac 17'' Intel

    Hello everyone, I have a big problem with my iMac 17'' intel, and a service provider in Serbia, the only service provider in Serbia. I broth my iMac to a service provider in Serbia - GlobeNet (www.applecentar.co.yu ) a month and a half ago, on 13th D

  • BW RRI /Jump query functionality in Design Studio

    Hi Folks Could someone throw light on the following functionality: I am using Design Studio 1.2 with BI 4.1 SP1 and BW 7.3 SP9 . I have  a BW query which is having jump query in it. I have included it in the Design studio. I have configured Query A .

  • An advertiser is saying that the Ad is larger than the prescribed space

    So I have this ad for a leaderboard spot: 728x90. The dimensions of the FLA is 728x90 (as defined by the document settings). And yet the advertiser is saying that the produced SWF file is the wrong dimension. There are elements in the ad that animate

  • Database upgrade from March 2013 to October 2013 Issue

    Hiya, Am I missing something completely obvious trying to upgrade a March 2013 PU content database to a October 2013 CU and it's failing, using Mount-SPContentDatabase. The farm account and my install user has the DB_Owner and SPDataAccess roles, how

  • Modifying multiple transitions.

    Is it possible to modify the durations of several transitions at once? I tried selecting them all, but could not access "duration" under the "Modify" menu. I want all the transitions to have the same duration (not the default 1sec)