Execute Immediate and CLOB

Hi All,
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
I am getting error when trying to use CLOB with execute immediate.
DECLARE
v_clob CLOB;
BEGIN
EXECUTE IMMEDIATE 'SELECT DBMS_METADATA.GET_DDL(''TABLE'',''T_FDB_TMP'') from dual'
           INTO v_clob_part_ddl;
EXECUTE IMMEDIATE 'DROP TABLE T_FDB_TMP';
EXECUTE IMMEDIATE to_char(v_clob_part_ddl);
END;
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 1
ORA-06502: PL/SQL: numeric or value error
ORA-31605: the following was returned from LpxXSLResetAllVars in routine kuxslResetParams:
LPX-1: NULL pointer
ORA-06512: at line 3
06502. 00000 -  "PL/SQL: numeric or value error%s"Please help

If you can't upgrade to 11g then you'll have to use DBMS_SQL package...
e.g.
SQL> ed
Wrote file afiedt.buf
  1  declare
  2    v_large_sql  CLOB;
  3    v_num        NUMBER := 0;
  4    v_upperbound NUMBER;
  5    v_sql        DBMS_SQL.VARCHAR2S;
  6    v_cur        INTEGER;
  7    v_ret        NUMBER;
  8  begin
  9    -- Build a very large SQL statement in the CLOB
10    LOOP
11      IF v_num = 0 THEN
12        v_large_sql := 'CREATE VIEW vw_tmp AS SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
13      ELSE
14        v_large_sql := v_large_sql || ' UNION ALL SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
15      END IF;
16      v_num := v_num + 1;
17      EXIT WHEN DBMS_LOB.GETLENGTH(v_large_sql) > 40000 OR v_num > 800;
18    END LOOP;
19    DBMS_OUTPUT.PUT_LINE('Length:'||DBMS_LOB.GETLENGTH(v_large_sql));
20    DBMS_OUTPUT.PUT_LINE('Num:'||v_num);
21    --
22    -- Now split that large SQL statement into chunks of 256 characters and put in VARCHAR2S array
23    v_upperbound := CEIL(DBMS_LOB.GETLENGTH(v_large_sql)/256);
24    FOR i IN 1..v_upperbound
25    LOOP
26      v_sql(i) := DBMS_LOB.SUBSTR(v_large_sql
27                                 ,256 -- amount
28                                 ,((i-1)*256)+1 -- offset
29                                 );
30    END LOOP;
31    --
32    -- Now parse and execute the SQL statement
33    v_cur := DBMS_SQL.OPEN_CURSOR;
34    DBMS_SQL.PARSE(v_cur, v_sql, 1, v_upperbound, FALSE, DBMS_SQL.NATIVE);
35    v_ret := DBMS_SQL.EXECUTE(v_cur);
36    DBMS_OUTPUT.PUT_LINE('View Created');
37* end;
SQL> /
Length:40015
Num:548
View Created
PL/SQL procedure successfully completed.
SQL> select count(*) from vw_tmp;
  COUNT(*)
       548
SQL> select * from vw_tmp where rownum <= 10;
COL1
The number of this row is : 0000000
The number of this row is : 0000001
The number of this row is : 0000002
The number of this row is : 0000003
The number of this row is : 0000004
The number of this row is : 0000005
The number of this row is : 0000006
The number of this row is : 0000007
The number of this row is : 0000008
The number of this row is : 0000009
10 rows selected.
SQL>

