Sql 在ORACLE中使用另一个过程调用过程
我正在尝试使用第二个过程调用一个过程。第一个过程将创建一个文件,而第二个过程将为游标中的每条记录调用第一个文件。我期望的结果是每个记录都有一个单独的文件。当我运行该过程时,它将在文件上创建并生成以下错误:Sql 在ORACLE中使用另一个过程调用过程,sql,oracle,relational-database,Sql,Oracle,Relational Database,我正在尝试使用第二个过程调用一个过程。第一个过程将创建一个文件,而第二个过程将为游标中的每条记录调用第一个文件。我期望的结果是每个记录都有一个单独的文件。当我运行该过程时,它将在文件上创建并生成以下错误: ORA-29283: invalid file operation ORA-06512: at "SYS.UTL_FILE", line 536 ORA-29283: invalid file operation ORA-06512: at "PS.EXPORT_PROC", line 30
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at "PS.EXPORT_PROC", line 30
ORA-06512: at "PS.LOOP_EXPORT_PROC2", line 15
ORA-06512: at line 2
Process exited.
第一个程序如下:
create or replace
PROCEDURE "EXPORT_PROC"
(Psectionid number)
is
output_file_one utl_file.file_type;
--------------------------------------------------------------
Cursor Crs is
select s.student_number student_number, s.lastfirst as student_name,
cc.expression, c.course_name, t.lastfirst,
ps_customfields.getstudentscf(s.id,'blend_learn_score') grade
from
cc join courses c
on cc.course_number=c.course_number
join students s
on cc.studentid=s.id
join teachers t
on cc.teacherid=t.id
where cc.termid in (2300,2301,2302)
and cc.sectionid IN(30024,30065, 30276, 30064, 30052)
and s.enroll_status=0;
-----------------------------------------------------------------
Begin
For rec in Crs LOOP
output_file_one := utl_file.fopen ( 'BLENDED_LEARNING', rec.lastfirst || '-' ||
rec.expression || '-' || rec.course_name || '.txt' , 'W');
utl_file.putF (output_file_one, 'Student_Number' || chr(9) || 'Student_Name'||chr(9)||'Grade');
utl_file.fflush(output_File_one);
END LOOP;
For rec in Crs LOOP
utl_file.put_line (output_file_one, rec.student_number || chr(9) || rec.student_name ||
chr(9) || REC.grade);
utl_file.fflush(output_file_one);
End Loop;
utl_file.fclose(output_file_one);
END;
第二个过程应将值传递给第一个过程
create or replace
PROCEDURE LOOP_EXPORT_PROC2
IS
Cursor Blended_Crs is
select distinct sectionid
from cc
inner join courses a on cc.course_number = a.course_number
where cc.termid >= 2300 and a.course_name like ('AR%') and cc.schoolid = 3;
BEGIN
For rec in Blended_Crs LOOP
EXPORT_PROC(rec.sectionid);
End Loop;
END LOOP_EXPORT_PROC2;
在第二个过程中,它应该循环并为crs2中的每个记录创建一个文件,但在运行该过程时,它将成功创建一个文件并生成顶部列出的错误
我已验证该目录的权限是否正确
我的问题是你能想出我会犯这个错误的原因吗?根据代码,它应该能够为第二个过程游标中的每个记录运行第一个过程一次。我这样做是为了能够将不同的周长传递到第一个过程中,并为每个周长创建不同的文件 您有几个语法错误。例如:
select distinct FIELD4
from
where perimeter1=TRUE, perimeter2 in (1,2,3);
应该是
select distinct FIELD4
from
where perimeter1=TRUE AND perimeter2 in (1,2,3);
此处缺少分号:
Cursor crs is
select field1 , field2, field3
from table1
您没有在此处正确关闭外部环路:
For rec in crs LOOP
output_file_one := utl_file.fopen ( 'DIRECTORY', 'file.txt' , 'W');
For rec in crs LOOP
utl_file.put_line (output_file_one, rec.field1 || chr(9) ||
rec.field2 || chr(9) || REC.field3);
End Loop;
utl_file.fclose(output_file_one);
在这里发布问题之前,您需要调查源代码中的编译错误。使用
显示错误
编译后,您可以查看错误。代码中存在大量错误。请更新以便我们提供帮助。@PatrickHofman,缩进代码可以,您不应该添加括号,删除引号并添加??不过。翻滚back@PatrickHofman请不要通过添加缺少的结构来更改代码end循环代码>例如,添加(在这种情况下不加评论)错误的一个-错误使用声明
关键字。@NicholasKrasnov:对不起,我认为声明是偶然的,我会删除它。所有其他的更改都是合乎逻辑的。我对代码进行了更改,缩小了它的范围,并试图使它与更多的人相关。很抱歉出现语法错误。我将删除此问题并重新发布原始程序。它们都会编译,但第二个会生成错误。如果perimeter1=TRUE
不可能,则不能在SQL中使用布尔表达式,也不能定义存储布尔值的列。此外,第一个游标声明后的半列丢失您的过程可能无效。使用-->select*from user_objects检查它,其中status='INVALID'我的原始语法错误错误。我修改了代码,使其不太通用,但看起来有一些错误。我已经发布了原始的程序,现在他们正在编译。