SPOOL E:\SP.txt;
declare
v1 varchar2(20);
begin
select ename into v1 from emp where empno = 7369;
dbms_output.put_line(v1);
end;
SPOOL OFF;或者用utl_file包
declare
v1 varchar2(20);
begin
select ename into v1 from emp where empno = 7369;
dbms_output.put_line(v1);
end;
SPOOL OFF;或者用utl_file包
你给我的答复是:SPOOL E:\SP.txt;
declare
v1 varchar2(20);
begin
select ename into v1 from emp where empno = 7369;
dbms_output.put_line(v1);
end;
SPOOL OFF;
我把上面的代码写到一个文本中,保存为my.sql,然后在sqlplus上执行@my.sql
它为什么总是报sql statement error错误,说是第一行有错,这是为什么,请帮忙!谢谢!
我修改了一下代码,如果直接写成
spool e:sp.txt
select * from emp;
spool off
这样是可以执行的,所以我想是不是我上面写了declare,就不行了,所以我想有没有别的什么加法,你可以试一下。
declare
file_handle UTL_FILE.FILE_TYPE;
begin
file_handle := UTL_FILE.FOPEN('/tmp', '文件名', 'w');
UTL_FILE.PUTF(file_handle, '写入的信息\n');
UTL_FILE.FCLOSE(file_handle);
exception
WHEN utl_file.invalid_path THEN
raise_application_error(-20000, 'ERROR: Invalid path for file or path not in INIT.ORA.');
end; PutF()过程用来以指定格式把文本写入一个文件Put_Line()过程把一个指定的字符串写入文件并在文件中开始新的一行