Dynamic SQL in trigger

In a before insert/update on each row trigger I do the following:
I loop over the user_tab_columns to get the column names for a table.
In the loop I want to call :new.<columnname> with <columnname> a variable in which I stocked the current columnname.
It has to be dynamic, a direct call to the column does not solve my problem.
How can this be done?
Thanks in advance!
Marianne

Have a look at
re:Dynamic references to trigger vars :new and :old
Cheers,
Alex

Similar Messages

  • Executing dynamic SQL in trigger

    Hi !
    I just wanted to ask the community if it is ok using dynamic SQL
    with execute immediate in triggers, like:
    if (deleting or updating)
    and nvl(:old.col_val, 0) != 0
    then
    /* Update */
    sSql :=
    'update TMP_STAT_TEST ' ||
    'set col_val_' || to_char(:old.col_id) || ' = col_val_' ||
    to_char(:old.col_id) || ' - :1 ';
    execute immediate sSql using :old.col_val;
    end if;
    All dyn SQL inside the trigger does not reference the triggered
    table, so I will not get a mutating trigger.
    Thanks for your feedback.
    Stefan.

    Hi Andrew !
    I have a "master" table with date and amount and some more
    columns. I have a statistic table which must get updated
    accordingly each time the master table is changed (ins, upd,
    del). In this stats table there a cols like "sum_2000, sum_2001"
    etc. The dynamic statement depends on date to figure out the
    column name for the sum_yyyy cols, and amount will be
    added/subtracted. Of course there is a check that the trigger
    cannot handle when the year of the date is smaller than 2000 or
    greater than 2009.
    That's why I want to use dyn SQL.
    Stefan.

  • Dynamic sql in a trigger ...please help

    HI All,
    I've got a really large table called 'shop' of the form
    id number, product1_cost number, product2_cost number,product3_cost, product4_cost....and so on until product20_cost,
    product1_desc, product2_desc....and so so on until..product20_desc, active, start_date, end_date, usercreated,
    useramended.
    I have now created a new application. The new table is called 'products' which has an id, cost, description, oldproductid, shopid
    I need a trigger on the table shop so that if anyone uses the old application, it automatically creates the product rows in my new table 'products'
    Not all the product fields on the 'shop' table have data so I only want to migrate data if necessary.
    The trigger would do the following:
    1. Loop through all the products, if the product was updated and product number does not exist on 'products.oldproductid' then create a new record in products
    2. If product was updated and product number does exist then simply update the product details.
    I have got the trigger to work with product1. However, I'm finding it difficult to write some sort of dynamic sql that would
    do the same check on all 20 products without having to repeat the code 20 times.
    can someone help?
    CREATE OR REPLACE TRIGGER TR_PRODCOST
    AFTER UPDATE ON SHOP
    FOR EACH ROW
    DECLARE
    v_oldproductid products.oldpackageid%TYPE;
    v_datedl products.datedl%TYPE;
    v_product_sq number;
    v_status number := 1;
    v_cost number(11, 2);
    v_old_pkg number:= :old.product1_cost;
    v_new_pkg number:= :new.product1_cost;
    v_old_desc varchar2(100):= :old.product1_desc;
    v_new_desc varchar2(100):= :new.product1_desc;
    v_old_shop varchar2(10):= :old.shopid;
    v_new_shop varchar2(10):= :new.shopid;
    CURSOR get_newproduct_cur IS
    SELECT p.oldproductid, p.datedl
    FROM products p
    WHERE p.shopid = v_new_shop
    AND p.oldproductid = 1;
    BEGIN
    IF nvl(v_new_pkg, -1) <> nvl(v_old_pkg, -1) THEN
    OPEN get_newproduct_cur;
    FETCH get_newproduct_cur
    INTO v_oldproductid, v_datedl;
    IF get_newproduct_cur%NOTFOUND THEN
    v_oldproductid := null;
    v_datedl := null;
    END IF;
    CLOSE get_newproduct_cur;
    IF v_oldproductid is null THEN
    SELECT SEQ_products.nextval INTO v_product_sq FROM dual;
    INSERT into products p
    (product_ID,
    SHOPID,
    DESCRIPTION,
    COST,
    DATECR,
    USERCR,
    OLDproductID,
    SHORT_DESCRIPTION)
    VALUES
    (v_product_sq,
    v_new_shop,
    v_new_desc,
    v_new_pkg,
    sysdate,
    'OLFORMS',
    1,
    v_new_desc);
    ELSE
    IF v_new_pkg is null THEN
    UPDATE products p
    set p.datedl = sysdate,
    p.cost = 0.00
    WHERE p.shopid = v_new_shop
    AND p.oldproductid = 1;
    ELSE
    UPDATE products p
    set p.cost = v_new_pkg,
    p.datedl = null,
    WHERE p.shopid = v_new_shop
    AND p.oldproductid = 1;
    END IF;
    IF v_new_desc = v_old_desc THEN
    v_status := 1;
    ELSE
    UPDATE products p
    SET p.description = v_new_desc
    WHERE p.shopid = v_new_shop
    AND p.oldproductid = 1;
    END IF;
    END IF;
    ELSE
    END IF;
    END IF;
    END;

    Hi All,
    Thanks about your advice on the relational design. However, this is only a temporary fix. The old shop table was created about 10 years ago by someone else. Our users have to use the old pages for about 2-3 weeks and therefore I need a quick fix that will create the products on the new tables.
    The other problem I have is that another powerbuilder based applicated also uses the same tables and that application is being modified to use the new tables but not until another 3 weeks. To ensure both systems are available in parallel, I have to implement this temporary solution.
    B_Binoy, you seem you have a solution there but I didn't quite get it. I tried putting the whole pl/sql block in a string, replacing the '1' in product 1 using a variable x and then using execute immediate but because of the :new and :old bind variables, it kept giving me errors like 'variables not bound' etc. If you don't mind, please can you expand on your solution?
    Many Thanks

  • Convert a trigger format into a  stored procedure using Dynamic Sql

    Hi everyone,
    ihave table
    Table_NAME_ABCD contains
    i have a trigger Table_NAME_ID,ROW_CREATED_DATE,ROW_CREATED_BY,ROW_CHANGED_DATE,ROW_CHANGED_BY,UNQ columns
    i am populating Table_NAME_ID(primary_key) using sequencer in the below mentioned trigger.
    and for this table i have created IU trigger for inserting or updating trigger will fire
    create or replace
    TRIGGER "Table_NAME_IU_TRG" BEFORE INSERT OR UPDATE ON Table_NAME_ABCD FOR EACH ROW
    BEGIN
    If inserting then
    If :new.Table_NAME_ID is NULL THEN
    SELECT Table_NAME_ID_ABCD_SEQ.NEXTVAL INTO :NEW.Table_NAME_ID FROM DUAL;
    end if;
    if :new.ROW_CREATED_DATE is NULL then
    :new.ROW_CREATED_DATE := SYSDATE;
    end if;
    if :new.ROW_CREATED_BY is NULL then
    :new.ROW_CREATED_BY := USER;
    end if;
    if :new.ROW_CHANGED_DATE is NULL then
    :new.ROW_CHANGED_DATE := SYSDATE;
    end if;
    if :new.ROW_CHANGED_BY is NULL then
    :new.ROW_CHANGED_BY := USER;
    end if;
    if :new.UNQ is NULL then
    :new.UNQ := SYS_GUID():
    end if;
    end if;
    If updating then
    :new.ROW_CHANGED_DATE := SYSDATE;
    :new.ROW_CHANGED_BY := USER;
    end if;
    END;
    above mentioned table along with trigger is same format for ~100 different tables i have been created.
    i want a stored procedure in side it above mentioned trigger (i.e., for inserting or updating )code should be written with Dynamic Sql so that when ever i am passing Tablename as a parameter it should work.
    please suggest me.

    What is new since this thread?
    Stored procedure instead of Trigger

  • How to mention numbers in array while creating dynamic sql

    Hi,
    I am creating a dynamic sql and in that I am selecting some rows from the table and storing it into the array.
    I am firing this sql statement within trigger.
    But i got the error:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    I took the same sql statement (the one which was created dynamically) in the procedure and tried to run it but it gave me the same error.
    =========================================================
    Begin
    type NewValueArray is table of varchar2(4000);
    nVal_Array NewValueArray;
    Begin
    Select
    DISCOVERYHOSTNAME,
    DISCOVERYMACPRIMARYPHYSICAL,
    DISCOVERYSERIALNUMBER
    into
    nVal_Array(1),
    nVal_Array(2),
    nVal_Array(3)
    from ALT_42_Consolidated
    where rowid = 'AAEWNEABXAAAAkxAAA';
    EXCEPTION
    WHEN others THEN
    Raise;
    End;
    =========================================================
    I tried using to_number but still the same error.
    Can some body please inform me where I am goofing.
    Thanks!

    I got a different error, but you need to initialise your nval_array and make sure it can hold three values. The following should work:
    declare
      type NewValueArray is table of varchar2(4000);
      nVal_Array NewValueArray := NewValueArray();
    Begin
      nval_array.extend(3);
      Select col1, col2, col3
      into nVal_Array(1), nVal_Array(2), nVal_Array(3)
      from tab1
      where rowid = 'AAAGJZAAGAAAAAWAAV';
    EXCEPTION
      WHEN others THEN
        Raise;
    End;
    /

  • Using Native Dynamic SQL in Forms

    Can Native Dynamic SQL be used in Forms 5.0 or Forms 6.0? (Database 8.1.6.0.0)
    I have tried the following code (examples below) from the PL/SQL User's Guide and Reference Release 8.1.6 and the Metalinks Note: 62592.1 and the trigger/procedure (in Forms) will not compile. I appreciate any help given.
    Example1:
    (I have a table named temp_jane with a column named companies and a value 'Hello'. When compiling, I receive the error: 'Error 103 at line 8, column 11 Encountered the symbol ''IMMEDIATE" when expecting one of the following :=.(@%; ')
    declare
    str varchar2( 200 );
    val varchar2( 20 );
    ret temp_jane%rowtype;
    begin
    str := 'select company from temp_jane where company = :b1';
    val := 'Hello';
    execute immediate str into ret using val;
    message('Value fetched from table: '&#0124; &#0124;ret.company);
    end;
    Example2:
    (Here is the real issue, I don't know what the select statement, so I need to be able to assign a variable. When compiling, I receive the error: 'Error 103 at line 28, column 21 Encountered the symbol "VSQLSTATEMENT" when expecting one of the following: select ').
    declare
    type ItemsControlCurTyp is ref cursor;
    ItemsCur ItemsControlCurTyp;
    ItemsRec Items%rowtype;
    vSQLStatement varchar2( 5000 );
    vExecuteSQL varchar2( 5000 );
    vNumRows integer;
    vValue varchar2( 2000 );
    vFirstOne varchar2( 1 ) := 'Y';
    vRetval varchar2( 2000 );
    begin
    -- Display the column prompts with the right text.
    set_item_property( 'ITEMS_AVAILABLE.NDB_VALUE', PROMPT_TEXT, :ITEMS_CONTROL.AVAILABLE_LABEL );
    set_item_property( 'ITEMS_CHOSEN.NDB_VALUE', PROMPT_TEXT, :ITEMS_CONTROL.CHOSEN_LABEL );
    -- Save the original version of CHOSEN_STRING in case the user reverts or cancels.
    :ITEMS_CONTROL.CHOSEN_STRING_ORIG := :ITEMS_CONTROL.CHOSEN_STRING;
    vSQLStatement := :ITEMS_CONTROL.SELECT_STATEMENT;
    vExecuteSQL := vSQLStatement;
    -- Open the cursor
    open ItemsCur for vSQLStatement;

    Hi JTaylor
    You cannot use NDS in Client side (Developer). You have to use DBMS_SQL only.
    Regards
    A K Srinivasan
    Oracle.

  • Dynamic sql newbie question

    I am trying to do an insert statement dynamically inside a trigger. I want to concatenate the string 'IRFFFF' with substr(:new.stvterm_code,1,4).
    Example: :new.stvterm_code is 200509... I only want 'IRFFFF2005'.
    Here is my code....please help. The problem lies with the substr function and the :new operator.
    code := ' ''IRFFFF'' || substr(:NEW.stvterm_code,1,4) ';
    varsql := 'INSERT INTO ' || val_table || list || 'VALUES
    (' || code || ',''y'',sysdate)';
    cursor_handle := dbms_sql.open_cursor;
    dbms_sql.parse(cursor_handle, varsql, dbms_sql.native);
    feedback := dbms_sql.EXECUTE(cursor_handle);
    COMMIT; for pl/sql developer only
    dbms_sql.close_cursor(cursor_handle);
    I get the following error:
    ORA-01008: not all variables bound
    ORA-06512: at "SYS.DBMS_SYS_SQL", line 1120
    ORA-06512: at "SYS.DBMS_SQL", line 323
    ORA-06512: at "SATURN.STW_STVTERM_A_I_ROW", line 169
    ORA-04088: error during execution of trigger 'SATURN.STW_STVTERM_A_I_ROW'

    code := 'IRFFFF' || substr(:new.stvterm_code,1,4);
    varsql := 'INSERT INTO ' || val_table || list || 'VALUES(''' || code || ''',''y'',sysdate)';I would recommend though to use EXECUTE IMMEDIATE if possible, and bind variables in either case.

  • Dynamic SQL in Formula Column in OracleReports6i

    Following code is in formula column of my report. passing dynamic sql str1(actullay, this string comes from after parameter trigger form) into SQL and executing thru DBMS_SQL.PARSE function. it's failed with 'Fatal PL/SQL error occured' ...
    Coupld any one help me on this...
    function CF_1FORMULA0006 return Number is
    Credits1 NUMBER(10,2);
    str1 VARCHAR2(50) := 'AND b.PROGRAMID = 2 ';
    c1 INTEGER := dbms_sql.open_cursor;
    c2 INTEGER;
    begin
    begin
    dbms_sql.parse(c1,
    'SELECT NVL(SUM(a.AMOUNT),0) INTO Credits1' &#0124; &#0124;
    'FROM SPONSOR_TRAN_DATA a, SPONSOR b ' &#0124; &#0124;
    ' WHERE ' &#0124; &#0124;
    ' a.TRANTYPE = 41 ' &#0124; &#0124;
    ' AND a.SPONSORID = b.SPONSORID ' &#0124; &#0124;
    str1 &#0124; &#0124;
    'AND a.amount > 0 ' &#0124; &#0124;
    'AND a.timestamp >= :reportdate ' &#0124; &#0124;
    'AND a.timestamp < :reportdate + 1' ,2);
    c2 := dbms_sql.execute(c1);
    exception
    when no_data_found then
    Credits1 := 0;
    end;
    return Credits1;
    end;
    Thanks in advance......

    It looks like forms are not supporting text functions like FR yet, I gave it a try <<MemberName("<Formname>","<POV DIM Name>)>> in the formula header area and it didn't like it. It is just displaying what ever I typed in there.

  • Using dynamic sql in triggers with :OLD values

    i need to record all deleted rows from an entire schema in a single table. for that matter i created a function that receives a table name and generate an insert command according to it's primary key columns. i call this function in the table triggers. in order to insert the old values before the delete i use :OLD with "execute immediate" as followed :
    create or replace trigger trg_some_tbl_bd
    before delete on some_tbl
    for each row is
    declare
    v_sql varchar2(4000);
    begin
    v_sql := generate_insert_command('some_table');
    execute immediate v_sql;
    end;
    the return value from "generate_insert_command" function is the string:
    insert into deleted_table (table_name , date , pk1 , pk2) values
    ('some_table' , sysdate , :OLD.pk1 , :OLD.pk2)
    the execute immediate command notice the :OLD and looks for bind variables.
    i need to know i can i bypass that. i tried looking for escape characters but couldent find any...
    i would appriciate any help , it's kynda urgent
    Thanks !

    I don't believe this is going to work. Even if you could get around the fact that :old looks like a bind variable, the :old values are not visible to the dynamic SQL statement, they're like local variables in that respect.
    If you wanted to pass old values in, those values would have to be passed in as bind variables, i.e.
    EXECUTE IMMEDIATE v_sql USING :old.pk1, :old.pk2which defeats the purpose of using dynamic SQL.
    Since you have to create a trigger for each table, I don't see why you would bother with dynamic SQL inside the trigger-- your table structure is fixed when the trigger is created. You could write dynamic SQL that generated the triggers in the first place, but the code inside the trigger should be dynamic.
    As an aside, you realize that logging every audit record into a single table creates rather massive contention issues, right? And have you considered how painful it is to query this sort of table? Have you considered other options for maintaining history like Workspace Manager? Or at least separate history tables for each table?
    Justin

  • Using dynamic SQL (native) in triggers.

    Hi All:
    As a part of client requirement, I need to capture all column data from tables when rows get deleted. I am using a single table to capture deleted column data (not concatenated but one column data per row).
    I am using native dynamic SQL as I need to get the most recent column list for any table from USER_TAB_COLUMNS table. Somehow, Oracle does not allow me to use :old.xxx syntax when doing a EXECUTE IMMEDIATE insert_statment;
    Can't I use native dynamic SQL in triggers to refer to :old and :new values?
    Thanks,
    Sankar.

    No, you cannot use NDS to refer to the :old values. You can use the data dictionary to automate the writing of the audit trigger code itself though. Hi Todd,
    Can you please explain your comment about using the data dictionary to automate writing the audit trigger code..
    Thanks.

  • Dynamic sql in forms6i

    Hi! Friends....
    In trigger WHEN-BUTTON-PRESSED wrote:
    TYPE EmpCurTyp IS REF CURSOR;
    emp_cv EmpCurTyp;
    sql_stmt VARCHAR2(10000);
    my_dato Varchar2(15) := '36';
    begin
    sql_stmt := 'SELECT.........
    WHERE ....
    AND :j';
    OPEN emp_cv FOR sql_stmt USING my_dato;
    LOOP
    FETCH emp_cv INTO :materiales_det.item...
    EXIT WHEN emp_cv%NOTFOUND;
    NEXT_RECORD;
    END LOOP;
    CLOSE emp_cv;
    end;
    but exist a message: 'Encountered the symbol "SQL_STMT" when expecting one of the following: select'
    why?
    dynamic sql is not sopported for forms 6i???
    thanks.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by antonio Pacheco ([email protected]):
    Hi! Friends....
    In trigger WHEN-BUTTON-PRESSED wrote:
    TYPE EmpCurTyp IS REF CURSOR;
    emp_cv EmpCurTyp;
    sql_stmt VARCHAR2(10000);
    my_dato Varchar2(15) := '36';
    begin
    sql_stmt := 'SELECT.........
    WHERE ....
    AND :j';
    OPEN emp_cv FOR sql_stmt USING my_dato;
    LOOP
    FETCH emp_cv INTO :materiales_det.item...
    EXIT WHEN emp_cv%NOTFOUND;
    NEXT_RECORD;
    END LOOP;
    CLOSE emp_cv;
    end;
    but exist a message: 'Encountered the symbol "SQL_STMT" when expecting one of the following: select'
    why?
    dynamic sql is not sopported for forms 6i???
    thanks.<HR></BLOCKQUOTE>
    null

  • Dynamic SQL in Triggers

    Does anyone know if it is possible to have dynamic SQL statements
    within a trigger.
    for example,
    sql_str := 'insert into log_'||table_name||'values
    (''A'',:new.descr)';
    execute immediate sql_str;
    I kept on getting an internal error as follows
    ORA-00600: internal error code, arguments: [15212], [3], [], [],
    ORA-06512: at "CDC.TG_BI_COMPANY_C", line 30
    ORA-04088: error during execution of trigger 'CDC.TG_BI_COMPANY_C'
    Thanks in advance

    Hi,
    This is a bug i think ... a long shot but let us see what the
    people at oracle have to say for this.... I Am posting it on
    metalink....
    Here is the corrected code...
    create or replace trigger atrig
    before insert on A
    For Each Row
    Declare
    a number;
    begin
    execute immediate 'insert into ' || 'a_log values(:1)'
    using :new.a;
    end;
    This works....
    Always use bind Variables in Dynamic SQl ... Good Practice ....
    Regards,
    Ganesh R

  • Constructing dynamic SQL

    Forms6000. In a when_button trigger, I've coded dynamic sql statements via the concatenation method, nested within IF statements using forms_DLL built-in. Through debugging methods have confirmed that the statements are in fact being dynamically constructed or appended. Receiving form_sucess at run time but no DML is being executed against the database after concat. It's basically a simple insert statement.
    Any thoughts?
    Thanks..

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Bob Muller ():
    Oracle recommends against doing this because it upsets the delicate balance of the internal form (gives it gas, in other words). If you want to commit, you should use the Forms built-in to commit:
    Commit_Form;
    Forms commits when the user issues a kepress that results in Commit_Form (such as the Save button) or when a trigger executes Commit_Form. You might benefit from looking at the online help topic "Post and commit transactions" which has a flowchart for everything that happens here. If you use Forms_DDL to commit, you are short-circuiting the process and anything can happen.
    Could the problem here be that you are looking at the database before the forms commit happens and hence not seeing the update yet?
    Another alternative might be to use the DBMS_SQL package instead of Forms_DDL, look at the online help.
    Yet another alternative: if you can use host variables rather than creating the insert statement, you can just put the insert statement directly into your PL/SQL code, since PL/SQL can execute INSERT directly; it cannot execute DDL (CREATE TABLE, GRANT, and so on). INSERT, UPDATE, and DELETE are not DDL statements, they are DML statements, and that's why there is no implied commit. <HR></BLOCKQUOTE>
    Thanks for the response Bob,
    I'm researching the help files for review of post/commit and DBMS_SQL;
    Unfortunately I'm working against a database design that requires forms to view db column values as COLUMNS themselves,and as such requires a kind of re-design on-the-fly type of approach to be executed in the database at run-time pending user entries just before forms selects it's data through an relative view at runtime.
    Up and runnning, but was made more difficult by inability construct sql filters 'via user entry'. May need to re-engineer upon performance evaluation.
    So. really appreciate the help.

  • Why an "ORA-01006: bind variable does not exist" error when no dynamic SQL?

    Hi all,
    While running PL/SQL in SQL Developer 3.2.09, I got the following error after adding a section of code. Note that nothing I'm doing has anything to do with dynamic SQL (which is what 01006 is supposedly about).
    Error report:
    ORA-01006: bind variable does not exist
    01006. 00000 - "bind variable does not exist"
    *Cause:   
    *Action:
    After commenting out the new chunk of code that caused the error, the error persisted.
    After deleting the new code, the error went away.
    What the heck!?!? If you have any ideas, please lay 'em on me.
    Thanks so much,
    Kim
    P.S. It's a few hundred lines of code, so I didn't append it to this post and I don't see how to attach a file.

    Let's review a few facts:
    1. You post a question in the sql developer forum that has no apparent relation to sql developer. You could confirm this by doing the test using sql*plus or some other tool.
    2. You provide NO information about what database you are even using. The only clue is an ORA -xxx message that means SOME version of Oracle is involved.
    3. You provide NO information about what the four digit version of Oracle DB is being used.
    4. You provide NO information about what the code in general or what that specific section of the code is even doing. The code could be doing literally anything that Oracle is capable of doing.
    That's a bit like calling a mechanic you don't know, telling them your car is making a funny noise and asking them what the problem with your car is.
    >
    While running PL/SQL in SQL Developer 3.2.09, I got the following error after adding a section of code. Note that nothing I'm doing has anything to do with dynamic SQL (which is what 01006 is supposedly about).
    Error report:
    ORA-01006: bind variable does not exist
    01006. 00000 - "bind variable does not exist"
    *Cause:
    *Action:
    The error gives no indication of where the error occurred in the code.
    >
    Your first clue that your troubleshooting method is seriously flawed is when you make statements that aren't supported by any evidence at all but appear to be nothing but your opinion.
    Your second clue is when those statements appear to directly contradict what Oracle is telling you.
    I'm talking about these two statements you make; which you state as if they were universal truths
    >
    nothing I'm doing has anything to do with dynamic SQL
    (which is what 01006 is supposedly about).
    >
    If thoe were true then your 'unstated' conclusion appears to be that Oracle is wrong in saying 'bind variable does not exist'
    Sorry - but I would place my money on Oracle.
    I'm sure the above may sound harsh - it is intended to be. My four major rules (there are more) when troubleshooting Oracle problems.
    1. Assume that Oracle is CORRECT when it tells you there is a problem.
    2. Assume that you are WRONG if your opinion conflicts with what Oracle is telling you - see rule #1.
    3. Don't make ANY other assumptions. You can form hypotheses but don't state them as facts until they are proven.
    4. Your 'opinion' is only useful to the extent that it can help you form meaningful hypotheses - see rule #3.
    >
    To reiterate, there is no dynamic SQL in the code.
    >
    To reiterate - if, as you state, that error relates to dynamic SQL and bind variables then it can not be disputed that:
    ORACLE DOESN'T AGREE WITH YOU!
    So let's try it my way and hypothesize that Oracle is correct (see rule #1 above).
    Then by definition this statement by Oracle is correct
    >
    ORA-01006: bind variable does not exist
    >
    And that should immediately raise this question:
    1. where might there be a bind variable that does not exist?
    which leads to a prerequisite question:
    2. where are ALL of the bind variables that might be being used?
    Question #2 is where you need to start your search. Here are at least five possibilities (there are more)
    1. your code - this should be easiest to check and you state that your 'anonymous' block does not have any.
    2. a table trigger - triggers that use the :NEW, :OLD or :PARENT pseudocolumns. Those psuedocolumns are BIND variables and the trigger code that uses them is, by definition, dynamic sql.
    3. a pl/sql package/function/procedure - any of these might be being called from trigger code or a view that is involved in the transaction. Any of these could take a parameter and/or use bind variables and cause your problem if that bind variable does 'not exist'.
    4. a functional index - can also trigger code from #3 above
    5. an audit trigger that logs the audit activity that your user or your code is performing. This code could be trying to use a SYS_CONTEXT environment variable that has not been created and cause a 'bind variable does not exist' error.
    See rule #1 - Oracle is CORRECT. Until you have identified and examined ALL of the code (not just your anonymous block) being executed and ruled it out you should continue with the hypotheses that Oracle is CORRECT.
    In the (extremely) unlikely event that you can show that Oracle is NOT correct you should file a SOR with Oracle.

  • NULL and dynamic SQL

    If table testrh2 has the following columns and data
    col1 --> NULL
    col2 --> 2
    and table testrh has the following columsn and data
    col1 --> NULL
    How could I write a dynamic SQL statement to join on the nulls? I've written the following block as a starting point.
    declare
    cursor c1 is select col1 from isis.testrh;
    lval varchar2(1000);
    lval2 varchar2(1000);
    begin
    for r1 in c1 loop
    lval := 'select col2 from isis.testrh2 where col1 = '||r1.col1;
    execute immediate lval into lval2;
    dbms_output.put_line(lval2);
    end loop;
    end;

    You can't compare null values with '=' in Oracle SQL.
    Null can only be compared with <column> is null .
    You can see it when you try these two queries:
    select * from dual where null is null;  -- you will see one row
    select * from dual where null=null;  -- you will see no rowsThat's why you have to write something like
    (<column1>=<column1>   or   (<column1> is null and <column2> is null))This should also work with null:
    decode(<column1>,<column2>,1,0)=1By the way, why do you use dynamic sql?
    lval := 'select col2 from isis.testrh2 where col1 = '||r1.col1;
    I think you could replace your two lines ( lval:= ... AND execute immediate) by this:
    begin
      select col2
      into lval
      from isis.testrh2
      where decode(col1,r1.col1,1,0)=1;
      dbms_output.put_line('lval='||lval);
    exception
    when no_data_found then
      dbms_output.put_line('no data found'); -- or whatever you want
    end;Edited by: hartmutm on 02.10.2010 23:54

Maybe you are looking for

  • Calendar Host doesn't show up in WGM

    When I edit the advanced settings for a user in WGM, I can't choose a host in the 'Enable Calendaring' drop-down, as it says "No Calendar Host Selected". I configured iCal Service in SA such that "Host name" is the servers host.domain.com name I have

  • Amount of free space incorrect mavericks

    amt of free space not correct on new mbp 15  retina currently on desktop shows 988.08 gb which is correct but free space shows 1.1tb which is impossible disk utility shows correct amount 988.08 available 154.79 anyone else with this problem happened

  • Problem Moving Images Between Folders In Bridge (Windows 7 Professional)

    I have just bought a new computer with Windows 7 installed. I now also have Adobe CS5 Design Premium installed. When I try to MOVE or DRAG and DROP an image from one folder to another using Adobe Bridge I get the following error message: "The operati

  • Nokia Lumia 1020 screen doesn't light up when i re...

    title says it all, and no I will not do a reset on it so don't even suggest that.

  • How to save CD files to disk from within Flash?

    Hi. Is there any way I can copy files from a swf in a CD ROM to users computer? Some kind of "save to..." from within flash... ? Maybe I can explain better what I need to do: I have an external .swf, loaded into an .EXE. In the .swf, I need to put bu