The concatenation of the EXECUTE IMMEDIATE statement.

Hi all

The situation is that I am trying to find all customers whose Date of birth (DOB) is greater than or equal to 150 days. Unfortunately, when I run this SQL I get the error message:
(1) ORA-00904: "FEB": invalid identifier
(1) ORA-06512: at line 4 level

I'm not sure what I should do to solve this problem, I hope you can help.

Note: I have to encapsulate this statement in an immediate execution due to problems of roles/Privilidge. In the full version, I also use AUTHID CURRENT_USER.


DECLARE
    curr_date Date := SYSDATE;
BEGIN
    EXECUTE IMMEDIATE ' SELECT  cust_name,
                                cust_dob, -- date of birth
                                cust_shoe_size
                        FROM    tblCustDetails c
                        WHERE   SUBSTR(c.cust_name, 1,7) = ''Bob''
                                AND cust_dob >= NEXT_DAY(' || curr_date ||' - 150 , ''SATURDAY'')
                         ';
END;
Edited by: DaveyB February 23, 2012 08:39

The right way to use dynamic queries like this would get stuck in the variables you use... for example

DECLARE
    curr_date Date := SYSDATE;
BEGIN
    EXECUTE IMMEDIATE ' SELECT  cust_name,
                                cust_dob, -- date of birth
                                cust_shoe_size
                        FROM    tblCustDetails c
                        WHERE   SUBSTR(c.cust_name, 1,7) = ''Bob''
                                AND cust_dob >= NEXT_DAY(:1 - 150 , ''SATURDAY'')
                         ' USING curr_date;
END;

However, you also have to take into account the fact that the results of the query are currently disappearing into the ether, so you need an INTO statement...

DECLARE
    curr_date Date := SYSDATE;
BEGIN
    EXECUTE IMMEDIATE ' SELECT  cust_name,
                                cust_dob, -- date of birth
                                cust_shoe_size
                        FROM    tblCustDetails c
                        WHERE   SUBSTR(c.cust_name, 1,7) = ''Bob''
                                AND cust_dob >= NEXT_DAY(:1 - 150 , ''SATURDAY'')
                         ' INTO var1, var2, var3 USING curr_date;
END;

ensure that your variables are declared as appropriate, and then...

... you have to take into account the possibility that there is more than 1 line returned, in which case you will have the results of the query to a collection.

Of course, it is useless for dynamic SQL statements in the first place...

DECLARE
    curr_date Date := SYSDATE;
BEGIN
  SELECT  cust_name,
          cust_dob, -- date of birth
          cust_shoe_size
  INTO    var1, var2, var3
  FROM    tblCustDetails c
  WHERE   SUBSTR(c.cust_name, 1,7) = 'Bob'
  AND     cust_dob >= NEXT_DAY(curr_date - 150 , 'SATURDAY');
END;

still, you should always take into account the bulk collection in a collection if it were going to be more than one row returned.

Tags: Database

