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: Why doesn't this work - function failing?

Re: Why doesn't this work - function failing?

From: Paul <paul_at_see.my.sig.com>
Date: Fri, 12 Aug 2005 18:18:20 +0100
Message-ID: <g9mpf1tfie4p89n8pnc1j88pbnded053f8@4ax.com>

Paul <paul_at_see.my.sig.com> wrote:

> I have a .csv dump routine (code at end of post) and it's not working.

OK, I have this figured out. But a new problem has arisen.



CREATE OR REPLACE procedure test_dump_csv as

    l_rows number;

        billy varchar2(30); <--------- Added line begin

    DBMS_OUTPUT.put_line('Here is OK'); <------- Added line     l_rows := dump_csv( 'select * from scott.emp', ',', 'D:\Paul', 'test.csv');

	billy := TO_CHAR(l_rows);    <------------ Added line
	DBMS_OUTPUT.put_line('Hi there' + billy);   <---- Added line
end;
/

This works without the added lines. What I can't understand is why I'm getting this error when I try to run it in SQLPlus - it's just basic debugging code?

Thanks for any hints.

Paul...

dump_csv_code is as before.  

> dump_csv code ------------------------------------
> CREATE OR REPLACE function dump_csv(p_query in varchar2,
> p_separator in varchar2 default
> ',',
> p_dir in varchar2,
> p_filename in varchar2) return
> number
> AUTHID CURRENT_USER is
> l_output utl_file.file_type;
> 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 '';
> l_cnt number default 0;
> begin
> l_output := utl_file.fopen(p_dir, p_filename, 'w');
> 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);
> utl_file.put(l_output, l_separator || l_columnValue);
> l_separator := p_separator;
> end loop;
> utl_file.new_line(l_output);
> l_cnt := l_cnt + 1;
> end loop;
> dbms_sql.close_cursor(l_theCursor);
> utl_file.fclose(l_output);
> return l_cnt;
> end dump_csv;
> /
> ------------------------------------------------

-- 

plinehan __at__ yahoo __dot__ __com__

XP Pro, SP 2, 

Oracle, 9.2.0.1.0 (Enterprise Ed.)
Interbase 6.0.1.0;

When asking database related questions, please give other posters 
some clues, like operating system, version of db being used and DDL.
The exact text and/or number of error messages is useful (!= "it didn't work!").
Thanks.
 
Furthermore, as a courtesy to those who spend 
time analysing and attempting to help, please 
do not top post.
Received on Fri Aug 12 2005 - 12:18:20 CDT

Original text of this message

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