Similar Messages

  • Execute immediate and dynamic sql

    Dear all;
    Just curious....Why do developers still use dynamic sql..and execute immediate, because I always thought dynamic sql were bads and the use of execute immediate as well...
    or am I missing something...

    There are no 'bad' things and 'good' things.
    There are 'correctly used' and 'incorrectly used' features.
    It depends what you want to do.
    One simple example: Oracle 11.2 - you write a package that fetches data from range interval partitioned table (a new partition is created automatically every day when new key values are inserted). If you use static SQL then whenever Oracle creates a new partition then your package gets invalidated and has to be compiled. If your package is heavily used (by many sessions running in parallel) then you may get this:
    ORA-04068: existing state of packages has been discarded
    ORA-04061: existing state of package body "PACKAGE.XXXXX" has been invalidated
    ORA-06508: PL/SQL: could not find program unit being called: "PACKAGE.XXXXX" Nice, isn't it?
    You can avoid this kind of problems by simply using dynamic SQL. You break dependency with the table and your package is not invalidated when new partition is created.

  • Help with EXECUTE IMMEDIATE and DROP

    Hi all,
    we are trying to create a procedure to do the following:
    * We have in the database some tables named like C$_XXXXXXXXX
    * We want to drop some of these tables that have a common prefix (f.e C$_1203101)
    DECLARE
    v_sql VARCHAR2(300);
    BEGIN
    SELECT 'DROP TABLE ODISTAG.'|| TABLE_NAME ||';' INTO v_sql FROM USER_TABLES WHERE TABLE_NAME LIKE 'C$_1203101%';
    EXECUTE IMMEDIATE v_sql;
    END;
    But we get this error:
    Error report:
    ORA-00911: invalid character
    ORA-06512: at line 5
    00911. 00000 - "invalid character"
    *Cause:    identifiers may not start with any ASCII character other than
    letters and numbers. $#_ are also allowed after the first
    character. Identifiers enclosed by doublequotes may contain
    any character other than a doublequote. Alternative quotes
    (q'#...#') cannot use spaces, tabs, or carriage returns as
    delimiters. For all other contexts, consult the SQL Language
    Reference Manual.
    *Action:
    Any help on that please?
    Thanks!

    This will not work if you fetch more than one row..instead you can do this..
    DECLARE
         v_sql VARCHAR2(30000);
    BEGIN
         for c2 in (
                        SELECT 'DROP TABLE ODISTAG.'|| TABLE_NAME drp
                        FROM USER_TABLES WHERE TABLE_NAME LIKE 'C$_1203101%'
         loop
              v_Sql := c2.drp;
              EXECUTE IMMEDIATE v_sql;
         end loop;
    END;

  • PL/SQL Proc, execute immediate and materialized view 9.2.0.6

    Hello,
    Environement description: Sun Solaris 8 , Oracle database 9.2.0.6
    I've a problem trying to execute this PL/SQL Procedure:
    I'm loged in with PMU user
    CREATE OR REPLACE PROCEDURE PMU.PROC_TEST_PMU_C035 (part_arrete in integer, part_session in integer) AS
    lv_p_arrete number     := part_arrete;
    lv_p_session number     := part_session;
    lv_stmt     varchar2(31000);
    BEGIN
    lv_stmt := ' ';
    lv_stmt := lv_stmt || 'CREATE MATERIALIZED VIEW 'PMU''.''TEST_PMU_C035'' ';
    lv_stmt := lv_stmt || 'TABLESPACE PMU_8M_DATA ';
    lv_stmt := lv_stmt || 'BUILD IMMEDIATE ';
    lv_stmt := lv_stmt || 'REFRESH COMPLETE AS ';
    lv_stmt := lv_stmt || 'SELECT * FROM ACTION ';
    lv_stmt := lv_stmt || 'WHERE LIBELLE IN ( ''SOCIETE 1'', ''SOCIETE 2'', ''SOCIETE 3'' ) ;';
    dbms_output.put_line ( lv_stmt) ;
    execute immediate ( lv_stmt);
    END;
    When I comment the line : execute immediate ( lv_stmt); It works fine and my statement appear on the screen:
    CREATE MATERIALIZED VIEW PMU.TEST_PMU_C035 TABLESPACE PMU_8M_DATA BUILD
    IMMEDIATE REFRESH COMPLETE AS SELECT LIBELLE FROM ACTION WHERE LIBELLE IN (
    'SOCIETE1', 'SOCIETE2', 'SOCIETE3' ) ;
    When I execute manually this query it works.
    But when I try to do the execute immediate, it gives me this error:
    BEGIN "PMU"."PROC_TEST_PMU_C035" ( 13, 14); END;
    ERROR at line 1:
    ORA-00911: invalid character
    ORA-06512: at "PMU.PROC_TEST_PMU_C035", line 15
    ORA-06512: at line 1
    Action Table has this description and datas:
    SQL> desc action
    Name Null? Type
    ISIN NOT NULL VARCHAR2(20)
    LIBELLE VARCHAR2(100)
    SQL>
    ISIN LIBELLE
    FR1 SOCIETE 1
    FR2 SOCIETE 2
    FR3 SOCIETE 3
    FR4 SOCIETE 4
    FR5 SOCIETE 5
    FR6 SOCIETE 6
    FR7 SOCIETE 7
    FR8 SOCIETE 8
    FR9 SOCIETE 9
    FR10 SOCIETE 10
    FR11 SOCIETE 11
    This is a sample description of my probleme because the real case is on multiple partition tables with million rows, but the problem is the same with this sample.
    My question is why it doesn't work ? Could anybody help me ?
    Thanks In advance.
    Loic

    Yes but you did not show where you want the parametersOK this is my Original Query :
    CREATE OR REPLACE PROCEDURE "PMU"."PROC_TEST_PMU_C035" (part_arrete in integer, part_session in integer)AS
    lv_p_arrete integer := part_arrete;
    lv_p_session integer := part_session;
    lv_stmt varchar2(31000);
    BEGIN
    lv_stmt := 'CREATE OR REPLACE MATERIALIZED VIEW PMU.TEST_PMU_C035 ';
    lv_stmt := lv_stmt || ' TABLESPACE PMU_8M_DATA ';
    lv_stmt := lv_stmt || ' BUILD IMMEDIATE ';
    lv_stmt := lv_stmt || ' REFRESH COMPLETE AS ';
    lv_stmt := lv_stmt || ' select CD_SOCIETE, MONTANT, MOIS, TYPEDET, LIEUCONS, DETPEA, PERSPHYS, SECTDET, PAYSDET, ZONEDET, CSPDET, AGEDET, TRMONT, NATINSFI, MATURITE, MONNAIE, DEVISEISO, SECTEMT, PAYSEMT, ZONEEMT, ENCRSDEB, NBCPTIT, TYPEFLUX, CONTRAT, CODISIN, LIBELTIT, SEUILDET, PAYSCTP, NBTIT, SEUILA1, SEUILA2, SEUILM1, SEUILM2, SEUILB1, SEUILB2, SEUILQ1, SEUILQ2, TXEVOL, NBCPTITPEA, NBCPTITPPP, ';
    lv_stmt := lv_stmt || ' NO_PCI || ''-'' || SECTDET || ''-'' || ZONEDET || ''-'' || MONNAIE || ''-'' || SECTEMT || ''-'' || DETPEA || ''-'' || PERSPHYS || ''-'' || (CASE WHEN TYPEDET IN (''DCL'', ''DCG'') THEN ''DCL'' ';
    lv_stmt := lv_stmt || ' ELSE NVL(TYPEDET,'''') ';
    lv_stmt := lv_stmt || ' END ) || ''-'' || (CASE WHEN NATINSFI in (''OBL'', ''EMT'', ''BTR'', ''CDD'', ''CDE'', ''CPP'', ''BTS'', ''MIB'') THEN ''OBL'' ';
    lv_stmt := lv_stmt || ' ELSE NVL(NATINSFI,'''') ';
    lv_stmt := lv_stmt || ' END) || ''-'' ||(CASE WHEN MATURITE IN (''A0'', ''A1'') THEN ''AC'' ELSE NVL(MATURITE,'''') END) || ''-'' ||(CASE WHEN PAYSEMT IN (''FR'',''MC'') THEN ''F1'' ';
    lv_stmt := lv_stmt || ' WHEN PAYSEMT IN (''DE'',''AT'',''BE'',''ES'',''FI'',''GR'',''IE'',''IT'',''LU'',''NL'',''PT'',''SI'', ''4F'') THEN ''ZE'' ';
    lv_stmt := lv_stmt || ' WHEN PAYSEMT IN (''BG'',''CY'',''DK'',''EE'',''HU'',''LV'',''LT'',''MT'',''PL'',''RO'',''GB'',''SK'',''SE'',''CZ'', ''4C'', ''4D'', ''4H'', ''4E'', ''4Z'', ''JE'') THEN ''ZU'' ';
    lv_stmt := lv_stmt || ' ELSE ''ZR''';
    lv_stmt := lv_stmt || ' END ) AS CLE';
    lv_stmt := lv_stmt || ' from PMU_ESLD_ESTD partition(PMU_M13_S14) e ,';
    lv_stmt := lv_stmt || ' PMU_ESLD_ESTD_SPPRO partition(PMU_M13_S14) a';
    lv_stmt := lv_stmt || ' where e.PART_ARRETE = '||lv_p_arrete ;
    lv_stmt := lv_stmt || ' AND e.PART_ENV = ''BCE''' ;
    lv_stmt := lv_stmt || ' AND e.PART_SESSION = '||lv_p_session ;
    lv_stmt := lv_stmt || ' and e.ID = a.ID_ESTD ';
    lv_stmt := lv_stmt || ' and e.CD_STATUT = ''VE'' ' ;
    lv_stmt := lv_stmt || ' and e.TYP_MONTANT = ''33'' ; ' ;
    execute immediate lv_stmt;
    END;
    Thanks

  • Execute immediate and "in" operator

    Hello!
    I want to pass varchar2 type argument to my procedure in format '1,2,3' where 1,2 and 3 are some IDs.
    And then, in procedure I write:
    stmt := 'select avg(PRICE) from ORDERS where ORDER_ID in (:Ids)';
    execute immediate stmt into APrice using ARGUMENT;
    I undersand, that this is incorrect, because where clause in executable query is
    "where ORDER_ID in ('1,2,3')" but not "where ORDER_ID in (1,2,3)".
    Is there any easy way how to solve such a problem?
    Maybe I should use other argument type?

    user10304317 wrote:
    I undersand, that this is incorrect, because where clause in executable query isIf you want to use a string you will have to concatenate it into dynamic sql:
    stmt := 'select avg(PRICE) from ORDERS where ORDER_ID in (' || ARGUMENT || ')';
    execute immediate stmt into APrice;However, it will produce as many sql in shared pool as you will have different ARGUMENT values and each of them will do a hard parse. Or you could use collection and then you do not need dynamic sql (unless select list and/or rest of where clause is dynamic):
    SQL> create or replace
      2    type num_tbl_type
      3      as
      4        table of number;
      5  /
    Type created.
    SQL> create or replace procedure p1(
      2                                 p_num_tbl num_tbl_type
      3                                )
      4    is
      5    begin
      6        for rec in (select empno,ename from emp where empno in (select * from table(p_num_tbl))) loop
      7          dbms_output.put_line(rpad(rec.empno,10) || rec.ename);
      8        end loop;
      9  end;
    10  /
    Procedure created.
    SQL> set serveroutput on
    SQL> exec p1(num_tbl_type(7566,7839,7902))
    7566      JONES
    7839      KING
    7902      FORD
    PL/SQL procedure successfully completed.
    SQL> SY.

  • Difficulties with execute immediate and 'in' clause

    Hello all,
    I have some SQL that will have to run dynamically, which I can get to work by building a long statement, then getting it hard-parsed
    example:
    sql_stmt VARCHAR2(256) :=
    'select distinct some_id from table1
    where lname = ''Smith''
    and fname in(''Joe'', ''Joey'', ''Joseph'')
    and ssn = 111223333';
    execute immediate sql_stmt into new_id_value;
    the above state executes fine and returns the desired result.
    HOWEVER, when I try to use bind variables (this statement will be called several million times), I get a no rows returned error.
    I use bind variables as follows:
    sql_stmt VARCHAR2(256);
    vlname VARCHAR2(50) := 'Smith';
    vssn NUMBER := 111223333;
    vfname VARCHAR2(100) := '''Joe'', ''Joey'', ''Joseph''';
    sql_stmt :=
    'select distinct some_id from table1
    where lname = :vlname
    and fname in(:vfname)
    and ssn = :vssn;
    execute immediate sql_stmt into new_id_value
    using vlname, vfname, vssn;
    I know the issue involves the 'in' clause because I've substituted hardcoded values in and it has worked.
    any suggestions?

    Well maybe its all a little confusing, does an end to end demo make it any clearer Mr Bidness?
    SQL> create or replace type tabstr_t as table of varchar2(4000)
      2  /
    Type created.
    SQL> create or replace function tabstr (
      2      p_str in varchar2,
      3      p_sep in varchar2 default ','
      4      )
      5  return tabstr_t
      6  is
      7      l_str long := p_str || p_sep;
      8      l_tabstr tabstr_t := tabstr_t();
      9  begin
    10      while l_str is not null loop
    11          l_tabstr.extend(1);
    12          l_tabstr(l_tabstr.count) := rtrim(substr(
    13                  l_str,1,instr(l_str,p_sep)),p_sep);
    14          l_str := substr(l_str,instr(l_str,p_sep)+1);
    15      end loop;
    16      return l_tabstr;
    17  end;
    18  /
    Function created.
    SQL> var s varchar2(100)
    SQL> exec :s := 'king,turner,ward'
    PL/SQL procedure successfully completed.
    SQL> select ename, sal from emp
      2  where ename in (
      3    select upper(column_value) from
      4    table(cast(tabstr(:s) as tabstr_t))
      5    );
    ENAME             SAL
    KING             5000
    TURNER           1500
    WARD             1250
    SQL> exec :s := 'jones,blake,clark'
    PL/SQL procedure successfully completed.
    SQL> /
    ENAME             SAL
    BLAKE            2850
    CLARK            2450
    JONES            2975

  • EXECUTE IMMEDIATE AND BULK INSERT

    Hi,
    I have a code
    EXECUTE IMMEDIATE 'INSERT INTO PRC_ExcelDocumentStore_T(object_id,seg_index,segment,value,seg_length) VALUES (:object_id,:seg_index,:segment,:value,:seg_length)'
    USING SELF.object_id,p_index,p_segment,p_value,lengthc(v_value)+2;
    But due to some performance issue ,I can't use like this.Can you please suggest can i use Bulk Inserts instead of 'EXECUTE IMMEDIATE' statement.
    If I can do,please give me an example.
    Thanks in advance

    user10619377 wrote:
    Hi,
    I have a code
    EXECUTE IMMEDIATE 'INSERT INTO PRC_ExcelDocumentStore_T(object_id,seg_index,segment,value,seg_length) VALUES (:object_id,:seg_index,:segment,:value,:seg_length)'
    USING SELF.object_id,p_index,p_segment,p_value,lengthc(v_value)+2;
    But due to some performance issue ,I can't use like this.Can you please suggest can i use Bulk Inserts instead of 'EXECUTE IMMEDIATE' statement.
    If I can do,please give me an example.How can we give example when we don't know what you have now or what exactly needs to be done.?

  • Execute Immediate and the in list

    Hello,
    How do I format the in list when i am executing a query with execute immediate ?
    I want to check if a character value is in ('5', '6', '7') ? Execute immediate treats my in list as a string instead of checking to see if the given value is in ny list of values or not. Please see the code / output below.
    SQL> declare
    2
    3 v_result VARCHAR2 (1) := 'N';
    4 v_num_list1 VARCHAR2 (40) := '''5''';
    5 v_num_list2 VARCHAR2 (40) := '''5'',''6'',''7''';
    6
    7 v_in VARCHAR2 (100)
    8 := 'BEGIN IF (:txn_value IN (:case_list)) THEN :result := ''Y''; END IF; END;';
    9 v_ctrl_no varchar2(40) := '''5''';
    10 BEGIN
    11
    12 DBMS_OUTPUT.PUT_LINE ('txn_value: ' || v_ctrl_no);
    13 DBMS_OUTPUT.PUT_LINE ('case_list: ' || v_num_list1);
    14
    15 EXECUTE IMMEDIATE v_in
    16 USING IN v_ctrl_no, v_num_list1, OUT v_result;
    17
    18 DBMS_OUTPUT.PUT_LINE ('result is ''' || v_result || '''');
    19 v_result := 'N';
    20
    21 DBMS_OUTPUT.PUT_LINE ('txn_value: ' || v_ctrl_no);
    22 DBMS_OUTPUT.PUT_LINE ('case_list: ' || v_num_list2);
    23
    24 EXECUTE IMMEDIATE v_in
    25 USING IN v_ctrl_no, v_num_list2, OUT v_result;
    26
    27 DBMS_OUTPUT.PUT_LINE ('result is ''' || v_result || '''');
    28
    29 END;
    30 /
    txn_value: '5'
    case_list: '5'
    result is 'Y'
    txn_value: '5'
    case_list: '5','6','7'
    result is 'N'
    Thanks,
    Anna

    you can't use a bind variable for an in-list string.
    you can rebuild the dynamic statement each time, without a bind variable:
    sql := '... in ( ' || in_list_var ||' )...
    or, you can use instr:
    sql := ' ... instr(:in_list_var, :txn_val) > 0 ...'
    using ','||in_list, ','||txn_val||','; -- notice the extra commas

  • How to set multiple parameters in one EXECUTE IMMEDIATE sql

    I want to set both nls_language and nls_date_language, and set them as different languages. fnd_global.set_nls_context() doesn't work. So I think maybe I can use the EXECUTE IMMEDIATE, and add them together into one statement. But I don't know how to make that happen. Can anybody help me? Thanks very much.
    PS: It has to be done in one call.

    928091 wrote:
    Hey, thanks for your answer, I forgot to mention that it has to be in begin-end block, do you know how?EXEC is a SQL Plus API that can be used to run PL/SQL code. What it does is put the PL/SQL code in a BEGIN .. END block and run it.
    So you can also manually put the code in a BEGIN..END block and run like this.
    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 dont understand what possible benefit does it makes to do a single execution into a BEGIN..END over multiple execution.
    Why this code is not of your interest, something like this
    begin
         execute immediate 'alter session set nls_date_language = ''AMERICAN''';
         execute immediate 'alter session set nls_language = ''AMERICAN''';
    end;
    /

  • Using where clause with hardcode value in execute immediate

    Dear Experts, I am using below in stored procedure getting exception,
    EXECUTE IMMEDIATE 'DELETE FROM CC.TB WHERE COL='HG'';
    where col is varchar2(30) in CC.TB
    Please guide how can i use above statement in stored procedure
    Thanks,

    DBA wrote:
    Dear Experts, I am using below in stored procedure getting exception,
    EXECUTE IMMEDIATE 'DELETE FROM CC.TB WHERE COL='HG'';
    where col is varchar2(30) in CC.TB
    Please guide how can i use above statement in stored procedure
    Thanks,Why are you using Dynamic SQL? DELETE statement is a DML statement and its valid inside a PL/SQL block.
    So you can remove the execute immediate and write your DELETE statement directly.
    begin
      delete from cc.tb where col = 'HG';
    end;

  • EXECUTE IMMEDIATE Procedure from another schema

    When running this procedure... I get an error ORA-00900.
    Does someone kwow the problem? Can we launch procdeure in EXECUTE IMMEDIATE?
    DECLARE
    jobname VARCHAR2(10) := 'test';
    datedebut DATE := SYSDATE;
    statut VARCHAR2(10) := 'En cours';
    BEGIN
    EXECUTE IMMEDIATE 'WEXPSTAGN_DEVL.bicstg_standard.ins_log_job('''||jobname||''',
    '''||statut ||''',
    '||datedebut ||')';
    END;
    Edited by: 995370 on 2013-03-21 07:58

    995370 wrote:
    When running this procedure... I get an error ORA-00900.
    Does someone kwow the problem? Can we launch procdeure in EXECUTE IMMEDIATE?
    DECLARE
    jobname VARCHAR2(10) := 'test';
    datedebut DATE := SYSDATE;
    statut VARCHAR2(10) := 'En cours';
    BEGIN
    EXECUTE IMMEDIATE 'WEXPSTAGN_DEVL.bicstg_standard.ins_log_job('''||jobname||''',
    '''||statut ||''',
    '||datedebut ||')';
    END;
    Edited by: 995370 on 2013-03-21 07:58You just want to do...
    DECLARE
      jobname VARCHAR2(10) := 'test';
      datedebut DATE := SYSDATE;
      statut VARCHAR2(10) := 'En cours';
    BEGIN
      WEXPSTAGN_DEVL.bicstg_standard.ins_log_job(jobname,statut,datedebut);
    END;No need for execute immediate (and you were using it wrongly anyway)

  • Creating cursor using Execute immediate

    I am trying to create one cursor using a for loop, but I am not able to do so, could you please help me with the approach to get it done.
    Here is the scenario:
    I have one table table_1,it contains 2 columns source_query , target_query.
    source_query and target_query are Select statements like source_query is Select name, age , valid from customer where customer_id=123456;
    I fetched the data from these columns into 2 strings
    select source_query into source_data from table_1;
    select target_query into target_data from table_1;
    Now out of these 2 I want to create 2 cursors, so that I can compare the column values one by one ( I am not using the  source minus target approach because of difference in the data type).
    I have to individually check the values.
    So here are the cursors:
    For source_data_value in ( EXECUTE immediate source_data)
    LOOP
    For target_data_value in (EXECUTE IMMEDIATE target_data)
    LOOP
    <executable statements>;
    END LOOP;
    END LOOP;
    But the cursor creation is failing in the procedure.
    Please let me know if it is possible to create a cursor using the execute immediate , if not what approach I should use other than this?

    Why exactly you are doing this inside a procedure. You can take the SQL's out and write a simple query to retrieve the data. Anyways, to work it out in a procedure, I can think of the below solution. I am trying to do away with Execute Immediate and use REF cursor. Please note that this is untested and just a try to present a possible solution which can be changed to implement your original requirement. I haven't done anything sort of this before, so if this approach doesn't approach, kindly ignore
    DECLARE
       TYPE TempTyp IS REF CURSOR;
       temp_cv   TempTyp;
      temp_cv_2 Temptyp;
       emp_rec  emp%ROWTYPE;
       source_data VARCHAR2(200);
         target_data  VARCHAR2(200);
       BEGIN
       source_data:= 'SELECT * FROM source tablej';
       target_Date :='select * from target table';
       OPEN temp_cv FOR source_data;
       LOOP
          FETCH temp_cv INTO emp_rec;
          EXIT WHEN emp_cv%NOTFOUND;
            OPEN   temp_cv_2 FOR target_data;
              FETCH Temp_cv_2 into  emp_rec  emp%ROWTYPE
                   loop
                        < And then your comparisons here >
         END LOOP:
         CLOST TEMP_CV_2;
       END LOOP;
       CLOSE temp_cv;
    END;
    Ishan

  • Disadvantage with 'Execute Immediate'

    What is the disadvantage with 'EXECUTE IMMEDIATE'.

    I think you guys are missing the point here.
    None of the issues listed are 'EXECUTE IMMEDIATE' disadvantages.
    'EXECUTE IMMEDIATE' is a tool. Like DMS_SQL. Like ref cursors. Like explicit cursor. Like implicit cursors.
    A tool, any tool, needs to be used correctly. If you use a hammer and hit a nail so hard that it bents, causing the hammer to slip doing some serious damage to your thumb... whose fault it is?
    Is it The Hammer that is at fault here? Or is the user of that tool?
    There are no disadvantages to using 'EXECUTE IMMEDIATE'. It is a tool. But like all tools it needs to be used correctly and safely. Things like excessive hard parsing because of a severe lack of bind variables, or opening a hole for SQL injection, etc.. all these are symptoms of - and let's be blunt here - an ignorant developer. It has nothing to do with the tool 'EXECUTE IMMEDIATE'.
    And those same type of errors will be made by Mr Ignorant Developer using other tools in Oracle.
    Shoddy workmanship is not because of poor tools. Shoddy code is not because of using a specific feature (like execute immediate).
    The proper question to ask is thus not "what are the disadvantages of execute immediate", but rather "where should I typically use execute immediate and how?".
    Not every developer will know how to use every single tool in the toolbox (I sure don't know all the tools in the Oracle toolbox). So there is nothing wrong with asking.
    But asking what is "wrong" with a tool (aka "what are the disadvantages") is in my view seriously missing the point that a tool is there to solve very specific types of problems...
    That is what a developer should be after - How to use the tool correctly.

  • EXECUTE IMMIDIATE AND INSERT?

    Hi ALL,
    I want to know the difference between Execute Immediate and Insert statement???

    Hi,
    Welcome to the forum!
    Insert: add rows to a table, the base table of a view, a partition of a partitioned table or a subpartition of a composite-partitioned table, or an object table or the base table of an object view (more information: INSERT)
    Execute immediate: builds and executes a dynamic SQL statement in a single operation. It is the means by which native dynamic SQL processes most dynamic SQL statements (more information: [EXECUTE IMMEDIATE|http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/executeimmediate_statement.htm#i33888])
    Regards,

  • Usinga CLOB variable in an execute immediate

    HI,
    I'm trying to concatenate a huge sql statement and then pass the variable to an execute immediate . the sql statement could be bigger than 4000bytes and so I'm using a clob variablle. Is it possible for me to pass this clob variable to an execute immediate?
    DECLARE
    var_stmt clob;
    Begin
    var_stmt := 'The statement I want which may be more than 4000bytes'
    execute immediate var_stmt;
    END;
    This how I'm trying to do it. Has anybody come acroos something like this?
    Thanks,
    Mamata

    if your sql statement will not exceed 32K, you could use the PL/SQL VARCHAR2(32767) type variable to hold upto 32K of the SQL statement.
    DECLARE
      var_stmt LONG;
    Begin
      var_stmt := 'The statement I want which may be more than 4000bytes'
      execute immediate var_stmt;
    END;

Maybe you are looking for

  • In Nautilus, mounted network shares not showing up right away

    I've noticed a strange problem recently (last couple of weeks) where my mounted network shares don't always show up right away in Nautilus (side bar or desktop- like they used to). For example, if I manually mount an NFS share in CL to /media/files i

  • ARD opens but no window on startup

    I've just cloned my install from one iMac to another with asr (new machine core 2 duo to i3) and now ARD doesn't start up properly. I get this in the logs Dec 15 08:46:15 its-pvm-imac Remote Desktop[2169]: Exception raised during posting of notificat

  • Mac mail bounce back when forwarded

    Help! I use mac mail on my ibook to get mail from my go daddy server. Recently I cannot forward mail to one of my 3 accounts. when I try I get this message: Hi. This is the qmail-send program at p3plsmtpa01-07.prod.phx3.secureserver.net. I'm afraid I

  • Rectify the error

    <%@ page language="java"%> <%@ page import="java.text.*,java.sql.*,java.util.*,javax.servlet.*,javax.servlet.http.* " %> <% try {                String uid = request.getParameter("idno").trim();                String pwd=request.getParameter("pwd").t

  • I was working on pages and sudenly it stops working, its open but i can´t eject any action

    I WAS WORKING ON PAGES. THEN I COPY SOME CONTENTS FROM ONE FILE AND TRIED TO PASTE IT ON OTHER FILE, BUT IT JUST DIDN´T . MY MACBOOK CRIIED!!!! I MEAN IT START DOINGAN STRANGE NOISE AND WHEN I SELECT AGAIN THE FILE FROM WHERE I COPY TJ¡HE CONTENTS IT