Similar Questions

  • Pass Pl/sql table in the USING clause in the EXECUTE IMMEDIATE statement

    Getting error when I try to pass the PL/SQL table in the USING clause in the EXECUTE IMMEDIATE statement:

    Declare
    result NUMBER;
    TYPE values_tab IS TABLE OF NUMBER INDEX OF directory;
    lv_tab values_tab;
    lv_exp varchar2 (300);
    lv_exec varchar2 (300);
    BEGIN
    lv_tab (1): = 5;
    lv_tab (2): = 48;
    lv_tab (3): = 7;
    lv_tab (4): = 6;
    lv_exp: = ': + b1: b2 + (: b3 *: b4)';
    lv_exec: = 'SELECT'. lv_exp | ' THE DOUBLE '.

    IMMEDIATE EXECUTION
    lv_exec
    IN
    result
    USING
    lv_tab;
    DBMS_OUTPUT. Put_line (result);

    END;
    /

    Error on line 1
    ORA-06550: line 20, column 12:
    PLS-00457: expressions must be SQL types
    ORA-06550: line 15, column 8:
    PL/SQL: Statement ignored


    I am trying to evaluate the expression ': + b1: b2 + (: b3 *: b4) "which is stored in the table. This table has different expressions (expressions about 300). I want to use the bind variable in the expression because each expression evaluated thousands of time may be more in some cases. If I use bind variable can he fill pool.

    Is there a way I can pass parameters with the HELP of (IN) dynamically instead of write "help lv_tab (1), lv_tab (2), lv_tab (3), lv_tab (4)? As number of change of the input parameters depend on the expression in the table.

    If it is possible please suggest any other ideas/approaches

    Help, please...

    Published by: satnam on June 11, 2009 11:50

    Well, you keep changing faster reqs that I can follow. In any case, assuming that N-th variable bind (left to right) corresponds to n-th collection item:

    Declare
        result NUMBER;
        lv_tab values_tab := values_tab();
        lv_exp varchar2(300);
        lv_exec varchar2(300);
        lv_i number := 0;
    BEGIN
        lv_tab.extend(4);
        lv_tab(1) := 5;
        lv_tab(2) := 48;
        lv_tab(3) := 7;
        lv_tab(4) := 6;
        lv_exp := ':5000135+:5403456+(:5900111*:5200456)';
        lv_exec := lv_exp;
        While regexp_like(lv_exec,':\d+') loop
          lv_i := lv_i + 1;
          lv_exec := REGEXP_REPLACE(lv_exec,':\d+',':b(' || lv_i || ')',1,1);
        end loop;
        lv_exec := 'BEGIN :a := ' || lv_exec || '; END;';
    DBMS_OUTPUT.PUT_LINE(lv_exec);
    EXECUTE IMMEDIATE lv_exec USING OUT result,IN lv_tab;
    DBMS_OUTPUT.PUT_LINE(result);
    END;
    /
    BEGIN :a := :b(1)+:b(2)+(:b(3)*:b(4)); END;
    95
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • suffixing date in the EXECUTE IMMEDIATE statement

    Hi could one please let me know how I can the suffix of the name of the table to the year, which the calculation is being in the select statement. Output should be as an example: test_2007
    declare
    
    abc number;
    
    begin
    
       select (to_char(sysdate, 'YYYY') - 4) into abc from dual;
    
       EXECUTE IMMEDIATE 'CREATE TABLE test_&abc as select * from emp where 1=2';
    
    end;

    You can do it like this

    BEGIN
       EXECUTE IMMEDIATE
             'CREATE TABLE test_'
          || (TO_CHAR ( SYSDATE, 'YYYY') - 4)
          || ' as select * from emp where 1=2';
    END;
    

    You can use your variable as well, if this can change dynamically.

    DECLARE
       abc            NUMBER;
    BEGIN
       SELECT (TO_CHAR ( SYSDATE, 'YYYY') - 4) INTO abc FROM DUAL;
    
       EXECUTE IMMEDIATE 'CREATE TABLE test_'||abc||' as select * from emp where 1=2';
    END;
    

    Edited by: g. March 1, 2011 11:49

  • Creating external Tables using the EXECUTE IMMEDIATE in PL/SQL

    Hi guys,.

    I am trying to create an external Table using the EXECUTE IMMEDIATE in a procedure and I managed to compile and no errors were generated. But when I try to run it from sql using the exec command I get the following error:

    ------------------------------------------------------------------------
    ERROR on line 5:
    ORA-00911: invalid character
    ORA-06512: at "GEO. TEST_DDL', line 4
    ORA-06512: at line 5

    -------------------------------------------------------------------------

    I tried to check the whole statement to create the external table, but I can't find where is the error. Surprisingly, if I simply run the command table create external on sqlplus it works, but not a procedure.

    If anyone can help with ideas or experience?

    Geoffrey Kossami

    The error means that there is an identifier somewhere that starts with a nonalphanumeric. This is a typical mistake of editing. A procedure compiles correctly is not of course because the underlying dynamic sql running is OK. Which of course only be resolved when you try to run it.

    There is certainly a problem with the text you provide to be run as a piece of dynamic sql code. You should try to watch it with dbms_output and run this code in sqlplus. But your problem is with the code you run as dynamic PL/SQL, it is not itself compilable.

    Jack

  • How to run an EXECUTE IMMEDIATE statement in an interactive report

    Hi all!!

    I need to make a dynamic construction of a query to run in an interactive report, but the Source of the region only allows SELECT simple instructions. There is no way to run an EXECUTE IMMEDIATE statement in a Source of interactive report region?

    Cordially Pedro.

    Hi Pedro,

    Reduce the size of the varchar2 32000 1000 (or, up to a maximum of 4000)

    Andy

  • Error in EXECUTING IMMEDIATE statement

    Hello again, friends, I have this block:
    SET SERVEROUTPUT ON
    DECLARE
    columnCount pls_integer;
    counter pls_integer := 1;
    columnName VARCHAR2(50);
    sqlQuery VARCHAR2(1000);
    columnLength pls_integer;
    dataType VARCHAR2(50);
    rowSize pls_integer;
    BEGIN
      rowSize := 0;
      SELECT COUNT(TABLE_NAME) INTO columnCount FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'PERSON';
      WHILE counter <= columnCount LOOP
        SELECT COLUMN_NAME, DATA_TYPE INTO columnName, dataType FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'PERSON' AND COLUMN_ID = counter;
        IF dataType = 'BLOB' THEN
          sqlQuery := q'[SELECT NVL(DBMS_LOB.GETLENGTH(]' || columnName || q'[), 0) FROM PERSON WHERE UUID = '999E5241-02AD-45fc-958A-CE808B0F56A6']';
        ELSIF dataType = 'SDO_GEOMETRY' THEN
          sqlQuery := q'[SELECT 500 FROM DUAL]';
        ELSE
          sqlQuery := q'[SELECT NVL(DBMS_LOB.GETLENGTH(CAST(]' || columnName || q'[ AS VARCHAR2(4000))), 0) FROM PERSON WHERE UUID = '999E5241-02AD-45fc-958A-CE808B0F56A6';]';
        END IF;
        EXECUTE IMMEDIATE sqlQuery INTO columnLength; -- Error here
        rowSize := rowSize + columnLength;
        counter := counter + 1;
      END LOOP;
      DBMS_OUTPUT.PUT_LINE(rowSize);
    END;
    It shows me:

    DECLARE
    *
    ERROR on line 1:
    ORA-00911: invalid character
    ORA-06512: at line 21

    What could be?

    Get rid of semi-colons in:

    sqlQuery: = q'[SELECT NVL (DBMS_LOB. [(GETLENGTH (CAST (]' | columnName | q'[AS VARCHAR2 (4000)])), 0) OF THE PERSON WHERE the UUID = '999E5241-02AD-45-CF - 958 A-CE808B0F56A6';]';

    Must be:

    sqlQuery: = q'[SELECT NVL (DBMS_LOB. [(GETLENGTH (CAST (]' | columnName | q'[AS VARCHAR2 (4000)])), 0) OF THE PERSON WHERE the UUID = "999E5241-02AD-45-CF - 958 A-CE808B0F56A6"] ";

    SY.

  • Execute Immediate for an IF statement

    All,
    I'm trying to run an IF statement dynamically at execution using the Execute Immediate statement, but I am gettign error... The error is PLS-00201: identifier 'V_BARG_UNIT' must be declared
    The condition and the result for the case statement is stored in a test_dynamic_if_tbl table that has 2 columns.
    condition = v_barg_unit = 'ABC' and result_val = v_bg_group: = "93"

    Yet the code...

    DECLARE
    cmd VARCHAR2 (4000);
    v_barg_unit VARCHAR2 (10): = 'ABC ';
    v_bg_group VARCHAR2 (10): = ' ';

    ABC of the CURSOR
    IS
    SELECT * FROM test_dynamic_if_tbl;
    BEGIN
    FOR c1 IN abc
    LOOP
    cmd: =.
    "Start."
    If ' | C1.condition
    || "THEN."
    || C1.result_val
    || ' ; End if;
    End;';
    Dbms_output.put_line ('cmd: ' | cmd);

    Cmd EXECUTE IMMEDIATE.

    Dbms_output.put_line (' status: ' | c1.condition);
    Dbms_output.put_line ('result_value: ' | c1.result_val);
    Dbms_output.put_line ('v_bg_group: ' | v_bg_group);
    END LOOP;
    END;

    What I am doing wrong?

    Thanks for your help in advance,
    Vinay

    Published by: user652279 on September 16, 2009 11:45

    Published by: user652279 on September 16, 2009 11:47

    Well, dynamic sql is executed in a separate context and scope. V_barg_unit stated in your code is therefore not visible in the dynamic PL/SQL block you run. You can pass block dynamic PL/SQL using the variable binding and the USING clause:

    DECLARE
        cmd VARCHAR2 (4000);
        v_barg_unit VARCHAR2 (10) := 'ABC';
        v_bg_group VARCHAR2 (10) := ' ';
    
    CURSOR abc
    IS
    SELECT * FROM test_dynamic_if_tbl;
    BEGIN
    FOR c1 IN abc
    LOOP
    cmd :=
    'declare v_barg_unit VARCHAR2 (10);
    Begin
    v_barg_unit := :v_barg_unit;
    If ' || c1.condition
    || ' THEN '
    || c1.result_val
    || ' ; End if;
    End;';
    DBMS_OUTPUT.put_line ('cmd: ' || cmd);
    
    EXECUTE IMMEDIATE cmd USING v_barg_unit,OUT v_bg_group;
    
    DBMS_OUTPUT.put_line ('Condition: ' || c1.condition);
    DBMS_OUTPUT.put_line ('result_value: ' || c1.result_val);
    DBMS_OUTPUT.put_line ('v_bg_group: ' || v_bg_group);
    END LOOP;
    END;
    

    However, since you do not know what name will be stored in test_dynamic_if_tbl my suggestion is not a generic solution.

    SY.

    Published by: Solomon Yakobson September 16, 2009 12:07

  • Maximum size of EXECUTE IMMEDIATE

    Hellou everyone,

    I would like to ask if there is a way how to run the dynamic SQL CREATE or VIEW of REPLACE command more than 32 KB of wholesale. Because the EXECUTE IMMEDIATE statement can run up to 32 k (greater length of variable plsql chain) chain

    Is there a way how children Ridge or replace the command?

    Or I need to revrite using DBMS_SQL.

    Thank you.

    (a) WHY? If you want to dynamically create views?  This is not recommended because your application/database should be designed at the time of the design, not running.

    (b) If you are on 11 g, you can use the CLOB datatype with immediate execution, so there is no 32 K limit.

    (c) If you are before 11 g you need to update, but if you can't then the following example is how you do it using DBMS_SQL.

    SQL > declare

    2 v_large_sql clob.

    3 v_num number: = 0;

    number of v_upperbound 4;

    5 v_sql dbms_sql.varchar2s;

    6 whole v_cur;

    number of v_ret 7;

    8 v_join_sql varchar2 (100): = ' crΘer view vw_tmp as ";

    9 start

    10. build a very big SQL statement in the CLOB

    11 loop

    12 v_large_sql: = v_large_sql | v_join_sql | "select" the number of this line is: ' | TO_CHAR (v_num, 'fm0999999') | " "as col1 from dual;"

    13 v_join_sql: = "union all";

    14 v_num: = v_num + 1;

    15 exit when dbms_lob.getlength (v_large_sql) > 40000 or v_num > 800;

    16 end loop;

    17 dbms_output.put_line (' length :'||) DBMS_LOB. GetLength (v_large_sql));

    18 dbms_output.put_line ('Num :'|| v_num);

    19-

    20. now divide this big SQL statement into pieces of 256 characters and put in table VARCHAR2S

    21 v_upperbound: = ceil ((v_large_sql) dbms_lob.getlength / 256);

    22 because me at 1.v_upperbound

    23 loop

    24 v_sql (i): = dbms_lob.substr (v_large_sql

    25, 256 - amount

    26, ((i-1) * 256) + 1 - offset

    27                                 );

    28 end of loop;

    29-

    30. now analyze and execute the SQL statement

    31 v_cur: = dbms_sql.open_cursor;

    32 dbms_sql.parse (v_cur, v_sql, 1, v_upperbound, dbms_sql.native, false);

    33 v_ret: = dbms_sql.execute (v_cur);

    34 dbms_output.put_line ("' view created");

    35 dbms_sql.close_cursor (v_cur);

    36 end;

    37.

    Length: 40015

    NUM:548

    View created

    PL/SQL procedure successfully completed.

    SQL > select count (*) in the vw_tmp;

    COUNT (*)

    ----------

    548

    SQL > select * from vw_tmp where rownum<=>

    COL1

    -----------------------------------

    The number of this line is: 0000000

    The number of this line is: 0000001

    The number of this line is: 0000002

    The number of this line is: 0000003

    The number of this line is: 0000004

    The number of this line is: 0000005

    The number of this line is: 0000006

    The number of this line is: 0000007

    The number of this line is: 0000008

    The number of this line is: 0000009

    10 selected lines.

    SQL >

  • EXECUTE IMMEDIATE throwing error ORA-00933

    Hello

    I am trying to build a PL/SQL code that implements the EXECUTE IMMEDIATE statement in a cursor for EXECUTE IMMEDIATE does not support queries for multiple records. Recursively, I want to place a single record in a variable using the INTO clause, USING a defined value. But my code keeps throwing an error that the SQL command is not properly cancel online 15; which is the line of the EXECUTE IMMEDIATE statement.

    I tried to generate the SQL statement to the console to review in the effort to find the problem, but the result looks OK. I also made other variations of what I want to accomplish, but not to make any where. Could someone maybe help identify what I am doing wrong?

    DECLARE
    TBL VARCHAR2 (50);
    Col VARCHAR2 (50);
    sqlcmd VARCHAR (300);
    field_value VARCHAR2 (20): = 'MEXICO ';
    match_count NUMBER;
    CURSOR c1 IS SELECT TABLE_NAME, COLUMN_NAME FROM USER_TAB_COLS;

    BEGIN
    OPEN c1;
    LOOP
    FETCH c1 INTO tbl, col; -extract 2 columns in variables
    OUTPUT WHEN c1% NOTFOUND;
    Sqlcmd: = 'SELECT COUNT (*) FROM' | TBL | ' WHERE ' | Col |' = ": col" ';
    EXECUTE IMMEDIATE sqlcmd IN match_count USING field_value.
    DBMS_OUTPUT. Put_line (sqlcmd);
    END LOOP;
    CLOSE c1;
    END;
    /

    I am more proficient with SQL PL/SQL, but try to understand the semantics of the language.

    Thanks for any help.

    user10251149 wrote:
    I'm in class implementing the recommended code you posted Solomon and he is not sinning through out, but I'm sitting at a cursor blinking on the console.

    I noticed that you have placed the variables, this time taking the table_name and column_name inside quotes values, it is a possible workaround for the issue or is there another method I could use to get the same results?

    If you have N tables with columns of M your code will run statements N * Mr. If the tables are large, it might take some time. Now how about double quotes. You may receive error on the basis I assumed you have names of tables/columns composed of several words. You must include these names in quotation marks. Discover Oracle naming rules.

    SY.

  • Storing the values of execute immediate instruction.

    Hi all
    I execute immediate statement that gets several rows at a time. I need to save this picture and print. Pleas elte the syntax me to use an array or temp table in oracle. See the code provided below.
    Thank you...
    declare
    v_ct varchar2 (290);
    v_sqlcode number: = 0;
    v_stmt varchar2 (2900);
    r_tbl VARCHAR2 (150);
    cursor c_tbl is
    Select the table TABLE_NAME from DBA_TABLES where OWNER = 'ted '.
    Start
    Open c_tbl;
    loop
    extract the c_tbl in r_tbl;
    When the output c_tbl % notfound;
    v_stmt: = 'select NULLABLE from DBA_TAB_COLUMNS WHERE TABLE_NAME =' | " ' || r_tbl | " ' |' and COLUMN_NAME in (select column_name from DBA_IND_COLUMNS where INDEX_NAME = (select 'INDEX_NAME' from DBA_INDEXES where TABLE_NAME =' | ")) ' || r_tbl | " ((' |' and UNIQUENESS = "UNIQUE"))';
    run immediately v_stmt in v_ct;
    v_sqlcode: = SQLCODE;
    If v_sqlcode = 0
    then dbms_output.put_line (v_ct);
    end if;
    end loop;
    close c_tbl;
    end;

    Your immediate question seems to be answered.

    I would like to point out a few problems with your code, however.

    First of all, it seems pointless to use dynamic SQL here - you can use a static SQL statement to get the same data. You can use static SQL, you should.

    Secondly, if you want to use dynamic SQL statements, you should really use bind variables. Something like

      v_stmt := 'select NULLABLE from DBA_TAB_COLUMNS WHERE TABLE_NAME = :1 and COLUMN_NAME in (select column_name from DBA_IND_COLUMNS where INDEX_NAME= (select "INDEX_NAME" from DBA_INDEXES where TABLE_NAME =':2 and UNIQUENESS =''UNIQUE''))';
      execute immediate v_stmt
          bulk collect into v_ct
        using r_tbl, r_tbl;
    

    Third, your deepest query is to select the literal 'INDEX_NAME' rather than the name of the actual index. Unless you happen to have an index named INDEX_NAME, who is likely to be a mistake.

      v_stmt := 'select NULLABLE from DBA_TAB_COLUMNS WHERE TABLE_NAME = :1 and COLUMN_NAME in (select column_name from DBA_IND_COLUMNS where INDEX_NAME= (select INDEX_NAME from DBA_INDEXES where TABLE_NAME =':2 and UNIQUENESS =''UNIQUE''))';
      execute immediate v_stmt
          bulk collect into v_ct
        using r_tbl, r_tbl;
    

    Fourth, unless you can be sure that the table has a unique index, your query will return an error because the deepest returns multiple lines.

      v_stmt := 'select NULLABLE from DBA_TAB_COLUMNS WHERE TABLE_NAME = :1 and COLUMN_NAME in (select column_name from DBA_IND_COLUMNS where INDEX_NAME in (select INDEX_NAME from DBA_INDEXES where TABLE_NAME =':2 and UNIQUENESS =''UNIQUE''))';
      execute immediate v_stmt
          bulk collect into v_ct
        using r_tbl, r_tbl;
    

    Justin

    Published by: Justin Cave on August 5, 2011 23:28

  • FORALL with EXECUTE IMMEDIATE

    Hi all

    I'm using Oracle 11 g Release2.

    I need to use the forall with EXECUTE IMMEDIATE statement and the content of string inside EXECUTE IMMEDIATE is a SELECT instead of the usual DML statement.

    Objective: In this SELECT statement, I'll be passing of data using the "USING" clause in FORALL statement

    When I try to use it, am getting error found "no DATA".

    Please advice if I use FORALL and EXECUTE IMMEDIATE on a SELECT statement?

    I can share the scenario...

    Thank you!

    >
    Please advice if I use FORALL and EXECUTE IMMEDIATE on a SELECT statement?
    >
    No - you can't. See the specifications of the PL/SQL language
    http://docs.Oracle.com/CD/E14072_01/AppDev.112/e10472/forall_statement.htm
    >
    dml_statement

    An INSERT, UPDATE, or DELETE static or dynamic statement making reference at least a collection in its VALUES or the WHERE clause. Performance benefits apply only to references to the collection that use as an index index_name.

  • How to set multiple parameters in a sql EXECUTE IMMEDIATE

    I want to set nls_language and nls_date_language and set them as different languages. fnd_global.set_nls_context () does not work. So I think I can use the EXECUTE IMMEDIATE and add them together into a single statement. But I don't know how to make that happen. Can someone help me? Thank you very much.

    PS: It must be done in a single call.

    928091 wrote:
    Hey, thanks for your reply, I forgot to mention that it should be in the begin-end block, do you know how?

    EXEC is a more SQL API which can be used to execute the PL/SQL code. What it does is put the PL/SQL code in a BEGIN block... END of block and run.

    So, you can also manually put code in a BEGIN block... END of block and run like that.

    SQL> begin
      2     execute immediate q'[begin execute immediate 'alter session set nls_date_language = ''AMERICAN'''; execute immediate 'alter session set nls_language = ''AMERICAN'''; end;]';
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    And I don't understand what possible benefit he made a single run in a BEGIN block... Terminate during execution of multiples.

    Why this code is not in your interest, something like this

    begin
         execute immediate 'alter session set nls_date_language = ''AMERICAN''';
         execute immediate 'alter session set nls_language = ''AMERICAN''';
    end;
    /
    
  • "EXECUTE IMMEDIATE" of CLOB

    I have plsql-variable with CLOB datatype. It contains the source code of a package body. The size of the variable does not fit into 'varchar2' data type, it is larger.
    Now, I want to run a "EXECUTE IMMEDIATE" statement to create my package body defined in my CLOB variable.
    How can I use the "EXECUTE IMMEDIATE"?
    Note that "EXECUTE IMMEDIATE" does not allow for CLOB-variable as an argument.
    Note that "EXECUTE IMMEDIATE" allows "varchar2" - variables as arguments but "varchar2" contains maximum only some 32 KB of data.


    --

    Maybe it's possible to run something like
    "EXECUTE IMMEDIATE v1 | v2 | v3»
    where v1, v2, v3 are of type varchar2 and altogether they contain ca 100K of data and execute immediately would succeed?
    I wil outside, a s test...

    I wil outside, a s test...

    You may have searched for as well ;)

    Re: immediate execution of a CLOB field.

    Note: In 11 GR 2 run immediately accepts a clob as well...

  • EXECUTE IMMEDIATE in error &gt; &gt; ORA-00972: identifier is too long

    Hello

    I wrote a code using execute immediate command. This command essentially creates a cursor that selects user_tab_columns table names. These table names are then used inside the statement immediately execute in order to apply the same select statement on the table being selected within the cursor names. The problem is that the above error is thrown saying identifier is too long. I can't understand how to solve this problem.

    Please find the below code:

    Declare
    Cursor C_1 is select distinct table_name
    of user_tab_columns
    where column_name = 'PROGRAM_UPDATE_DATE' AND table_name LIKE '% MISPA '.
    intersect
    Select unique table_name
    of gsi_daily_count;
    table_names varchar2 (100);
    Begin
    C_1 open;
    Loop
    Extract the C_1 in table_names;
    WHEN THE EXIT C_1% NOTFOUND;

    EXECUTE IMMEDIATE "select last_extract_date,
    TO_CHAR (min (largest (nvl (last_update_date, "1 January 10"), nvl (program_update_date, "1 January 10"))), "MON-DD-YY HH24:MI:SS") mi.
    TO_CHAR (max (greatest (nvl (last_update_date, "1 January 10"), nvl (program_update_date, "1 January 10"))), "MON-DD-YY HH24:MI:SS") my
    of ' | table_names |
    "Last_extract_date group".
    order of last_extract_date desc;';

    End loop;
    Close C_1;
    COMMIT;
    End;
    /


    Help, please.

    Kind regards
    Hossam
    declare
      cursor C_1
      is
      select distinct table_name
        from user_tab_columns
       where column_name = 'PROGRAM_UPDATE_DATE'
         and table_name LIKE 'MISPA%'
      intersect
      select unique table_name
        from gsi_daily_count;
    
      table_names varchar2(100);
    begin
      open C_1;
      loop
        fetch C_1 into table_names;
        exit when c_1%notfound;
    
        execute immediate
          'select last_extract_date,
                  to_char(min(greatest(nvl(last_update_date,''01-Jan-10''),nvl(program_update_date,''01-Jan-10''))),''DD-MON-YY HH24:MI:SS'') mi,
                  to_char(max(greatest(nvl(last_update_date,''01-Jan-10''),nvl(program_update_date,''01-Jan-10''))),''DD-MON-YY HH24:MI:SS'') ma
             from'|| table_names ||
          'group by last_extract_date
            order by last_extract_date desc;';
      end Loop;
      close C_1;
      commit;
    End;
    

    Here is the list of question I see in this code.

    1. in the SQL string, you must have a after the keyword and before the GROUP BY keyword.

    2. you should not use ';' in EXECUTE IMMEDIATE. You must remove it.

    3. the result set returned by the EXECUTE IMMEDIATE should be stored in a Variable. You use the INTO LEDGES INTO clause or in BULK to this effect.

  • Execute Immediate and by calling a function

    I'm calling a function by using the Execute Immediate, but not sure what the correct syntax for the function's return value after the Execute Immediate runs.

    I need the value for further processing in my PL/SQL package.

    I tried several methods, but cannot get the right format for this work/compilation.


    EExecute Immediate plsql_block back in ShName2;

    Have been that plsql_block has the code to:
    Declare shname2 varchar2 (4000); Begin shname2: = lurking. ShortNm ('STRUCTURE'); End;
    SQL> set serveroutput on
    SQL>
    SQL> create or replace
      2  function fun
      3     return varchar2
      4  is
      5  begin
      6     return 'hello';
      7  end fun;
      8  /
    
    Function created.
    
    SQL>
    SQL>
    SQL> declare
      2     var varchar2(100);
      3  begin
      4     execute immediate 'begin :this := fun; end;' using in out var;
      5    dbms_output.put_line(var);
      6  end;
      7  /
    hello
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

Maybe you are looking for

  • Disk failure hard satellite L650-12N - replaced with SSD - how to recover?

    My HARD drive has failed, so I bought a 256 GB SSD Crucial CT256MX100SSD1. I installed it in the laptop and went to use the recovery CD. It's the bit score correctly as far as I can tell, but to cut a long story short, I think that the recovery disk

  • Windows XP 2002 service pack 2 does not have internet explorer 7 or 8.

    Recently, I took out my old laptop. Windows XP 2002 Service Pack 2. I was using internet just fine, then when I went to a Web page (don't remember now). He said that my computer needed update to IE 7 to the support page. I tried to load this (update)

  • MD3000i Add Group of physical disc to disc

    When you add additional physical disks to a disk group how normal time does it take for the course ends?  I would like to create another virtual disk in a disk group, but needs space.  Also, how does he know which physical disk to use?

  • Programs Office can not send as e-mail

    When I try to send a document from the office of the function of the 'Share' document under file, I get an error message that says: "There are no associated messaging program to perform the requested action. Install an e-mail program or, if such is a

  • File system agent

    Hi all I need assistance with system files foglight on a solaris host agent The agent is configured as follows, and I need the point of editing/GB to watch with the file system agent that I created Global Fatal threshold value 50 Critical threshold v