MySQL - In a Query, Using a Variable as a Table Name

Hello,
The code I have attached works. However, I would like to
replace the table name "tractors" with the variable "$result". How
do I do this? (It doesn't work if I just type "$result" where
"tractors" is.)
Thanks,
John

ArizonaJohn wrote:
> The code I have attached works. However, I would like to
replace the table
> name "tractors" with the variable "$result". How do I do
this?
You can't. In the code you have given $result is a MySQL
database result
resource. You need to extract the actual value from the
result resource
in the same way as you have done by using
mysql_fetch_array().
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS4",
"PHP Solutions" & "PHP Object-Oriented Solutions"
http://foundationphp.com/

Similar Messages

  • How to use bind variable value for table name in select statement.

    Hi everyone,
    I am having tough time to use value of bind variable for table name in select statement. I tried &p37_table_name. ,
    :p37_table_name or v('p37_table_name) but none worked.
    Following is the sql for interactive report:
    select * from v('p37_table_name') where key_loc = :P37_KEY_LOC and
    to_char(inspection_dte,'mm/dd/yyyy') = :P37_INSP_DT AND :p37_column_name is not null ;
    I am setting value of p37_table_name in previous page which is atm_state_day_insp.
    Following is error msg:
    "Query cannot be parsed, please check the syntax of your query. (ORA-00933: SQL command not properly ended) "
    Any help would be higly appreciated.
    Raj

    Interestingly enough I always had the same impression that you had to use a function to do this but found out from someone else that all you need to do is change the radio button from Use Query-Specific Column Names and Validate Query to Use Generic Column Names (parse query at runtime only). Apex will substitute your bind variable for you at run-time (something you can't normally do in pl/sql without using dynamic sql)

  • How to use a variable as a table name in PL/SQL?

    Hello all.
    I was given one day to wrote a piece of PL/SQL code to do a query. That is,
    First select two columns from one table and use them to build another table's name, then
         join the two tables. I'm not sure if variables can be used in the select list, if possible,
         how to reference them?
    -- My code is
    DECLARE
         tablename varchar2(40);
         CURSOR c1 IS
    select a.sourcesystemcode, a.adminorganizationno from cdb1.organization_mapping a
    where exists( select 1 from cdb1.organization_mapping b where
    a.cdborganizationno = b.cdborganizationno and a.adminorganizationno != b.adminorganizationno)
    order by a.cdborganizationno,a.adminorganizationno;
         v_src_sys_cod cdb1.organization_mapping.sourcesystemcode%TYPE;
         v_adm_org_no cdb1.organization_mapping.adminorganizationno%TYPE;
    BEGIN
    OPEN c1;
    LOOP
    FETCH c1 INTO v_src_sys_cod, v_adm_org_no;
    EXIT WHEN c1%NOTFOUND;
    tablename := 'ODS1.SRC_' || v_src_sys_cod || v_adm_org_no || 'ACTORG_CURR';
    select c.cdborganizationno, c.sourcesystemcode, c.adminorganizationno, c.sourceorganizationno, d.ibkcde, d.orgnam
    from cdb1.organization_mapping c inner join tablename d on c.sourceorganizationno = d.orgidt;
    END LOOP;
    CLOSE c1;
    END;
    The error message says "... the table or view does not exist... line 18, column 66..."
    It says the variable "tablename" wasn't build or build incorrectly.
    Please give the solution.

    If the TABLEs being queried are already known, and it is just a matter of which one to query, perhaps you can CREATE a VIEW that uses all the TABLEs with a UNION ALL, and include an identifier COLUMN.
    CREATE VIEW SRC_ALL_ACTORG_CURR
    AS
    SELECT 'aa' Name, ibkcde, orgnam FROM SRC_aa_ACTORG_CURR UNION ALL
    SELECT 'bb' Name, ibkcde, orgnam FROM SRC_bb_ACTORG_CURR UNION ALL
    SELECT 'cc' Name, ibkcde, orgnam FROM SRC_cc_ACTORG_CURR UNION ALL
    SELECT 'dd' Name, ibkcde, orgnam FROM SRC_dd_ACTORG_CURR UNION ALL
    SELECT 'ee' Name, ibkcde, orgnam FROM SRC_ee_ACTORG_CURR;
    Then, in you query:
    select c.cdborganizationno, c.sourcesystemcode, c.adminorganizationno, c.sourceorganizationno, d.ibkcde, d.orgnam
    from cdb1.organization_mapping c inner join SRC_ALL_ACTORG_CURR d on c.sourceorganizationno = d.orgidt and d.Name = v_src_sys_cod || v_adm_org_no;

  • Use a variable as a table name with NATIVE SQL

    Hi all,
    I am trying to execute a SELECT statement in order to fetch data from an external Oracle DB table to SAP with the following instructions:
    EXEC SQL.
      SELECT cityfrom, cityto
             INTO STRUCTURE :wa
             FROM spfli
             WHERE mandt  = :sy-mandt AND
                   carrid = :p_carrid AND connid = :p_connid
    ENDEXEC.
    However, I need to indicate the external table name from a variable instead of the solution above. That is, declaring a variable and store the name of the table (e.q. spfli) in it. The resulting ABAP code would be something like:
    EXEC SQL.
      SELECT cityfrom, cityto
             INTO STRUCTURE :wa
             FROM <VARIABLE>
             WHERE mandt  = :sy-mandt AND
                   carrid = :p_carrid AND connid = :p_connid
    ENDEXEC.
    Does anybody know if is possible to do that?
    If not, is there any other solution?
    Thank you in advance

    Yes, as Suhas said, you could use the ADBC API and his class CL_SQL_CONNECTION to achieve this...
    Here is a small example:
    PARAMETERS: p_carrid TYPE spfli-carrid,
                               p_connid TYPE spfli-connid.
    DATA:
      l_con_ref      TYPE REF TO cl_sql_connection,
      l_stmt         TYPE string,
      l_stmt_ref     TYPE REF TO cl_sql_statement,
      l_dref         TYPE REF TO data,
      l_res_ref      TYPE REF TO cl_sql_result_set,
      l_col1         TYPE spfli-carrid,
      l_col2         TYPE spfli-connid,
      l_wa           TYPE spfli.
    CONSTANTS:
      c_tabname  TYPE string VALUE 'SPFLI'.
    * Create the connecction object
    CREATE OBJECT l_con_ref.
    * Create the SQL statement object
    CONCATENATE 'select * from' c_tabname 'where carrid = ? and connid = ?'
           INTO l_stmt SEPARATED BY space.                           "#EC NOTEXT
    l_stmt_ref = l_con_ref->create_statement( ).
    * Bind input variables
    GET REFERENCE OF l_col1 INTO l_dref.
    l_stmt_ref->set_param( l_dref ).
    GET REFERENCE OF l_col2 INTO l_dref.
    l_stmt_ref->set_param( l_dref ).
    * Set the input value and execute the query
    l_col1 = p_carrid.
    l_col2 = p_connid.
    l_res_ref = l_stmt_ref->execute_query( l_stmt ).
    * Set output structure
    GET REFERENCE OF l_wa INTO l_dref.
    l_res_ref->set_param_struct( l_dref ).
    * Show result
    WHILE l_res_ref->next( ) > 0.
      WRITE: / 'Result:', l_wa-carrid, l_wa-connid.
    ENDWHILE.
    * Close the result set object
    l_res_ref->close( ).
    Otherwise you can also use the FM DB_EXECUTE_SQL...
    Kr,
    m.

  • CS5 Advanced Query - using a variable for a column name

    Hi
    I have been using Dreamweaver for a few years now, mostly version 8, but have just moved to CS5 (I teach it - among lots of other thing -  at what in the US would be a community college).
    I have problem with a page in CS5 that worked fine in my old version 8 edition.
    I am using PHP and MySQL as my server technologies
    I have a CD database and have constructed a Search Page which has a Form with a Text Box (stext) for the search criteria, and 3 option buttons to select the DB column I want to search on.  The option buttons are called sfield - and have values band, title, and/or year these will be passed to my display page (display.php) via GET array URL Parameters.  They are passed fine.
    I want to be able to enter "Pink" into the search text field, click the Band option button, and then my data displayed would inlude CDs by any band with Pink in their name i.e. Pink Floyd.  If I put 1989 and click the year option button, I search for all CDs from 1989 and so on.
    On my display page I created a recordset and selected my MySQL Server, DB Table, and using the simple dialogue selected band as the Filter and "contains" and the URL Parameter stext.   This all works as expected. I put in a  dynamic table and when I run it to test it, it will search on band only and works fine.
    Its when I try to select the column to search I get a problem.  I go to the advanced recordset dialogue.  I have the SQL
    Select * from newellcds where band like %colname%
    I need to change this to add a new variable, lookfield, which will hold my column selection from the option buttons (URL parameter: sfield), so I create the TEXT variable, with band as the default and the value of $_GET['sfield'] and put it into my SQL
    Select * from newellcds where lookfield like %colname% - and it doesn't work!!!  I always get no return from the database.
    After much experimentation, I echoed the Dreamweaver generated SQL on the screen and when I entered Pink and selected band on the search page, the Display SQL was displayed as:
    Select * from newellcds where 'band' like '%Pink%'
    Dreamweaver is putting single quotes round the value returned by my lookfield variable 'band' in this case.  If I enter the SQL without the quotes round Band into MySQL it works, with the quotes I get no returns.
    After this very long description - does anyone have an idea how to get rid of the quotes round my lookfield variable???
    How do I create a search page with two values passed - the actual criteria to search for, and the field to search for it in?
    Any help would be greatly appreciated.

    I don't have anything useful to contribute because I don't use DW to create queries, and you are not looking for help writing the query. You just want to get rid of the single quotes, which I can't help with.
    But based on your description, shouldn't the query be
    SELECT * FROM newellcds WHERE $sfield LIKE '%$stext%'
    If not, then I am not following.

  • PL/SQL - Using a variable as a table name

    I have a procedure like this -
    PROCEDURE insert_food IS
    BEGIN
    INSERT INTO food_table
    SELECT *
    FROM fruit_table;
    END insert_food;
    So this proceudre would insert all the records in the 'fruit_table' into the 'food_table'.
    Would there be any way to store the 'fruit_table' as a variable and use that in the script?
    Something like -
    PROCEDURE insert_food IS
    table_name varchar(11) := 'fruit_table';
    BEGIN
    INSERT INTO food_table
    SELECT *
    FROM table_name;
    END insert_food;
    Any help would be great!

    create or replace PROCEDURE insert_food IS
    table_name1 varchar(11) := 'emp';
    BEGIN
    execute immediate 'INSERT INTO emp2
    SELECT *
    FROM '||table_name1||'';
    commit;
    END insert_food;then
    exec insert_food;

  • How do I...Mimic Replacement Path with Query using Customer Variable Exits?

    Hello SDN:
    We are on BW 3.5 SP16.
    We are currently using a replacement path Query(RP) with variables
    to populate a variable in another Query(T).
    The problem we are having is with performance.
    The entry of variables in replacement path Query(RP) is optional (This is necessary there cannot be required values)
    When results from Replacement Path Query are small performance is fine. (e.g. 10 seconds)
    When results from Replacement path query are large performance suffers. (e.g. 1+ minutes)
    Users are free to leave the replacement path variables empty resulting in a large set of data to be replaced. This is the worst performance case.
    We would like to discover a way to conditionally execute the replacement path query. That is if users do not enter values for the replacement Query(RP) variables do not execute the replacement path query(RP).
    Does anyone know if this is possible within reason and in customer exit space?
    We have reviewed the situation from all angles and the requirement for the replacement path FUNCTIONALITY and the freedom for the user to leave variable values blank remains.
    I've been searching and reading SDN and SAP notes for about a week and do not find threads which address this situation.
    We are also exploring Customer variable exits to mimic replacement path functionality
    (different topic subject="How do I...Mimic Replacement Path with Query using Customer Variable Exits?")
    Any help will be appreciated
    Many thanks
    David Schuh

    My appologies-I posted this message with the wrong subject. I will repost it with appropriate subject.
    dave schuh

  • Using a parameter for a table name?

    In SQL Server, can you use a parameter for a table name?  I'm working with Visual C# and want to do something like this:
    SELECT MAX(ItemID) FROM @TableName;
    Can this be done?
    (Basically, I have three separate methods within a class--one for each table I have; and each one will perform the above query but on different table names.  I'd like to see if there is a way that I can have just one method that will allow me to specify
    the table name.)

    As pointed out in other posts, you can. But a more relevant question is whether you should.
    A table in a relational database is supposed to model a unique entity, and each column in the table is supposed to model a unique attribute. This is not always how it is, but it is from this model a relational database is designed.
    From this angle, having a dynamic table name does not really make sense for application code. (Administrative actions is a different story.) Think of it this way: have you ever wanted to make the class name dynamic in C#?
    Admittedly, it is different in .NET, because everything inherits from System.Object, but in a relational database there is no inheritence.
    Anyway, if you are using stored procedures, you should have one stored procedure per table. Physically, in the plan cache, there will be one query plan per table, no matter how you do it.
    If you are submitting SQL statements from your application, it is a different matter. In this case, I find it difficult to object if you have a class that performs generic actions against tables. Then you build the SQL string in the client code.
    However, no matter how you do it, you need to be careful to avoid SQL injection. We had the example:
    DECLARE @TableName nvarchar(50),@sqlCommand nvarchar(max)
      SET @TableName = ' ItemInformation'
      SET @sqlCommand = 'SELECT MAX(ItemID) FROM ' + @TableName
    EXEC (@sqlCommand)
    But what if we have:
      SET @TableName = ' sys.objects; SHUTDOWN WITH NOWAIT; --'
    As long as we do it in T-SQL, we can (and we should do!) this to prevent SQL injection:
      SET @sqlCommand = 'SELECT MAX(ItemID) FROM ' + quotename(@TableName)
    If you build your SQL strings in C#, you will need to employ other checks. There is only an issue if the user can inject data somewhere, but your generic class will not have knowledge of this, and must assume the worst.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • How to feed a query using a variable defined as Replacement Path-Query

    Scenario description : BI NetW 2004S - InfoCube with the following characteristics Customer, OrderDate, OrderYear and the following KeyFigure Number of Pieces.
    Objective: I need a query "QB" that shows how many pieces a set of customers has ordered in the year 2008. The set of customers is defined as all customers that in the previous years (the user can select one or more years) have ordered more than 500 pieces within the same year.
    Implementation: In general terms the idea is to build a query "QB" with the characteristic "Customer"  that is restricted (filtered) using a variable that is fed by another query "QA" (Replacement Path-Query).
    In order to have the selection of customers that for each of previous years (2007, 2006, 2005,...) have ordered more than 500 pieces, in the query "QA":
    - I put OrderYear as filter and defined a variable in order to ask the user which year/s he wants to analyse to define the selection
    - I put Customer and OrderYear in row
    - I put the KeyFigure Number of Pieces in column
    - I've defined the following condition: Number of Pieces > 500 with the option Caracteristic Assignment = All Characteristics in the Drilldown Indipendently
    Now if I run the query "QA" it works correctly showing me all customers that in the selected years have ordered more than 500 pieces within of the same year.
    If I run the query "QB" it shows a correct result only if I enter only one year (for example 2006) in the OrderYear field (coming from the query "QA"); if I enter more than one year (for example 2006 and 2007) the selection of customers showed is not the same defined by the first query "QB": I was expecting to see all customers defined from the first query less all customers that have no ordered any piece in 2008.
    Questions
    1) Why is query "QA" working on a different selection of customers when the user selects more than one year?
    2) Cosidering the scenario and the objective described above do you have any other idea?
    Thanks
    Ciao
    Roberto

    Hi Christophe,
         it's ok for me if I consider the customer only once in the final selection of customers that feeds the final query, this is my objective.
    However as test I've created 2 "input" queries, one related to 2006 and one related to 2007, and then in my destination query I've tried to restrict the customer using 2 variables of type replacement path-query (one attached to the 2006 query and one attached to the 2007 query). Unfortunately when I try to check and save the destination query, Query Designer tells me it is not possible to restrict the characteristic in this way.
    Could you please describe me steps you run in to order to restrict a characteristic using more than one variable of type replacement path-query?
    Thank you in advance for your answer.
    Ciao,
    Roberto

  • How to make dynamic query using DBMS_SQL variable column names

    First of all i will show a working example of what i intend to do with "EXECUTE IMMEDIATE":
    (EXECUTE IMMEDIATE has 32654 Bytes limit, which isn't enough for me so i'm exploring other methods such as DBMS_SQL)
    -------------------------------------------------CODE-----------------------------------
    create or replace PROCEDURE get_dinamic_query_content
    (query_sql IN VARCHAR2, --any valid sql query ('SELECT name, age FROM table') 
    list_fields IN VARCHAR2) --list of the columns name belonging to the query (  arr_list(1):='name';   arr_list(2):='age';
    -- FOR k IN 1..arr_list.count LOOP
    -- list_fields := list_fields || '||content.'||arr_list(k)||'||'||'''~cs~'''; )
    AS
    sql_stmt varchar (30000);
    BEGIN
                   sql_stmt :=
    'DECLARE
         counter NUMBER:=0;     
    auxcontent VARCHAR2(30000);     
         CURSOR content_cursor IS '|| query_sql ||';
         content content_cursor%rowtype;     
         Begin
              open content_cursor;
              loop
                   fetch content_cursor into content;
                   exit when content_cursor%notfound;
                   begin                              
                        auxcontent := auxcontent || '||list_fields||';                    
                   end;
                   counter:=counter+1;     
              end loop;
              close content_cursor;
              htp.prn(auxcontent);
         END;';
    EXECUTE IMMEDIATE sql_stmt;
    END;
    -------------------------------------------------CODE-----------------------------------
    I'm attepting to use DBMS_SQL to perform similar instructions.
    Is it possible?

    Hi Pedro
    You need to use DBMS_SQL here because you don't know how many columns your query is going to have before runtime. There are functions in DBMS_SQL to get information about the columns in your query - all this does is get the name.
    SQL&gt; CREATE OR REPLACE PROCEDURE get_query_cols(query_in IN VARCHAR2) AS
    2 cur PLS_INTEGER;
    3 numcols NUMBER;
    4 col_desc_table dbms_sql.desc_tab;
    5 BEGIN
    6 cur := dbms_sql.open_cursor;
    7 dbms_sql.parse(cur
    8 ,query_in
    9 ,dbms_sql.native);
    10 dbms_sql.describe_columns(cur
    11 ,numcols
    12 ,col_desc_table);
    13 FOR ix IN col_desc_table.FIRST .. col_desc_table.LAST LOOP
    14 dbms_output.put_line('Column ' || ix || ' is ' ||
    15 col_desc_table(ix).col_name);
    16 END LOOP;
    17 dbms_sql.close_cursor(cur);
    18 END;
    19 /
    Procedure created.
    SQL&gt; exec get_query_cols('SELECT * FROM DUAL');
    Column 1 is DUMMY
    PL/SQL procedure successfully completed.
    SQL&gt; exec get_query_cols('SELECT table_name, num_rows FROM user_tables');
    Column 1 is TABLE_NAME
    Column 2 is NUM_ROWS
    PL/SQL procedure successfully completed.
    SQL&gt; exec get_query_cols('SELECT column_name, data_type, low_value, high_value FROM user_tab_cols');
    Column 1 is COLUMN_NAME
    Column 2 is DATA_TYPE
    Column 3 is LOW_VALUE
    Column 4 is HIGH_VALUE
    PL/SQL procedure successfully completed.I've just written this as a procedure that prints out the column names using dbms_output - I guess you're going to do something different with the result - maybe returning a collection, which you'll then parse through in Apex and print the output on the screen - this is just to illustrate the use of dbms_sql.
    best regards
    Andrew
    UK

  • SQL Query using bind variables

    Hi All,
    Can any one please explain me how oracle will parse the below substr query using the bind varaibles, just want to know what oracle does in the backend when processing the below substr query.
    SUBSTR(:CDR_RT,3,7)
    Regards,
    Deepti

    All queries are processed in the same way.
    The example I've used on this article: PL/SQL 101 : Cursors and SQL Projection
    demonstrates the steps that a query/cursor goes through.
    If you're wondering if the SUBSTR in your query is applied to the value being bound in, _before_ the query is executed, then you are mistaken, the value is bound in as it is, and the substr takes place as part of the execution of the query.

  • Using a variable in an instance name

    Hey all,
    Simple question:
    I'm trying to use a variable to call on different instance names:
    var picCaller:uint=2;
    material_mc.addChild(pic_""+picCaller+"");
    The code in red is the issue in question.  In this example, I'm trying to add a child called "pic_2", with the number two called from the variable "picCaller"
    Any assistance is greatly appreciated.
    Thanks!

    Just for context, here is what I'm trying to do:
    I have jpegs in my library and I want to add them to the stage when they're needed, so just to add one image, here is the code I have:
    var pic_1=new pic1(0,0);
    var image_1:Bitmap=new Bitmap(pic_1);
    material_mc.addChild(image_1);
    I want to put the above into a loop so that I dont have to repeat those three lines for every image in my library like so:
    var pic_1=new pic1(0,0);
    var image_1:Bitmap=new Bitmap(pic_1);
    var pic_2=new pic2(0,0);
    var image_2:Bitmap=new Bitmap(pic_2);
    var pic_3=new pic3(0,0);
    var image_3:Bitmap=new Bitmap(pic_3);
    var pic_4=new pic4(0,0);
    var image_4:Bitmap=new Bitmap(pic_4);
    var pic_5=new pic5(0,0);
    var image_5:Bitmap=new Bitmap(pic_5);
    var pic_6=new pic6(0,0);
    var image_6:Bitmap=new Bitmap(pic_6);
    var pic_7=new pic7(0,0);
    var image_7:Bitmap=new Bitmap(pic_7);
    the variable "picNum" is the total amount of images that in the library, each one exported as "pic1", "pic2", "pic3" respectively.
    var picNum:uint=7;
    var picCaller:uint=1;
    var  picMC:MovieClip = new MovieClip();
    picMC=this["pic_"+picCaller];
    for (var  i:int = 1; i <= picNum; i=i+1)
         var "pic_"+i = new image_i(0,   0);
         var image:Bitmap = new Bitmap("pic_"+i);
    Thanks so much for your help.

  • Using a variable in an object name.

    Hi,
    I have 15 text fields each with 6 check boxes.
    I would like to copy the text fields to new fields depending on which checkbox's are checked.
    This also needs to be in a loop.
    I need to know how to add a variable into a textfield name?
    My code is basically like this:
    var x = 1;
    while (x<15)
         {if (Page1.CheckP// insert the value of x //S1.rawValue==1)
                        {Pax// insert the vaule of x //Sect1.rawValue=PaxName1
                   x=x+1};
    I am using Adobe Designer.
    Thank you in advance.
    Damo.

    Hi Bruce,
    I am running this code in a 'on click' event on a button.
    Basically, I have 5 passenger names each with 6 CheckBox's for 6 sectors.
    If Checkbox1 (Sector 1) is checked, I want to put the passenger name in a textfield. Then look for the next passenger on sector 1 and put them in the next textfield.
    This needs to be done for each sector.
    So this is what I have:
    var PaxName1=Page1.PaxName1.rawValue;  // and all other passenger names.
    // Sector 1
    var x = 1;
    while (x<5)
         var vCheck=Page1["CheckS1P"+x];
         if (vCheck.rawValue==1)
              {[TextField"+X].rawValue = PaxName''+X;
                x=x+1};
    Hope this explains what I am trying to do.

  • Using variable as a table name

    hi i want to use a variable as table in plsql block
    like
    declare cursor c1
    select to_char(to_date(substr(appl_uid,21,2),'MM'),'MON')||'_'|| as v_Tab,ename from my_table;
    v_ename = varchar(55);
    vv_table =varchar(6);
    begin
    open c1
    fetch c1 into vv_table,v_ename
    select ename into v_ename from vv_table;
    DBMS_OUTPUT.PUT_LINE (v_ename);
    close c1
    end;
    please help me to correct this block

    As mentioned by BlueShadow above the following statement will fail if the table has more then one row.
    EXECUTE IMMEDIATE 'select ename from ' || vv_table INTO v_ename;So I would suggest you use ref curosr to execute a SELECT dynamically which is likely to return more then one row.
    SQL> create table my_table (appl_uid VARCHAR2(30),ename varchar2(30));
    Table created.
    SQL> insert into my_table values ('123456789012345678901234567890','SCOTT');
    1 row created.
    SQL> insert into my_table values ('123456789012345678901123456789','WARD');
    1 row created.
    SQL> create table nov_ (ename varchar2(30));
    Table created.
    SQL> insert into nov_ values ('SMITH');
    1 row created.
    SQL> insert into nov_ values ('JAMES');
    1 row created.
    SQL> insert into nov_ values ('JONES');
    1 row created.
    SQL> create table dec_ (ename varchar2(30));
    Table created.
    SQL> insert into dec_ values ('ALLEN');
    1 row created.
    SQL> insert into dec_ values ('ADAMS');
    1 row created.
    SQL> insert into dec_ values ('KING');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> set serveroutput on
    SQL> declare
      2        cursor c1 is
      3        select to_char(to_date(substr(appl_uid, 21, 2), 'MM'), 'MON') || '_' as v_tab,ename
      4        from my_table;
      5        type ref_cur is ref cursor;
      6        c2 ref_cur;
      7        v_ename   varchar(55);
      8  begin
      9        for rec in c1 loop
    10          open c2 for 'select ename from ' || rec.v_tab;
    11          DBMS_OUTPUT.PUT_LINE('********************'||rec.v_tab||'********************');
    12          loop
    13              fetch c2 into v_ename;
    14              exit when c2%notfound;
    15              DBMS_OUTPUT.PUT_LINE(v_ename);
    16          end loop;
    17          close c2;
    18        end loop;
    19 end;
    23 /
    ********************DEC_********************
    ALLEN
    ADAMS
    KING
    ********************NOV_********************
    SMITH
    JAMES
    JONES
    PL/SQL procedure successfully completed.And at last as suggested by fellow members that it is a bad idea, I would agree and suggest you to relook your design.
    Edited by: zahid79 on Jul 22, 2010 10:28 PM

  • Dynamic Select query is failing with error "Invalid Table Name"

    OPEN rc FOR 'SELECT count(*) from :s' USING tab_name;
    fetch rc into rec_count;
    CLOSE rc;
    my requirement is to build dynamic select query to retrieve the total count of rows in each table ( variable tab_name contains the table_name )
    But I am getting stuck by this errror, not sure if there is any alternative !
    ORA-00903: invalid table name
    ORA-06512: at line 43

    OPEN rc FOR 'SELECT count(*) from '||tab_name;
    fetch rc into rec_count;
    CLOSE rc;
    -- This will work
    1. Create a sql statement.
    2. Open ref cursor for that statement.

Maybe you are looking for

  • Changing quiz button text

    I am working on a series of tutorials and quizzes for our client, I want to change the text on the "Next" button on the quizzes. It appears easy enough, in the options, Next button text field, I have entered what I want, but it still appears as "Next

  • Thinkpad Edge 15 TVSU "Not applicable" after fresh wipe of Windows 8.1 and install of Windows 7

    Hello, I have a user that purchased a Lenovo laptop and is having problems downloading drivers to support the machine now that it has Windows 7 (via Volume Licensing) on it. When running System Update after Windows updates, it will tell me that "Ther

  • Quick question (Synching)

    i have about 35 gigs of music on my ipod which took too many hours to synch..But i actually went in and redid all my id3 tags, and now want to re-sync it all over again. My question is.. If i just plug in my ipod , will it automatically overwrite eve

  • AE CS5 says missing component and refuses to fireup

    after effects could not start because a required component could not be found. this may be because of a damaged installation or unsupported operating system. Please consult the minimum requiremtns of re install After Effects. (998) thats the error me

  • PPR(Partner Product Range) Type for Product Catalog Views

    Hi all, I need to prevent showing some products in E-commerce Catalog depending on the PPR settings. Does the PPR type for Catalog Views help me? can any one explain me what is significance of drop-down "Application" in the PPR type configuration. th