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.

Similar Messages

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

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

  • Table name where query variables stored

    Hi All,
    can any one please tell me in which data base table all the custom query variables are stored???

    Hi Pousali,
      Check RSZGLOBV.
    Hope it Helps
    Srini

  • How to use table name as variable in insert statement

    Hi,
    I want to insert data from the cursor into the table and I want to submit table name as a variable. I tried the code below but it's not working. Any ideas how to solve this problem? Thx
    DECLARE
    v_new_table_name VARCHAR2(30) := 'test';
    --open cursor   
    CURSOR ACM IS
    SELECT *
    FROM DWH.CLI_DIMENSION@SLSPDW CLI
    WHERE where_clause
    FROM some_table;
    BEGIN
    FOR REC_ACM IN ACM LOOP
    EXECUTE IMMEDIATE 'INSERT INTO ' || v_new_table_name || ' VALUES REC_ACM'; --table name as a variable in which the data from cursor will be inserted
    V_ROWCOUNT := V_ROWCOUNT + 1;
    IF MOD(V_ROWCOUNT, 100) = 0 THEN --this feature commits after 100 rows.
    COMMIT;
    END IF;
    END LOOP;
    COMMIT;
    DBMS_OUTPUT.PUT_LINE('Number of inserted records:' || V_ROWCOUNT);
    END;

    Try this and let me know if it works. I have not tested it so I can not say for sure.
    DECLARE
      v_new_table_name VARCHAR2(30) := 'test';
      CURSOR ACM IS
        SELECT * FROM DWH.CLI_DIMENSION@SLSPDW CLI
                WHERE where_clause
                FROM some_table;
      BEGIN
      loop
       fetch ACM INTO REC_ACM
       exit when ACM%NOTFOUND;
       EXECUTE IMMEDIATE 'INSERT INTO ' || v_new_table_name || ' VALUES REC_ACM';
       V_ROWCOUNT := V_ROWCOUNT + 1;
       IF MOD(V_ROWCOUNT, 100) = 0 THEN
        COMMIT;
       END IF;
      end loop;
      COMMIT;
      DBMS_OUTPUT.PUT_LINE('Number of inserted records:' || V_ROWCOUNT);
      END;

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

  • Variable table name in insert

    In forms i want to give variable as table name.
    e.g When_button_press
    Insert into :txt1 values (select * from abc1)
    return error on :txt1.
    how can i do this.

    There are examples in the forum that show how. Here are some of them:
    CAN I PASS A TABLE NAME AS A VARIABLE IN THE FROM CLAUSE?
    DML issue in Oracle forms
    Re: How to include variable on block's query
    How to use table name as variable

  • Passing Table name as parameter to proc.

    Hi,
    I need to know how to pass a table name to a oracle procedure.
    In that procedure I will put that table name in a variable and then I will make operations on that table like DELETE, UPDATE and INSERT.
    Kinldy give me the solution for the above problem as soon as possible..
    Thanks & regards,
    Kiran

    You shouldn't do it, but if you do, you can use something like this:
    Anton
    create or replace type my_parm as object
      ( name varchar2(30)
      , val  anydata
    create or replace type my_parms as table of my_parm
    create table t1( c1 number, c2 varchar2(10), c3 date )
    create or replace procedure doital( p_action in varchar2, p_tab in varchar2, parms in my_parms )
    is
      p_stmt1 varchar2(32000);
      p_stmt2 varchar2(32000);
      ind pls_integer;
      curs integer;
      dummy integer;
      t_a anytype;
      t_v varchar2(32000);
      t_n number;
      t_d date;
    begin
      curs := dbms_sql.open_cursor;
      if upper( p_action ) = 'I'
      then
        ind := parms.first;
        loop
          exit when ind is null;
          p_stmt1 := p_stmt1 || ', ' || parms( ind ).name;
          p_stmt2 := p_stmt2 || ', :b' || to_char( ind );
          ind := parms.next( ind );
        end loop;
        p_stmt1 := 'insert into ' || p_tab || ' (' || substr( p_stmt1, 2 ) || ' ) values (' || substr( p_stmt2, 2 ) || ' )';
        dbms_sql.parse( curs, p_stmt1, dbms_sql.native );
        ind := parms.first;
        loop
          exit when ind is null;
          case parms( ind ).val.GetType( t_a )
            when dbms_types.typecode_varchar2
            then
              dummy := parms( ind ).val.GetVarchar2( t_v );
              dbms_sql.bind_variable( curs, ':b' || to_char( ind ), t_v );
            when dbms_types.typecode_number
            then
              dummy := parms( ind ).val.GetNumber( t_n );
              dbms_sql.bind_variable( curs, ':b' || to_char( ind ), t_n );
            when dbms_types.typecode_date
            then
              dummy := parms( ind ).val.GetDate( t_d );
              dbms_sql.bind_variable( curs, ':b' || to_char( ind ), t_d );
          end case;
          ind := parms.next( ind );
        end loop;
      end if;
      dummy := dbms_sql.execute( curs );
      dbms_sql.close_cursor( curs );
    end;
    begin
      doital( 'I', 't1', my_parms( my_parm( 'c2', anydata.ConvertVarchar2( 'testje' ) )
                                 , my_parm( 'c1', anydata.ConvertNumber( 3 ) )
                                 , my_parm( 'c3', anydata.ConvertDate( sysdate ) )
      doital( 'I', 't1', my_parms( my_parm( 'c1', anydata.ConvertNumber( 77 ) )
                                 , my_parm( 'c2', anydata.ConvertVarchar2( 'goedzo' ) )
                                 , my_parm( 'c3', anydata.ConvertDate( sysdate - 5 ) )
    end;
    /

  • Dynamic physical table name vs. Cache

    Hello, Experts!
    I'm facing quite an interesting problem. I have two physical tables with the same structure but with a different data. Requirement is to show same reports with one or another table. Idea is to have dynamically changed physical table name with session variable usage. Session variable can be change in UI so it was working until cache was turned on. When cache is turned on logical statements sent to OBI backend are the same even for different values of session variable that stores physical table name. Once cache is populated every users will get values from cache. This is possible source of discrepancy because some users might run reports with tableA values and some with tableB values.
    Are there any options to set OBI to use data related to proper physical table name (i.e. accordingly to session variable value)? Model clone is not an option because it will be way to hard and complex to maintain both, beside same reports need to work sometimes with one table name and sometimes with other...
    PS. Cache is set to be common for all users.
    Lucas

    thank you, I've found another way to make it running. In fact there are two ways of doing it: filter LTS and have all data filtered from single table with session variable or use fragmentation content also with session variable.
    Now tricky part is to set variable from UI, currently I'm using issue raw sql: call NQSSetSessionValue( 'String SV_SIGNOFF=aaa;' ) but I have to figure out how to change session non system variable value without need of administrator user rights.
    There is GoURL method, but it's not working...
    2. Add In ORACLE_HOME/bifoundation/web/display/authenticationschemas.xml
    <RequestVariable source="url" type="informational" nameInSource="lang"
    biVariableName="NQ_SESSION.LOCALE" />
    inside the top <AuthenticationSchemaGroup> </AuthenticationSchemaGroup> tag

  • Table Name Substitution with a varaible

    I have the following procedure....
    LOOP
    FETCH table_cur INTO table_rec;
    EXIT WHEN NOT table_cur%FOUND;
    TableID := table_rec.TableName;
    Office := table_rec.OfficeNum;
    Client := table_rec.CliNum;
    IF Office = 'Y' AND Client = 'Y' Then
    UPDATE TableID
    SET OfficeNum = (SELECT OfficeNum
    FROM Comd02a
    WHERE Comd02a.CliNum = TableID.CliNum
    AND Comd02a.LoanNum = TableID.LoanNum);
    END IF;
    END LOOP;
    CLOSE table_cur;
    TableID is a vaiable and I keep coming back with an error... How
    do I make a reference to a table through a variable...
    Thanks in Advance
    Sally
    null

    Brian Lelek (guest) wrote:
    : Rashmi Rungta (guest) wrote:
    : : Hi,
    : : You cannot make a direct reference to a table name thru a
    : : variable. You have to use dynamic sql.
    : : Hope it helps. Let me know if you need further information on
    : how
    : : to use dynamic sql.
    : : Rashmi
    : : Sally (guest) wrote:
    : : : I have the following procedure....
    : : : LOOP
    : : : FETCH table_cur INTO table_rec;
    : : : EXIT WHEN NOT table_cur%FOUND;
    : : : TableID := table_rec.TableName;
    : : : Office := table_rec.OfficeNum;
    : : : Client := table_rec.CliNum;
    : : : IF Office = 'Y' AND Client = 'Y' Then
    : : : UPDATE TableID
    : : : SET OfficeNum = (SELECT OfficeNum
    : : : FROM
    : Comd02a
    : : : WHERE Comd02a.CliNum =
    : TableID.CliNum
    : : : AND Comd02a.LoanNum =
    : : TableID.LoanNum);
    : : : END IF;
    : : : END LOOP;
    : : : CLOSE table_cur;
    : : : TableID is a vaiable and I keep coming back with an
    error...
    : : How
    : : : do I make a reference to a table through a variable...
    : : : Thanks in Advance
    : : : Sally
    : The previous response is correct. You must use dynamic SQL.
    : With dynamic SQL, you create a string in a varchar field that
    : contains the SQL statement. Then you pass that string to
    Oracle
    : for execution. I think that orange and white book has a good
    : explanation of dynamic SQL. My copy of the book is not here,
    : but I can look it up in a few days if you are still having
    : trouble.
    : By the way, you may want to consider using a "cursor for
    loop".
    : This code is more simple because you don't need and OPEN,
    FETCH,
    : EXIT, or CLOSE. See below:
    : FOR table_rec IN table_cur
    : LOOP
    : END LOOP;
    : Brian
    Hello,
    Yes, you need to use dynamic SQL. If you are using oracle 7 or
    8.0.x, you can use the bundled package dbms_sql to do the dynamic
    SQL. If you are using 8i (8.1.5), the PL/SQL is improved to do
    the dynamic SQL directly. You can now do for example:
    begin
    execute immediate 'update '

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

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

Maybe you are looking for