Error in execute immediate statement

i am writing a stored procedure i am getting error
v_Sql NVARCHAR2(1500);
BEGIN
v_Sql := 'Select * from vw_FillPatient Where 1 = 1 ';
IF v_pVisitTypeID <> 0 THEN
v_Sql := v_Sql || ' AND VisitTypeID = ' || CAST(v_pVisitTypeID AS VARCHAR2) || '';
ELSE
IF v_pVisitTypeID = 0 THEN
v_Sql := v_Sql || ' AND VisitTypeID In (1,2,6)';
END IF;
END IF;
v_Sql := v_Sql || ' AND VisitDate between ''' || TO_CHAR(v_pFromDate,'''DD_MON_YYYY''')
|| ''' and ''' || TO_CHAR(v_pToDate,'''DD-MON-YYYY''') || '''';
v_Sql := v_Sql || ' ORDER BY VisitID ';
EXECUTE IMMEDIATE v_Sql;-- error in this line as shown by SQL Developer
end;
error
Error(64,22): PLS-00382: expression is of wrong type

v_Sql NVARCHAR2(1500);
BEGIN
  V_SQL := 'Select * from vw_FillPatient Where 1 = 1 ';
  IF V_PVISITTYPEID=0 THEN
    v_Sql := v_Sql || ' AND VisitTypeID = ''' || CAST(v_pVisitTypeID AS VARCHAR2) || '''';
  ELSE
    IF v_pVisitTypeID = 0 THEN
      v_Sql          := v_Sql || ' AND VisitTypeID In (1,2,6)';
    END IF;
  END IF;
  V_SQL :=
  V_SQL || ' AND VisitDate between  to_date(''' ||V_PFROMDATE||''',''DD-MON-YYYY'') and '
        ||  'to_date('''||v_pToDate||''',''DD-MON-YYYY'')';
  v_Sql := v_Sql || ' ORDER BY VisitID ';
  EXECUTE IMMEDIATE v_Sql;-- error in this line as shown by SQL Developer
END;try it , please
I think your V_PFROMDATE, and V_PTODATE is varchar
elsif V_PFROMDATE and V_PTODATE id date then
V_SQL || ' AND VisitDate between  to_date(''' ||to_char(V_PFROMDATE,'DD-MON-YYYY')||''',''DD-MON-YYYY'') and '
        ||  ' to_date('''||to_char(v_pToDate,'DD-MON-YYYY')||''',''DD-MON-YYYY'')';Edited by: Mahir M. Quluzade on Mar 1, 2011 11:15 AM
Edited by: Mahir M. Quluzade on Mar 1, 2011 11:22 AM

Similar Messages

  • Error on execute immediate statement ?

    declare
    v_statement VARCHAR2(500);
    CURSOR Mov_Tab_to_ERP_Tbsp
    IS
    select t.table_name
    from user_tables t
    where t.tablespace_name='SYSTEM' or t.tablespace_name='USER';
    BEGIN
    FOR y IN Mov_Tab_to_ERP_Tbsp
    LOOP
    /* Build the statement */
    v_statement := 'Alter table ' || y.table_name ||' Move tablespace ERP;';
    execute immediate v_statement;
    END LOOP;
    END;
    I am getting the error of
    ORA-00911: invalid character
    ORA-06512: at line 14
    it is correct by the book....what could be the reason. ...Thanks in advance.

    Hi,
    try below given code
    DECLARE
       v_statement   VARCHAR2 (500);
       CURSOR mov_tab_to_erp_tbsp
       IS
          SELECT t.table_name
            FROM user_tables t
           WHERE t.tablespace_name = 'SYSTEM' OR t.tablespace_name = 'USER';
    BEGIN
       FOR y IN mov_tab_to_erp_tbsp
       LOOP
    /* Build the statement */
          v_statement :=
                        'Alter table ' || y.table_name || ' Move tablespace ERP';/* removed ';'*/
          EXECUTE IMMEDIATE v_statement;
       END LOOP;
    END;*009*

  • How to make my Execute Immediate statement to work??

    Hi, Sir:
    I use SQL Oracle 9i,
    I have following procedure called by a trigger:
    CREATE OR REPLACE PROCEDURE emps_check IS
    s_sql VARCHAR2(500);
    BEGIN
    DBMS_OUTPUT.PUT_LINE('1. Start to Delete all rows in the emps' );
    delete from emps;
    DBMS_OUTPUT.PUT_LINE('2. Start to insert into emps from emp' );
    s_sql:='INSERT INTO Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) select EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO from emp;';
    DBMS_OUTPUT.PUT_LINE('3. s_sql= ' || s_sql );
    EXECUTE IMMEDIATE s_sql;
    DBMS_OUTPUT.PUT_LINE('3. Procedure call OK, Employ Name ' );
    EXCEPTION
    -- Use this to trap the ORA-00942: table or view does not exist
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Procedure call Exception: Employ Name ' );
    end emps_check;
    My trigger is:
    CREATE OR REPLACE TRIGGER emps_biu_after
    after INSERT OR UPDATE or delete on emp
    for each row
    begin
    if TO_CHAR(SYSDate,'DY')= 'SUN'
    then
    DBMS_OUTPUT.PUT_LINE('Today is holiday, ename =' );
    else
    DBMS_OUTPUT.PUT_LINE('Today is working Day, ename =');
    emps_check();
    end if;
    end;
    When I use following to update emp table:
    SQL> UPDATE emp T1
    2 SET T1.sal = 200.0
    3 WHERE T1.ename like '%SCOTT%';
    I got:
    Today is working Day, Trigger Call Procedure emps_check()
    1. Start to Delete all rows in the emps
    2. Start to insert into emps from emp
    3. s_sql= INSERT INTO Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) select EMPNO,ENAME,JOB,MGR
    Procedure call Exception: Employ Name
    Trigger Call Procedure emps_check() Success
    Looks like EXECUTE IMMEDIATE s_sql; did not work.
    What is wrong??
    How to make my Execute Immediate statement to work??
    Thanks

    You may omit the ';' character...
    s_sql:='INSERT INTO
    Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
    select EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO
    from emp';
    ... and something else
    IN PL/SQL when a procedure , function doews not take
    any parameter(s) then its call can be made as simply
    its name without a pair of parenthesis....(It seems
    that you are influenced by Java...:) )
    SimThanks Sir:
    I remove this ; but still error:
    1 UPDATE emp T1
    2 SET T1.sal = 768.1
    3* wHERE T1.ename like '%SCOTT%'
    SQL> /
    Today is working Day, Trigger Call Procedure emps_check()
    1. Start to Delete all rows in the emps
    2. Start to insert into emps from emp
    3. s_sql= INSERT INTO Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) select EMPNO,ENAME,JOB,MGR,
    Procedure call Exception: Employ Name
    Trigger Call Procedure emps_check() Success
    My code as follows:
    CREATE OR REPLACE PROCEDURE emps_check IS
    s_sql VARCHAR2(500);
    BEGIN
    DBMS_OUTPUT.PUT_LINE('1. Start to Delete all rows in the emps' );
    delete from emps;
    DBMS_OUTPUT.PUT_LINE('2. Start to insert into emps from emp' );
    s_sql:='INSERT INTO Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) select EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO from emp';
    DBMS_OUTPUT.PUT_LINE('3. s_sql= ' || s_sql );
    EXECUTE IMMEDIATE s_sql;
    DBMS_OUTPUT.PUT_LINE('3. Procedure call OK, Employ Name ' );
    EXCEPTION
    -- Use this to trap the ORA-00942: table or view does not exist
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Procedure call Exception: Employ Name ' );
    end emps_check;
    what is other wrong??
    Yes, I am java guys,
    Thanks

  • Execute a DML query its length exceeds 4000 characters with execute immediate statement.

    I want to execute a DML query with execute immediate statement. That DML query length exceeds 4000 characters. This query has Xquery related conditions, i can not split the query. when i tried execute it is giving "string literal too long".  I tried with DBMS_SQL.Parse() and DBMS_SQL.Execute also, but it is giving same error. I have to execute this DML query inside a Procedure. Please help me to resolve this. We are using oracle 10g version
    Thanks & Regards,
    K.Kedarnadh

    Actually Query is a dynamic query. Query length will exceeds if the no of domains\domain values \products exceeds. Any way Below one is current dynamic query, which is generated within procedure
    SELECT
      IVT.ID_IVT
        ,IVT.ID_INS_IVT
      ,EXTRACTVALUE(IVT.DOCUMENT_IVT,'//productName/text()') AS PRODUCTNAME
      ,EXTRACTVALUE(IVT.DOCUMENT_IVT,'//elementName/text()') AS INSTANCENAME
      ,EXTRACTVALUE(IVT.DOCUMENT_IVT,'//elementInternalName/text()') AS INTERNALNAME
        ,CTG.NAME_CTG
        ,CTR.NAME_CTR
        ,MDL.NAME_MDL
      ,IVT.REEDIT_FLAG_IVT
        FROM  VARIATION_IVT IVT INNER JOIN CATEGORY_CTG CTG ON CTG.ID_CTG=IVT.ID_CTG_IVT
      AND IVT.STATUS_IVT='Active' AND IVT.DELETE_FLAG_IVT=0 AND IVT.ID_PRJ_IVT=1
      AND  IVT.DOCUMENT_IVT.existsnode('.//domain[domainName="Jurisdictions" and (domainValue="Delhi" or domainValue="Bangladesh" or domainValue="Mumbai" or domainValue="India" or domainValue="Pakistan" or domainValue="Nepal" or domainValue="Maldives" or domainValue="Kolkata" or domainValue="Bhutan" or domainValue="Chennai" or domainValue="ALL")]')=1 AND  IVT.DOCUMENT_IVT.existsnode('.//domain[domainName="Channels" and (domainValue="Agents" or domainValue="SBI" or domainValue="Maruti" or domainValue="Direct" or domainValue="CitiFinancial" or domainValue="SCB" or domainValue="BankAssurance" or domainValue="CitiBank" or domainValue="Employees" or domainValue="GE" or domainValue="Brokers" or domainValue="Telemarketing" or domainValue="Agency" or domainValue="ALL")]')=1 AND  IVT.DOCUMENT_IVT.existsnode('.//domain[domainName="ModeofDelivery" and (domainValue="Walkin" or domainValue="Internet" or domainValue="ALL")]')=1 AND  IVT.DOCUMENT_IVT.existsnode('.//context[(productName="ALL" or productName="A009" or productName="A010" or productName="A046" or productName="AccidentShieldClassic" or productName="AccidentShieldOnline" or productName="AM01" or productName="AM02" or productName="AME_Cancellation" or productName="ARHG" or productName="ARPA" or productName="B003" or productName="B004" or productName="B007" or productName="B008" or productName="B009" or productName="B010" or productName="B012" or productName="B013" or productName="B015" or productName="B016" or productName="B017" or productName="BC04_PA" or productName="BC06_FDP" or productName="BC06_PA" or productName="BC09" or productName="BC10" or productName="BC12" or productName="BC13" or productName="BF03" or productName="BS01" or productName="BS02" or productName="C017" or productName="C035" or productName="C036" or productName="C037" or productName="C038" or productName="C040" or productName="C041" or productName="C041Gold" or productName="C041New" or productName="C045HomeContents" or productName="C048" or productName="C049" or productName="C054" or productName="C057" or productName="C060Building" or productName="C060Contents" or productName="C060FDP" or productName="C061Building" or productName="C061Contents" or productName="C062" or productName="C063" or productName="C067" or productName="C070" or productName="C072" or productName="C074" or productName="C077" or productName="C081" or productName="C082" or productName="C087" or productName="C088" or productName="CITIFOREVER" or productName="CITISECURE" or productName="CITICHILDPLAN" or productName="D001" or productName="DB01" or productName="DD01" or productName="DD02" or productName="DD03" or productName="DD04" or productName="DD09" or productName="DD10" or productName="E005" or productName="E011" or productName="E016" or productName="E020" or productName="E030" or productName="E034" or productName="E040" or productName="E041" or productName="E045HCP" or productName="E045HSP" or productName="E049" or productName="E049New" or productName="E052" or productName="E053" or productName="E054FDP" or productName="E055" or productName="E056" or productName="E057" or productName="E058" or productName="E061" or productName="E061BATCH" or productName="E062" or productName="E063" or productName="E064HCP" or productName="E064HSP" or productName="E066" or productName="E069" or productName="E073" or productName="E075" or productName="E076" or productName="E088" or productName="E090" or productName="E093A" or productName="E093B" or productName="E095" or productName="E099A" or productName="E099B" or productName="E106" or productName="E107" or productName="E110" or productName="E112" or productName="E114" or productName="E115" or productName="E116" or productName="F001" or productName="FamilyHealthInsurance" or productName="FamilyHospitalBenefits" or productName="FamilyHospitalisationCoverBenefit" or productName="G001" or productName="G002" or productName="HealthShieldOnline" or productName="Health_B005" or productName="Health_S057" or productName="HealthSheild" or productName="HealthWalkin" or productName="HomeContentOnline" or productName="HomeShieldOnline" or productName="HomeShieldWalkin" or productName="HospitalCashOnline" or productName="J001" or productName="J008" or productName="K001" or productName="KV02" or productName="LC03" or productName="ML01" or productName="MP02" or productName="MP03" or productName="MR01" or productName="O005" or productName="PO01" or productName="PO02" or productName="PO03" or productName="PO04" or productName="PO05" or productName="PO06" or productName="RR02" or productName="RR03" or productName="RR04" or productName="S006" or productName="S033" or productName="S049" or productName="S051" or productName="S054" or productName="S057" or productName="S060" or productName="S061" or productName="S065" or productName="S065TM" or productName="S068" or productName="S076" or productName="S077" or productName="S079" or productName="S080" or productName="S081" or productName="S084" or productName="S085" or productName="S086" or productName="S087" or productName="S088" or productName="S091" or productName="S092" or productName="S093" or productName="S094" or productName="S095" or productName="S097" or productName="S098" or productName="S099" or productName="S100" or productName="S101" or productName="S102" or productName="S103" or productName="S104" or productName="S106" or productName="S107" or productName="S108" or productName="S109" or productName="S110" or productName="S111" or productName="S113" or productName="SCBNAC" or productName="SF02" or productName="SS01" or productName="SS02" or productName="SUNFHM" or productName="SurgicalShield" or productName="TD01" or productName="TD02" or productName="TP01" or productName="U002Building" or productName="U002Contents" or productName="U004Building" or productName="U007" or productName="U009" or productName="U013" or productName="U014" or productName="U015" or productName="U016" or productName="V001" or productName="V002" or productName="V005" or productName="V006" or productName="V008" or productName="W008" or productName="W020" or productName="W021" or productName="W022" or productName="W023" or productName="W024" or productName="W026" or productName="W027" or productName="W028" or productName="W029" or productName="W105" or productName="W106" or productName="WI01" or productName="WI02" or productName="WI03" or productName="WI07" or productName="WI08" or productName="WI09" or productName="WI10" or productName="WI11" or productName="WI12" or productName="WI13" or productName="WI14" or productName="WI17" or productName="WI20" or productName="WI21" or productName="WI21_Health" or productName="WI23" or productName="WI24" or productName="WI26" or productName="WI30" or productName="WI31" or productName="WI33" or productName="WI34" or productName="X001" or productName="X002" or productName="X003" or productName="X004" or productName="X005" or productName="X008" or productName="Y001" or productName="Y007" or productName="Y009" or productName="Y010" or productName="Y011" or productName="Y011H" or productName="Y020" or productName="Y020N" or productName="Z008" or productName="ZI001")]')=1
      INNER JOIN CENTER_CTR CTR ON CTR.ID_CTR=CTG.ID_CTR_CTG
        INNER JOIN MODEL_MDL MDL ON  MDL.ID_MDL=CTR.ID_MDL_CTR

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

  • 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

  • What can be the cause of Web ADI error : Cannot execute SQL statement?

    I created a custom integrator in r12.2.3 and while loading I encountered an error, Cannot execute SQL statement.
    I checked my setup in Interface attribute , the RUN_ID column has a default type SQL QUERY with a default value SELECT  XXCONV_EAM_ASSET_NUM_S.NEXTVAL FROM DUAL.
    If I have a right setup here, what can be the cause of this error?

    Hi,
    The possibilities can be of various reasons, with the sql statements,
    xml descriptors, data sources, improper drivers anything. To crack down
    the solution, kindly let me know the error messages and what exactly are
    you trying to accomplish.
    Thanks & Regards
    Raj
    manimaran t wrote:
    what may be the cause of this error java.sql.SQLException: invalid sql
    type passed to callable statement in iplanet ussing JNDI
    Try our New Web Based Forum at http://softwareforum.sun.com
    Includes Access to our Product Knowledge Base!

  • [Solved] Reference apex_application.g_fXX in "execute immediate" statement

    Hi!
    I created a dynamically generated tabular form - the number of columns is not known in advanced. Each cell of the form is a text item generated with apex_item.text().
    I want to write an after-submit process that saves the values from the form into a database table. In this process I already know how many columns there are in the report so I want to do the following:
    --for each row...
    for i in 1..apex_application.g_f01.count loop
      -- and for each column in that row (number of columns is in v_col_count)
      for j in 1..v_col_count loop
        -- get the value of text item
        v_query := 'select apex_application.g_f0' || j || '(' || i || ')' || ' from dual';
        execute immediate v_query into v_value;
        -- now do some DML with v_value
      end loop;
    end loop;The problem is that I get an error: ORA-06553: PLS-221: 'G_Fxx' is not a procedure or is undefined where xx is the number from the generated query.
    My question is - am I doing something wrong or is is just not possible to reference apex_application.g_fxx in "execute immediate"? Will I have to manually check for all 50 possibilites of apex_application.g_fxx? Is there another way?
    TIA,
    Jure

    Well now I know what was wrong and what you were trying to tell me - apex_application.g_fxx is not visible in "plain" SQL. And now I also have a solution to this problem. The point is to wrap the select statement with begin - end block so that the statement is rendered as pl/sql:
    --for each row...
    for i in 1..apex_application.g_f01.count loop
      -- and for each column in that row (number of columns is in v_col_count)
      for j in 1..v_col_count loop
        -- get the value of text item
        v_query := 'begin select apex_application.g_f0' || j || '(:i)' || ' into :x from dual; end;';
        execute immediate v_query using i, out v_value;
        -- now do some DML with v_value
      end loop;
    end loop;This works great :).
    Jure

  • How to use using clause in execute immediate statement??

    Hi ALL,
    Can u help me ....
    This is the code which I have written...
    declare
    type rec_typ is table of forall_test%rowtype;
    v_rectype rec_typ:=rec_typ();
    begin
    --poputating records
    for i in 1..10000 loop
    v_rectype.extend;
    v_rectype(v_rectype.last).id:=i;
    v_rectype(v_rectype.last).code:=to_char(i);
    v_rectype(v_rectype.last).description:='Description :'||to_char(i);
    end loop;
    execute immediate 'truncate table forall_test';
    forall i in v_rectype.first..v_rectype.last
    execute immediate 'insert into forall_test values :1' using v_rectype(i);
    commit;
    end;
    But I am getting this ERROR....
    execute immediate 'insert into forall_test values :1' using v_rectype(i);
    ERROR at line 14:
    ORA-06550: line 14, column 61:
    PLS-00457: expressions have to be of SQL types
    ORA-06550: line 14, column 1:
    PL/SQL: Statement ignored
    Thanks & Regards,
    T.Halder

    Thatmeans using statement cannot be a non sql type.True: You need an sql type for this:
    e.g. with
    create or replace type emp_typ
    as
       object (empno number (4),
               ename varchar2 (10 byte),
               job varchar2 (9 byte),
               mgr number (4),
               hiredate date,
               sal number (7, 2),
               comm number (7, 2),
               deptno number (2))
    create or replace type emp_tab as table of emp_typ
    /you can do
    --- an empty test table
    SQL> create table emp2
    as
       select *
       from emp
       where 1 = 2
    Table created.
    SQL> declare
       emp2_tab       emp_tab;
    begin
      /* fill the collection */
       select emp_typ (empno,
                       ename,
                       job,
                       mgr,
                       hiredate,
                       sal,
                       comm,
                       deptno)
       bulk collect into emp2_tab
       from emp
       where empno like '77%';
      --  forall loop
       forall c in 1 .. emp2_tab.count
          execute immediate 'begin
                               insert into emp2 select * from table(cast(emp_tab(:1) as emp_tab)) t;
                               update emp2 set sal = null where empno = (:1).empno and empno = 7788;
                             end;' using emp2_tab (c);
    end;
    PL/SQL procedure successfully completed.
    SQL> select empno, ename, sal from emp2
         EMPNO ENAME             SAL
          7782 CLARK            2450
          7788 SCOTT               
    2 rows selected.

  • How can i have '&' in EXECUTE IMMEDIATE statement?

    I have PL/SQL procedure, where i will be inserting data to a table. Data which i am inserting is having a '&' value in it. If i use the below statement for insert then sqlplus is prompting for the value '&' like a substitution value while compile this procedure.
    EXECUTE IMMEDIATE 'INSERT INTO TABLE_TEST VALUES (:1,:2)' USING 'root/direct/&text', SYSDATE;If i replace the '&' by assigning this value to VARCHAR field then it is working properly. But when i populate an xml from this table using DBMS.XMLGEN, then the value '&' is not entity escaped in the XML which is normally replaced with '&amp;' in XML.
    Please help.

    Vel wrote:
    i can't go by both ways because i am using '&' in various files to get some values. Also in this package i am using the '&' to get another substitution variable. Is there any other workaround possible?I prefer not to mess with server-side SQL and PL/SQL code to fix, or work around, a problem on the client-side. Not a very sensible thing IMO.
    In such a case as you've described, I would set the substitution character to a character that I'm not using in server-side code. I have done this a couple of times in the past for db create and installation scripts. Oracle uses the same approach for their Apex installation scripts.
    I think Oracle uses the +#+ character for their Apex install scripts. E.g.
    set define '#'I think I used the tilde (char <i>~</i>) at a stage as substitution char as it is very seldom used in PL/SQL and SQL code.
    The bottom line is that you will need to change your code. Set define off and on where needed to ensure substitution only happens where needed. Set the substitution char to a different char and update your substitution variables. Or hack your server-side code (as suggested above) and use the char() function instead.

  • Unable to execute EXECUTE IMMEDIATE statement in a stored procedure...

    Hi People,
    I use oracle 10g.In which i tried a procedure with follwing code and am thrown with the error that says,
    SQL>   create or replace procedure ptable(ptab varchar2) is
      2  lstmt varchar(200);
      3  begin
      4  lstmt:='CREATE TABLE '||ptab||'(a int,b varchar2(30)) ';
      5  execute immediate lstmt;
      6  end;
      7  /
    Procedure created.
    SQL>  exec ptable('hos');
    BEGIN ptable('hos'); END;
    ERROR at line 1:
    ORA-01031: insufficient privileges
    ORA-06512: at "VIDYA.PTABLE", line 5
    ORA-06512: at line 1Procedure has been created but error occurs while executing it.why do i get this error even though i possess DBA privilege?.which permission is lagging for me?.help me with ur suggestions.thanks in advance.
    With Regards
    VIDS

    Yep Yep.Perfect.It was the CREATE ANY TABLE privilege which i was lagging.I granted it to my schema and now got created with the table.Thanku so much for such a quick reply :).
    With Regards
    VIDS

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

  • Table or view does not exists error while executing select statement

    Hi,
    I am new to Oracle. I am getting a error while executing the select statement if i give table name without double quotes.
    Ex: Select * from Customer;
    But working fine when the table name is enclosed within a double quotes.
    Ex: Select * from "Customer";
    Is there any way to execute the select statement without the double quotes?
    Actually I am using NHibernate objects for data access.
    Thanks,
    Sai

    Actually I am using NHibernate objects for data access.And probably that's the problem:
    SQL> select * from mytab;
             A
             1
    SQL> select * from mYtAb;
             A
             1
    SQL> select * from MYTAB;
             A
             1
    SQL>  select * from MYTAb;
             A
             1Oracle statements are case insensitive and doesn't require double quotes unless the object names are reserved words.
    As wrote by others if table is created using double quotes it's name bacomes case-sensitive... and this could be the problem...
    Max
    [My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/02/05/gestione-degli-errori-in-sql-con-log-errors/]
    Edited by: Massimo Ruocchio on Feb 5, 2010 7:08 PM
    Added last comment..

  • Inserting variables to table by "execute immediate' statement

    EXECUTE IMMEDIATE 'INSERT INTO aTABLETKA_HISTORY
    (update_id,
    update_type,
    update_date,
    old_db_version,
    description,
    patch_number)
    values
    (' || m_id(v_rec) || ',
    '||m_package(v_rec)||',
    ''07-NOV-07'',
    ''snezi'',
    '||m_desc(v_rec)||',
    '||m_new(v_rec)||')';
    ORA-00917: missing comma
    ORA-06512: at line 142
    i cannot solve this,. can anybody help me?
    i have simillar insert:
    EXECUTE IMMEDIATE 'INSERT INTO ab_table_VERSION(property,version) values (''wiz_datalink'',' || my_version || ')';
    and this one statement work correctly

    Do NOT use "execute immediate". What is the reason for trying it this way?
    If the column update_date is of type date, then you have a bug in the code, as you are trying to insert a string. If it is not a date data type, then you have a bug, because it is not of type date.
    What is the outcome of:
    INSERT INTO aTABLETKA_HISTORY (update_id, update_type, update_date,
          old_db_version, description, patch_number)
       values (m_id(v_rec), m_package(v_rec), to_date('07-NOV-2007', 'dd-MON-yyyy'),
          snezi, m_desc(v_rec), m_new(v_rec) )
    /

  • Invalid Table Name error in EXECUTE IMMEDIATE

    Hi there.
    I am trying to truncate few debug tables I created a used ago. Refer the code
    declare
    lv_sql varchar2(100) := 'truncate table :b1';
    begin
    for i in (select object_name
                 from all_objects
                where object_type = 'TABLE'
                  and object_name like 'DEBUG_%'
                  and owner = user)
    loop             
       dbms_output.put_line('Table Name: '||i.object_name);
       execute immediate lv_sql using i.object_name;
    end loop;
    end;Seems to be correct (unless I messed something big). And, I get an error message:
    ORA-00903: invalid table name
    ORA-06512: at line 13Any idea? Thanks in advance.

    you can't bind table or column names... try this instead:
    declare lv_sql varchar2(100);
    begin for i in (select object_name
                  from all_objects
                where object_type = 'TABLE'
                  and object_name like 'DEBUG_%'
                  and owner = user) loop
                     dbms_output.put_line('Table Name: '||i.object_name);
       lv_sql := 'truncate table '||i.object_name;
       execute immediate lv_sql;
    end loop;
    end;Message was edited by:
    RACER
    forgot ending  tag

Maybe you are looking for