Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting "ORA-00932: inconsistent datatypes: expected - got CLOB"

GaffApr 20 2009 — edited Apr 21 2009
Hi:

I've got a stored procedure that is attempting to open a cursor for a SQL string and getting an error. The query in the string is only a select (i.e. I'm not updating anything). I'm not doing a bind because the sole reason for doing any of this is just to validate the SQL. I am given some XML and I translate it into SQL and before saving the XML off because I want to verify that it actually translates into valid SQL. The validation test is dmbs_sql.parse().

I've tried using varchar2 and CLOB as the sql string argument but still get the error. What is the inconsistency that Oracle is complaining about?

Oracle 10.2.0.3 on RHEL 4 (64 bit)

Thanks

PROCEDURE SaveXML(XMLClob in CLOB, status out integer) IS

    chandle                      INT;
    sqlString                     VARCHAR2(4000);
    errorString                  VARCHAR2(300) := 'NO ERRORS.' ;
    xmldata                      XMLType;  -- The XMLType format of the XML to transform
    xsldata                       XMLType;  -- The XMLType format of the stylesheet to apply
    stylesheetClob             CLOB;   -- The stylesheet in CLOB form.
 
    
BEGIN
    
    status := -1;
    
    -- Before saving, convert the XML to SQL and parse it to verify that it will in
    -- fact be able to be represented later as a valid SQL query.  
  
    -- Get the stylesheet from the stylesheet table. 

    select stylesheet into stylesheetClob from saved_query_stylesheets 
        where name = 'SAVED_QUERY.XSL' and rownum = 1
        order by version desc;
        
    xmldata := XMLType.createXML(XMLClob);
    xsldata :=  XMLType.createXML(stylesheetClob);

    sqlString := rto_char(dbms_xmlgen.convert(xmldata.transform(xsldata).getStringVal(),
                dbms_xmlgen.ENTITY_DECODE) ) ;
    
    -- dbms_output.put_line('Length of query string is ' || length(sqlString));
      
    if(length(sqlString) <= 0) then
        dbms_output.put_line('NO sqlString obtained!');
        return;
    end if;
        

    begin -- catch the exception in this block

        dbms_output.put_line('SaveXML(): parsing XML now.'); 

        -- The parse command wants a cursor
        chandle := dbms_sql.open_cursor;    
        Dbms_sql.parse(chandle, sqlString, DBMS_SQL.NATIVE);
        DBMS_SQL.CLOSE_CURSOR(chandle);

        status := 0;
        dbms_output.put_line('SaveXML() successful!!  Returning...');

        EXCEPTION
            WHEN OTHERS THEN  
            DBMS_SQL.CLOSE_CURSOR(chandle);        
            DBMS_OUTPUT.PUT_LINE('Exception occurred and caught! ' || SQLERRM);
            
    end ;   
            
EXCEPTION
  WHEN OTHERS THEN          
   DBMS_OUTPUT.PUT_LINE('Exception occurred ' || SQLERRM);
  
  status := 0;
  
  
END SaveXML;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 19 2009
Added on Apr 20 2009
2 comments
1,218 views