Update a date field using execute immediate statement..

I need to update a date field dynamically .
Below is the code I have written for the same..
EXECUTE IMMEDIATE
'UPDATE Temp_Emp ' ||
' SET ' || V_Fieldname || ' = ' || D_Value ||
'WHERE Emp_Id = ' || 8447;
I am getting the following error..
ORA-00904: "AUG": invalid identifier
Pls anyone have any ideas..
Thanks,
Xyz

put D_Value in single quotes like this
EXECUTE IMMEDIATE
'UPDATE Temp_Emp ' ||
' SET ' || V_Fieldname || ' = ''' || D_Value ||''' WHERE Emp_Id = ' || 8447;

Similar Messages

  • Andydata.getObject in piecewise mode using execute immediate statement err

    andydata.getObject in piecewise mode using execute immediate statement
    will get ora-00600 arguments:[kopuigpfx1], [14] in Oracle 11.1.0.6 and Oralce 10.2.0.2.
    andydata.getObject in piecewise mode using execute immediate statement err
    andydata.getObject in piecewise mode using execute immediate statement will get ora-00600 arguments:[kopuigpfx1], [14] in Oracle 11.1.0.6 and Oralce 10.2.0.x
    The following are test scripts in HR schema.
    create type ob_test is object(c1 varchar2(10));
    script 1: not using execute immediate statement and works fine.
    DECLARE
    p_anytype anytype;
    p_anydata anydata;
    p_value_1 VARCHAR2(4000);
    p_value_2 ob_test;
    p_result PLS_INTEGER;
    BEGIN
    anytype.begincreate(dbms_types.typecode_object, p_anytype);
    p_anytype.addattr('A1',
    dbms_types.typecode_varchar2,
    NULL,
    NULL,
    4000,
    NULL,
    NULL,
    NULL);
    p_anytype.addattr('A2',
    dbms_types.typecode_object,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    anytype.getpersistent('HR', 'OB_TEST'));
    p_anytype.endcreate();
    anydata.begincreate(p_anytype, p_anydata);
    p_anydata.setvarchar2('abc');
    p_anydata.setobject(OB_TEST('abc'));
    p_anydata.endcreate;
    DECLARE
    p_anydata2 anydata := p_anydata;
    p_value_1 VARCHAR2(4000);
    p_value_2 OB_TEST;
    p_result PLS_INTEGER;
    BEGIN
    p_anydata2.piecewise;
    p_result := p_anydata2.getvarchar2(p_value_1);
    p_result := p_anydata2.getobject(p_value_2);
    END;
    END;
    script 2: using execute immediate statement will get ora-600
    DECLARE
    p_anytype anytype;
    p_anydata anydata;
    p_value_1 VARCHAR2(4000);
    p_value_2 ob_test;
    p_result PLS_INTEGER;
    BEGIN
    anytype.begincreate(dbms_types.typecode_object, p_anytype);
    p_anytype.addattr('A1',
    dbms_types.typecode_varchar2,
    NULL,
    NULL,
    4000,
    NULL,
    NULL,
    NULL);
    p_anytype.addattr('A2',
    dbms_types.typecode_object,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    anytype.getpersistent('HR', 'OB_TEST'));
    p_anytype.endcreate();
    anydata.begincreate(p_anytype, p_anydata);
    p_anydata.setvarchar2('abc');
    p_anydata.setobject(OB_TEST('abc'));
    p_anydata.endcreate;
    EXECUTE IMMEDIATE 'DECLARE' || chr(10) ||
    ' p_anydata2 anydata := :1;' || chr(10) ||
    ' p_value_1 VARCHAR2(4000);' || chr(10) ||
    ' p_value_2 OB_TEST;' || chr(10) ||
    ' p_result PLS_INTEGER;' || chr(10) || 'BEGIN' ||
    chr(10) || ' p_anydata2.piecewise;' || chr(10) ||
    ' p_result := p_anydata2.getvarchar2(p_value_1);' ||
    chr(10) ||
    ' p_result := p_anydata2.getobject(p_value_2);' ||
    chr(10) || 'END;'
    USING p_anydata;
    END;
    script 3: comment statment "p_result := p_anydata2.getobject(p_value_2);", it works ok.
    DECLARE
    p_anytype anytype;
    p_anydata anydata;
    p_value_1 VARCHAR2(4000);
    p_value_2 ob_test;
    p_result PLS_INTEGER;
    BEGIN
    anytype.begincreate(dbms_types.typecode_object, p_anytype);
    p_anytype.addattr('A1',
    dbms_types.typecode_varchar2,
    NULL,
    NULL,
    4000,
    NULL,
    NULL,
    NULL);
    p_anytype.addattr('A2',
    dbms_types.typecode_object,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    anytype.getpersistent('HR', 'OB_TEST'));
    p_anytype.endcreate();
    anydata.begincreate(p_anytype, p_anydata);
    p_anydata.setvarchar2('abc');
    p_anydata.setobject(OB_TEST('abc'));
    p_anydata.endcreate;
    EXECUTE IMMEDIATE 'DECLARE' || chr(10) ||
    ' p_anydata2 anydata := :1;' || chr(10) ||
    ' p_value_1 VARCHAR2(4000);' || chr(10) ||
    ' p_value_2 OB_TEST;' || chr(10) ||
    ' p_result PLS_INTEGER;' || chr(10) || 'BEGIN' ||
    chr(10) || ' p_anydata2.piecewise;' || chr(10) ||
    ' p_result := p_anydata2.getvarchar2(p_value_1);' ||
    chr(10) ||
    ' /*p_result := p_anydata2.getobject(p_value_2);*/' ||
    chr(10) || 'END;'
    USING p_anydata;
    END;
    Could someone tell me how to solve this problem.
    Thanks a lot.
    Daniel

    andydata.getObject in piecewise mode using execute immediate statement
    will get ora-00600 arguments:[kopuigpfx1], [14] in Oracle 11.1.0.6 and Oralce 10.2.0.2.
    andydata.getObject in piecewise mode using execute immediate statement err
    andydata.getObject in piecewise mode using execute immediate statement will get ora-00600 arguments:[kopuigpfx1], [14] in Oracle 11.1.0.6 and Oralce 10.2.0.x
    The following are test scripts in HR schema.
    create type ob_test is object(c1 varchar2(10));
    script 1: not using execute immediate statement and works fine.
    DECLARE
    p_anytype anytype;
    p_anydata anydata;
    p_value_1 VARCHAR2(4000);
    p_value_2 ob_test;
    p_result PLS_INTEGER;
    BEGIN
    anytype.begincreate(dbms_types.typecode_object, p_anytype);
    p_anytype.addattr('A1',
    dbms_types.typecode_varchar2,
    NULL,
    NULL,
    4000,
    NULL,
    NULL,
    NULL);
    p_anytype.addattr('A2',
    dbms_types.typecode_object,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    anytype.getpersistent('HR', 'OB_TEST'));
    p_anytype.endcreate();
    anydata.begincreate(p_anytype, p_anydata);
    p_anydata.setvarchar2('abc');
    p_anydata.setobject(OB_TEST('abc'));
    p_anydata.endcreate;
    DECLARE
    p_anydata2 anydata := p_anydata;
    p_value_1 VARCHAR2(4000);
    p_value_2 OB_TEST;
    p_result PLS_INTEGER;
    BEGIN
    p_anydata2.piecewise;
    p_result := p_anydata2.getvarchar2(p_value_1);
    p_result := p_anydata2.getobject(p_value_2);
    END;
    END;
    script 2: using execute immediate statement will get ora-600
    DECLARE
    p_anytype anytype;
    p_anydata anydata;
    p_value_1 VARCHAR2(4000);
    p_value_2 ob_test;
    p_result PLS_INTEGER;
    BEGIN
    anytype.begincreate(dbms_types.typecode_object, p_anytype);
    p_anytype.addattr('A1',
    dbms_types.typecode_varchar2,
    NULL,
    NULL,
    4000,
    NULL,
    NULL,
    NULL);
    p_anytype.addattr('A2',
    dbms_types.typecode_object,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    anytype.getpersistent('HR', 'OB_TEST'));
    p_anytype.endcreate();
    anydata.begincreate(p_anytype, p_anydata);
    p_anydata.setvarchar2('abc');
    p_anydata.setobject(OB_TEST('abc'));
    p_anydata.endcreate;
    EXECUTE IMMEDIATE 'DECLARE' || chr(10) ||
    ' p_anydata2 anydata := :1;' || chr(10) ||
    ' p_value_1 VARCHAR2(4000);' || chr(10) ||
    ' p_value_2 OB_TEST;' || chr(10) ||
    ' p_result PLS_INTEGER;' || chr(10) || 'BEGIN' ||
    chr(10) || ' p_anydata2.piecewise;' || chr(10) ||
    ' p_result := p_anydata2.getvarchar2(p_value_1);' ||
    chr(10) ||
    ' p_result := p_anydata2.getobject(p_value_2);' ||
    chr(10) || 'END;'
    USING p_anydata;
    END;
    script 3: comment statment "p_result := p_anydata2.getobject(p_value_2);", it works ok.
    DECLARE
    p_anytype anytype;
    p_anydata anydata;
    p_value_1 VARCHAR2(4000);
    p_value_2 ob_test;
    p_result PLS_INTEGER;
    BEGIN
    anytype.begincreate(dbms_types.typecode_object, p_anytype);
    p_anytype.addattr('A1',
    dbms_types.typecode_varchar2,
    NULL,
    NULL,
    4000,
    NULL,
    NULL,
    NULL);
    p_anytype.addattr('A2',
    dbms_types.typecode_object,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    anytype.getpersistent('HR', 'OB_TEST'));
    p_anytype.endcreate();
    anydata.begincreate(p_anytype, p_anydata);
    p_anydata.setvarchar2('abc');
    p_anydata.setobject(OB_TEST('abc'));
    p_anydata.endcreate;
    EXECUTE IMMEDIATE 'DECLARE' || chr(10) ||
    ' p_anydata2 anydata := :1;' || chr(10) ||
    ' p_value_1 VARCHAR2(4000);' || chr(10) ||
    ' p_value_2 OB_TEST;' || chr(10) ||
    ' p_result PLS_INTEGER;' || chr(10) || 'BEGIN' ||
    chr(10) || ' p_anydata2.piecewise;' || chr(10) ||
    ' p_result := p_anydata2.getvarchar2(p_value_1);' ||
    chr(10) ||
    ' /*p_result := p_anydata2.getobject(p_value_2);*/' ||
    chr(10) || 'END;'
    USING p_anydata;
    END;
    Could someone tell me how to solve this problem.
    Thanks a lot.
    Daniel

  • Problem in Update statement using Execute Immediate

    Hi All,
    I am facing problem in update statement.
    I am creating dynamic sql and use "execute immediate" statement to execute a update statement.
    But it is not updating any thing there in the table.
    I have created a query like :
    update_query='Update '|| Table_Name ||' t set t.process_status =''Y'' where t.tid=:A';
    Execute immediate update_query using V_Id;
    commit;
    But it is not updating the table.
    I have a question , is execute immediate only does insert and delete?
    Thanks
    Ashok

    SQL> select * from t;
                     TID P
                     101 N
    SQL> declare
      2     V_Id          number := 101;
      3     Table_Name    varchar2(30) := 'T';
      4     update_query  varchar2(1000);
      5  begin
      6     update_query := 'Update '|| Table_Name ||' t set t.process_status =''Y'' where t.tid=:A';
      7     Execute immediate update_query using V_Id;
      8     commit;
      9  end;
    10  /
    PL/SQL procedure successfully completed.
    SQL> select * from t;
                     TID P
                     101 Y                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Have problem when using EXECUTE IMMEDIATE.

    Hi, i'm new here... i having problem when trying to use execute immediate statement... :(
    procedure code as below:
    create procedure copy_row(
    p_table varchar2,
    p_key varchar2,
    p_keyval varchar2,
    p_user varchar2,
    p_frmto varchar2 default 'FROM')
    IS
    V_SQL VARCHAR2(500);
    BEGIN
    if upper(p_frmto)='FROM' then
    V_SQL:='INSERT INTO '||P_TABLE||
    ' SELECT * FROM '||P_USER||'.'||P_TABLE||' WHERE '||P_KEY||' = '''||P_KEYVAL||'''';
    elsif upper(p_frmto)='TO' then
    V_SQL:='INSERT INTO '||P_USER||'.'||P_TABLE||
    ' SELECT * FROM '||P_TABLE||' WHERE '||P_KEY||' = '''||P_KEYVAL||'''';
    end if;
    EXECUTE IMMEDIATE V_SQL;
    exception
    when others then
    raise_application_error(-20000,'PROCEDURE: COPY_ROW - UNABLE TO COPY ROWS! SQL='||V_SQL,TRUE);
    end;
    is there any limitation on using EXECUTE IMMEDIATE command? i need to use procedure because i'm using old form builder.... but the database server was 9i which able to use this command, so... i decide to use procedure....
    i've done some testing on this.... assume the structure of schema1.table1 and schema2.table1 are same....
    SQL> CREATE PROCEDURE TESTING IS
    2 BEGIN
    3 exeCute IMMEDIATE 'INSERT INTO schema1.table1 SELECT * FROM schema2.table1 WHERE column1 = ''abc''';
    4 END;
    5 /
    Procedure created.
    SQL> BEGIN
    2 TESTING;
    3 END;
    4 /
    BEGIN
    ERROR at line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at "SCHEMA1.TESTING", line 3
    ORA-06512: at line 2
    any idea?? or have better solution other than this?
    database server:9i
    sqlplus:SQL*Plus: Release 8.0.6.0.0

    Do you have an access to tables you are going to insert into / select from ?
    Dynamic SQL checks the access permissions at runtime, not at the compilation stage:
    SQL> create user master identified by master default tablespace users temporary
      2  tablespace temp;
    User created.
    SQL> alter user master quota unlimited on users;
    User altered.
    SQL> grant create session to master;
    Grant succeeded.
    SQL> grant create table to master;
    Grant succeeded.
    SQL> grant create procedure to master;
    Grant succeeded.
    SQL> conn master/master
    Connected.
    SQL> create procedure wrong_prc
      2  is
      3  begin
      4   execute immediate 'insert into master.t select * from scott.t';
      5  end;
      6  /
    Procedure created.
    SQL> create table t (id number);
    Table created.
    SQL> exec wrong_prc;
    BEGIN wrong_prc; END;
    ERROR at line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at "MASTER.WRONG_PRC", line 4
    ORA-06512: at line 1
    SQL> conn scott/tiger
    Connected.
    SQL> grant select on t to master;
    Grant succeeded.
    SQL> conn master/master
    Connected.
    SQL> exec wrong_prc;
    PL/SQL procedure successfully completed.
    SQL> select * from t;
            ID
             1And don't use literals in dynamic SQL - you should use binding variables instead.
    Rgds.

  • Delete From More than 1 table without using execute immediate

    Hi,
    Am new to PL/SQL, I had been asked to delete few of the table for my ETL jobs in Oracle 10G R2. I have to delete(truncate) few tables and the table names are in another table with a flag to delete it or not. So, when ever I run the job it should check for the flag and for those flag which is 'Y' then for all those tables should be deleted without using the Execute Immediate, because I dont have privilages to use "Execute Immediate" statement.
    Can anyone help me in how to do this.
    Regards
    Senthil

    Then tell you DBA's, or better yet their boss, that they need some additional training in how Oracle actually works.
    Yes, dynamic sql can be a bad thing when it is used to generate hundreds of identical queries that differ ony in the literals used in predicates, but for something like a set of delte table statements or truncate table statements, dynamic sql is no different in terms of the effect on the shared pool that hard coding the sql statements.
    This is a bad use of dynamic sql, because it generates a lot of nearly identical statements due to the lack of bind variables. It is the type of thing your DBA's should, correctly, bring out the lead pipe for.
    DECLARE
       l_sql VARCHAR2(4000);
    BEGIN
       FOR r in (SELECT account_no FROM accounts_to_delete) LOOP
          l_sql := 'DELETE FROM accounts WHERE account_no = '||r.account_no;
          EXECUTE IMMEDIATE l_sql;
       END LOOP;
    END;This will result in one sql statement in the shared pool for every row in accounts_to_delete. Although there is much else wrong with this example, from the bind variable perspective it should be re-written to use bind variables like:
    DECLARE
       l_sql  VARCHAR2(4000);
       l_acct NUMBER;
    BEGIN
       FOR r in (SELECT account_no FROM accounts_to_delete) LOOP
          l_sql := 'DELETE FROM accounts WHERE account_no = :b1';
          EXECUTE IMMEDIATE l_sql USING l_acct;
       END LOOP;
    END;However, since you cannot bind object names into sql statements, the difference in terms of the number of statements that end up in the shared pool between this:
    DECLARE
       l_sql VARCHAR2(4000);
    BEGIN
       FOR r in (SELECT table_name, delete_tab, trunc_tab
                 FROM tables_to_delete) LOOP
          IF r.delete_tab = 'Y' THEN
             l_sql := 'DELETE FROM '||r.table_name;
          ELSIF r.trunc_tab = 'Y' THEN
             l_sql := 'TRUNCATE TABLE '||r.table_name;
          ELSE
             l_sql := NULL;
          END IF;
          EXECUTE IMMEDIATE l_sql;
       END LOOP;
    END;and something like this:
    BEGIN
       DELETE FROM tab1;
       DELETE FROM tab2;
       EXECUTE IMMEDIATE 'TRUNCTE TABLE tab3';
    END;or this as a sql script
    DELETE FROM tab1;
    DELETE FROM tab2;
    TRUNCTE TABLE tab3;is absolutley nothing.
    Note that if you are truncating some of the tables, and wnat/need to use a stored procedure, you are going to have to use dynamic sql for the truncates anyway since trncate is ddl, and you cannot do ddl in pl/sql wiothout using dynamic sql.
    John

  • Error while insert data using execute immediate in dynamic table in oracle

    Error while insert data using execute immediate in dynamic table created in oracle 11g .
    first the dynamic nested table (op_sample) was created using the executed immediate...
    object is
    CREATE OR REPLACE TYPE ASI.sub_mark AS OBJECT (
    mark1 number,
    mark2 number
    t_sub_mark is a class of type sub_mark
    CREATE OR REPLACE TYPE ASI.t_sub_mark is table of sub_mark;
    create table sam1(id number,name varchar2(30));
    nested table is created below:
    begin
    EXECUTE IMMEDIATE ' create table '||op_sample||'
    (id number,name varchar2(30),subject_obj t_sub_mark) nested table subject_obj store as nest_tab return as value';
    end;
    now data from sam1 table and object (subject_obj) are inserted into the dynamic table
    declare
    subject_obj t_sub_mark;
    begin
    subject_obj:= t_sub_mark();
    EXECUTE IMMEDIATE 'insert into op_sample (select id,name,subject_obj from sam1) ';
    end;
    and got the below error:
    ORA-00904: "SUBJECT_OBJ": invalid identifier
    ORA-06512: at line 7
    then when we tried to insert the data into the dynam_table with the subject_marks object as null,we received the following error..
    execute immediate 'insert into '||dynam_table ||'
    (SELECT

    887684 wrote:
    ORA-00904: "SUBJECT_OBJ": invalid identifier
    ORA-06512: at line 7The problem is that your variable subject_obj is not in scope inside the dynamic SQL you are building. The SQL engine does not know your PL/SQL variable, so it tries to find a column named SUBJECT_OBJ in your SAM1 table.
    If you need to use dynamic SQL for this, then you must bind the variable. Something like this:
    EXECUTE IMMEDIATE 'insert into op_sample (select id,name,:bind_subject_obj from sam1) ' USING subject_obj;Alternatively you might figure out to use static SQL rather than dynamic SQL (if possible for your project.) In static SQL the PL/SQL engine binds the variables for you automatically.

  • No of record updated using EXECUTE IMMEDIATE

    Hi,
    I have a scenario where I am using :
    EXECUTE IMMEDIATE 'UPDATE TEST1 SET NAME='ABC' WHERE CODE='001''
    I want to know how many records updated using EXECUTE IMMEDIATE
    Any help will be needful for me
    Edited by: user598986 on Sep 23, 2009 3:33 AM

    user598986 wrote:
    I want to know how many records updated using EXECUTE IMMEDIATESame as usual - SQL%ROWCOUNT:
    SQL> set serveroutput on
    SQL> begin
      2  execute immediate 'update emp set sal=sal where ename = ''KING''';
      3  dbms_output.put_line(sql%rowcount);
      4  end;
      5  /
    1
    PL/SQL procedure successfully completed.
    SQL> SY.

  • Selecting data from a table using Execute Immediate in 9i

    Hi,
    I was wondering how I would be able to do a SELECT on a table using EXECUTE IMMEDIATE. When I tried it (with the proc below), I got the following below. Can anyone tell me what I am doing wrong?
    Using Scott/Tiger I tried this:
    SQL> ed
    Wrote file afiedt.buf
    1 CREATE OR REPLACE PROCEDURE P2
    2 IS
    3 v_SQL VARCHAR2(100);
    4 BEGIN
    5 v_SQL := 'Select * from Emp';
    6 EXECUTE IMMEDIATE v_SQL;
    7* END;
    SQL> /
    Procedure created.
    SQL> exec p2
    PL/SQL procedure successfully completed.
    SQL> set serveroutput on
    SQL> exec p2
    PL/SQL procedure successfully completed.
    SQL>
    Thanks in advance.
    Sincerely,
    Nikhil Kulkarni

    1 CREATE OR REPLACE PROCEDURE P2
    2 IS
    3 v_SQL VARCHAR2(100);
    erec emp%rowtype;
    4 BEGIN
    5 v_SQL := 'Select * from Emp';
    6 EXECUTE IMMEDIATE v_SQL into erec;
    7* END;
    SQL> /

  • Using EXECUTE IMMEDIATE with an NVARCHAR2 parameter

    Hi everyone,
    In the system I'm working on, my stored procedure receives an NVARCHAR2 parameter which contains a complete SQL statement. e.g.
    'UPDATE SomeTable SET SomeTable.Value = 0'
    I want to be able to execute this dynamically, using EXECUTE IMMEDIATE, but I've encountered a problem where this is apparently not supported (because the string is Unicode).
    It is crucial that the string stays as Unicode, because of the data that may possible be baked into the SQL statement, and so casting it off to a VARCHAR2, or changing the parameter type, is not acceptable.
    Is there a work-around for this issue? Even if it has a performance hit, it will be better than nothing :)
    I've tried something like this;
    declare
    myVal VARCHAR2(256);
    begin
    myVal := 'UPDATE SomeTable SET SomeTable.Value = 2';
    execute immediate 'BEGIN :x; END;' using myVal;
    end;
    But I get an error;
    "bind variable 'X' not allowed in this context"
    Has anyone any ideas?
    Thanks for your help,
    Chris

    uhmm, I'm not sure if this is a valid testcase. the string could still be converted into ascii or we8iso8859p1 or whatever 1byte-character set you want.
    What I think you should test is a two-byte character as part of SQL, PL/SQL resp. as in SQL all words are defined you can not enlarge it with a 2byte word. But in PL/SQL you could define your own variable. If this variable name itself contains a 2byte character, I guess it will fail.
    (I have used l_vär and l_vér as variable names in my example)
    Message was edited by:
    Leo Mannhart
    According to the PL/SQL Reference Guide PL/SQL consists of:
    PL/SQL programs are written as lines of text using a specific set of characters:
    Upper- and lower-case letters A .. Z and a .. z
    Numerals 0 .. 9
    Symbols ( ) + - * / < > = ! ~ ^ ; : . ' @ % , " # $ & _ | { } ? [ ]
    Tabs, spaces, and carriage returns
    This seems no longer up-to-date as I could define a variable l_vär for instance as long as I use a 1byte char set (like iso8859p1). The same variable name as a n-byte char set like UTF-8 will give an error as my example shows.

  • Problem using EXECUTE IMMEDIATE

    Hi,
    I am running the following procedure..
    table emp ( empno number,ename varchar2 , dept varchar2 )
    CREATE OR REPLACE PROCEDURE Sp_Test11 ( p_dept IN VARCHAR2 )
    IS
    m_count               NUMBER               :=     NULL;
    m_sql_query               VARCHAR2(32767) := 'SELECT COUNT(*) INTO m_count FROM emp WHERE dept = ';
    BEGIN
    m_sql_query := m_sql_query||''''||p_dept||''''||';';
         EXECUTE IMMEDIATE m_sql_query ;
    END Sp_Test11;
    I am getting the "Invalid character" error on execute immediate statement when i debug ..
    Please guide.

    venkata wrote:
    Use RETURN or RETURNING INTO Keywords in execute immediate statement.RETURNING INTO is used with INSERT/UPDATE/DELETE statements when there will be triggers that will populate something on the table after an insert or update etc. e.g. when you insert a new record and you want to return the primary key that is automatically generated from a sequence so you can use it in your code for something else.
    If you are SELECTing data then you would use the INTO keyword as Gj demonstrated.
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_cnt number;
      3  begin
      4    execute immediate 'select count(*) from x' returning into v_cnt;
      5* end;
    SQL> /
    declare
    ERROR at line 1:
    ORA-06547: RETURNING clause must be used with INSERT, UPDATE, or DELETE statements
    ORA-06512: at line 4
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_cnt number;
      3  begin
      4    execute immediate 'select count(*) from x' into v_cnt;
      5* end;
    SQL> /
    PL/SQL procedure successfully completed.
    SQL>It's amazing how many people are just jumping in here with wrong answers.

  • Using EXECUTE IMMEDIATE with XML

    Database version : 10.2.0.3.0 - 64bi
    Hi All,
    I have a xml which is stored in a table, xmltype column.
    i have target insert tables whose column names and xml nodes are same.
    using all_tab_columns table i will generate columns to be passed to xmltable.
    all these data i will store in variables and finally pass to xmltable as below
    just want to know using execute immediate is good to use in XML?
    SQL_STMT := 'insert into '||table_name|| ' ( '||V_COLUMN_NAME||')';
    SQL_STMT := SQL_STMT ||' SELECT ' ||V_XTAB_COLUMN_NAME ||
    ' FROM TO_XML,
    XMLTABLE(' ||v_xpath||
    'PASSING XML_VALUE
    columns ' || V_COLUMNS_DATA_TYPE
    ||') XTAB
    WHERE Seq_NO = ' || P_SEQUENCE_NO ;
    EXECUTE IMMEDIATE SQL_STMT ;
    Thanks and Regards,
    Rubu

    1) is it OK? As I stated above, it can be made to work. It would not be my first choice, but then none of us here know the full details as well as you do so maybe there is a compelling reason to use dynamic SQL.
    Here is the documentation for [url http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/executeimmediate_statement.htm#LNPLS01317]EXECUTE IMMEDIATE.
    Actually now I finally realize your XML resides in table TO_XML so that means you won't be putting the actual XML into the shared pool via an incorrectly written dynamic SQL statement at least. That is what Odie and I were first concerned about with dynamic SQL usage, that the XML would be hard-coded into your SQL_STMT variable. You are simply changing the columns (in 3 locations). With that setup, you have no need for (nor can use) bind variables. The overall issue of dynamic SQL being slightly slower than static SQL still exists as the SQL statement will first have to be parsed and validated.
    A larger issue in terms of performance is how 10.2 handles XMLTypes. If the underlying XML is large, XMLTable performance degrades quickly. Options around this are to parse the XML in PL/SQL or to upgrade to some version of 11 and use SECUREFILE BINARY XML as the underlying storage structure for the TO_XML.XML_VALUE column.

  • How to run a EXECUTE IMMEDIATE statement in a Interactive Report

    Hello all!!
    I need to make a dinamic construction of a query to execute in a Interactive Report, but the Region Source only allows simple SELECT statements. There is any way to run a EXECUTE IMMEDIATE statement in a Interactive Report Region Source?
    Regards Pedro.

    Thank you Andy for your reply.
    I have been testing for a while the use of a collection in the interactive report but i am unable to load data in the interactive report.
    I created the collection successfully in the SQL Commands with the code:
    declare
    v_sql varchar2(32000);
    begin
    v_sql:='select ename, job from emp';
    APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY('coleccao_emp',v_sql,'NO' );
    end;
    I tested successfully the creation of the collection with the query:
    SELECT c001, c002
    FROM APEX_collections
    WHERE collection_name = 'COLECCAO_EMP'
    My problem is: the data of the collection are returned in the SQL Commands but when i run the query statament in an interactive report, report or even a Pl/Sql region in my application the data aren't displayed, only the message (No data found).
    Can someone explain why, besides the collection is populated the interactive can not print the results.
    Regards Pedro.

  • How do I update a date field through CMP

    I wonder how to update a date field through CMP.
    For example, I can't update an employee table with following statement.
    employee.setHire_date('2002-03-20');
    Thanks,

    Thats correct......
    Try using the following code....
    String strDate ="2002-03-20";
    String date_fmt = "yyyy-MM-dd";
    java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat(date_fmt);
    java.util.Date hireDate =null;
    hireDate =(Date) sdf.parse(strDate);
    employee.setHire_date(hireDate);
    Hope this helps
    Cheers
    --Venky                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Create temp table using EXECUTE IMMEDIATE

    Is there any performance issue in creating globally temp table
    using EXECUTE IMMEDIATE or creating globally temp table from
    SQL PLUS.
    Any response will be greatly appreciated.
    null

    Anish,
    Creating tables is likely to be an expensive operation.
    Performance issues can only be considered in comparison to
    alternatives.
    Alternatives include: PLSQL tables, cursors and/or recoding so
    that tmp tables are not required. (One of our consultants reckons
    that sqlserver temp tables are usually used to get around
    limitations in sqlserver, ie slightly more complicated sql
    statements could be used instead of simpler sql and temporary
    tables).
    I would think creating the temp table once during sqlplus would
    be cheaper than creating and deleting it repeatedly at run time.
    Note that EXECUTE IMMEDIATE may do an implicit commit (dbms_sql
    certainly does). This may be got over my using the PRAGMA
    AUTONOMOUS_TRANSACTION; direction which places a
    procedure/function in a seperate transaction.
    Turloch
    P.S. We have some difficulty in getting information back from the
    field/customer sites. If you have questions and answers that are
    likely to be useful to other Oracle Migration Workbench
    users, and migrators in general, please send them in for possible
    inclusion in our Frequently Asked Question list.
    Oracle Migration Workbench Team
    Anish (guest) wrote:
    : Is there any performance issue in creating globally temp table
    : using EXECUTE IMMEDIATE or creating globally temp table from
    : SQL PLUS.
    : Any response will be greatly appreciated.
    Oracle Technology Network
    http://technet.oracle.com
    null

  • Using EXECUTE IMMEDIATE for DML

    What benefit is there to use EXECUTE IMMEDIATE for an UPDATE statement like the one below.
    EXECUTE IMMEDIATE 'UPDATE mytable SET bonus = v_bonus(i)
                       WHERE empid =:empid AND sal =:sal'
                              USING v_empid(n),v_sal(i);This UPDATE sql is not dynamically created. So is there any performance benefit associated with using
    EXECUTE IMMEDIATE for this UPDATE? Can't i just use a normal UPDATE without EXECUTE IMMEDIATE?

    Ran these same tests with SQL_Trace turned on, ran the trace files through tkprof and look at what it tells us:
    declare
    begin
    for i in 1 .. 100000 loop
    gso_prueba_a();
    end loop;
    end;
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.07       0.08          0          0          0           1
    Fetch        0      0.00       0.00          0          0          0           0
    total        2      0.07       0.08          0          0          0           1Now a slow one
    declare
    begin
    for i in 1 .. 100000 loop
    execute immediate 'call gso_prueba_b()';
    end loop;
    end;
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1     36.07      36.54          0          0          0           1
    Fetch        0      0.00       0.00          0          0          0           0
    total        2     36.07      36.54          0          0          0           1but with this slow one, we see LOTS of recursive SQL - the 'call gso_prueba_b' is getting parsed a gazillion times with the resulting CPU consumption
    SQL ID : 1uu09hhqdp1yz
    call gso_prueba_b()
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute  99989      2.42       2.72          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total    99990      2.42       2.72          0          0          0           0
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 91     (recursive depth: 1)
    SQL ID : dcstr36r0vz0d
    select procedure#,procedurename,properties,itypeobj#
    from
    procedureinfo$ where obj#=:1 order by procedurename desc, overload# desc
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2      0.00       0.00          0          4          0           1
    total        4      0.00       0.00          0          4          0           1Lots, lots more like this last one but having different SQL ID
    By wrapping the procedure call in a dynamically created anonymous block, you are incurring LOTS of overhead.
    What is it that you are trying to simulate.
    What are you trying to do?

Maybe you are looking for

  • HOW CAN I DOWNLOAD THE RIGTONES THAT I PURCHASE

    HI MY NAME IS JOAQUIN I PURCHASE A FEW HOURS AGO SOME RINGTONES BUT I ALREADY RECEIVED ONLY 1 OF THE 5 RINGTONES WHAT CAN I DO ?????

  • Mini-dvi to svga

    Hey, my name is Chuck and I have a macbook and a moniter. The moniter is only svga and I couldn't find any cable that connects mini-dvi (macbook) to svga. Is there any possible way to connect them?

  • UDF or Graphical Mapping

    Hello All I have a requirement like below: Source fields               TXT                                  AddTXT Target Field Node I want to create Node as many times as AddTXT comes with value Concatinate(TXT+AddTXT). This I have achieved not a is

  • Please help me in export

    i have 3 database in . 2 in oracle 9.2.0.6.0(wps,wpsd) and 1 in 10.2.0(orcl) . iam try ing to take export in oracle 9.2.0.6.0 in win2003 . step that i do is set oracle_sid=wps export us/password file=d:\my_dump full=y the error i got is PLS-0032 COMP

  • Friends, Link for Java Material, Practice Test......

    Hi friends, One of my friend has suggest me this below site for Online Learning, Practice Test, etc.. Please visit this site and register your self there www.elearnonnet.com Registration is free of charges. You can get lots of free materials like Ora