Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Problem with DBMS_SQL

Re: Problem with DBMS_SQL

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Wed, 15 Apr 1998 01:00:44 GMT
Message-ID: <35340645.1118878@192.86.155.100>


A copy of this was sent to Cory Brooks <coryb_at_lilly.com> (if that email address didn't require changing) On Tue, 14 Apr 1998 15:20:56 -0400, you wrote:

>I am getting an invalid character error when I try to execute a stored
>procedure containing a dbms_sql.parse command.
>
>If I hard code the "statement" (second parameter), it works ok.
>Eg. dbms_sql.parse(cursor_#,'Select ...',DBMS_SQL.V7);
>
>
>If I build the statement in a Varchar2 or Char variable
>Eg.
>SQL_STMT := 'Select ...';
>DBMS_SQL.PARSE(CURSOR_NUM,SQL_STMT,DBMS_SQL.V7);
>

You might want to use

SQL> set serveroutput on

in sqplus and put

  dbms_output.put_line( sql_stmt );

before the dbms_sql.parse so you can see if what you think you are parsing matches what is being parsed.

>fails with the following message:
>*
>ERROR at line 1:
>ORA-20400: ORA-00911: invalid character
>
>Has anyone successfully used a character variable for the statement and
>if so, was it necessary to do anything special?

It works with variables just fine -- nothing special needs to be done, here is an example

create or replace procedure csv( p_query     in varchar2,
                                 p_separator in varchar2 default ',' )
is
    l_theCursor     integer default dbms_sql.open_cursor;
    l_columnValue   varchar2(2000);
    l_status        integer;
    l_colCnt        number default 0;
    l_separator     varchar2(10) default '';
begin

    dbms_sql.parse( l_theCursor, p_query, dbms_sql.native );

    for i in 1 .. 255 loop

        begin
            dbms_sql.define_column( l_theCursor, i, l_columnValue, 2000 );
            l_colCnt := i;
        exception
            when others then
                if ( sqlcode = -1007 ) then exit;
                else
                    raise;
                end if;
        end;

    end loop;

    dbms_sql.define_column( l_theCursor, 1, l_columnValue, 2000 );

    l_status := dbms_sql.execute(l_theCursor);

    loop

        exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );
        l_separator := '';
        for i in 1 .. l_colCnt loop
            dbms_sql.column_value( l_theCursor, i, l_columnValue );
            dbms_output.put( l_separator || l_columnValue );
            l_separator := p_separator;
        end loop;
        dbms_output.new_line;

    end loop;
    dbms_sql.close_cursor(l_theCursor); end csv;

>TIA
>Cory Brooks
 

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA  

http://govt.us.oracle.com/ -- downloadable utilities  



Opinions are mine and do not necessarily reflect those of Oracle Corporation  

Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Tue Apr 14 1998 - 20:00:44 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US