我正在尝试编写这样的代码
CREATE OR REPLACE PROCEDURE EMAIL_TABLE (errbuf OUT VARCHAR2,
retcode OUT NUMBER
) is
cursor head is
select column_name
from all_tab_columns a
where table_name= 'EMP'
order by column_id;
cursor line is
select column_name
from all_tab_columns a
where table_name= 'EMP'
order by column_id;
count3 number;
count4 number;
lines1 varchar2(3000) := '';
lines2 varchar2(3000) := '';
count1 number;
count2 number;
header1 varchar2(3000) := '';
header2 varchar2(3000) := '';
BEGIN
count2 := 0;
select count(1)
into count1
from all_tab_columns a
where table_name= 'EMP';
FOR I IN head LOOP
count2 := count2+1;
IF count2 != count1 THEN
header1 := header1||'"'||i.column_name||'"'||',' ;
ELSIF count1 = count2 THEN
header1 := header1||'"'||i.column_name||'"' ;
END IF;
END LOOP;
header2 := header1;
count4 := 0;
select count(1)
into count3
from all_tab_columns a
where table_name= 'EMP';
FOR I IN line LOOP
count4 := count4+1;
IF count4 = 1 THEN
lines1 := lines1||''''||'"'||''''||'||'||i.column_name ;
ELSIF count4 != count3 THEN
lines1 := lines1||'||'||''''||'"'||','||'"'||''''||'||'||i.column_name;
ELSIF count3 = count4 THEN
lines1 := lines1||'||'||''''||'"'||','||'"'||''''||'||'||i.column_name||'||'||''''||'"'||'''' ;
END IF;
END LOOP;
lines2 := lines1;
FND_FILE.PUT_LINE(fnd_file.output, header2);
EMAIL_TABLE2(lines2);
END;
/
CREATE OR REPLACE PROCEDURE EMAIL_TABLE2(abc in varchar2) is
xyz varchar2(1000);
cursor lines is
select abc a from EMP; -- This is not working
BEGIN
for i in lines loop
FND_FILE.PUT_LINE(fnd_file.output,i.a);
end loop;
END;
/
以上将注册为并发程序,fnd_file.pu_line 将在 o||req_numebr||.out 中创建。我将把这个输出文件附加到电子邮件中并邮寄。
Outfile 应如下所示:
"NAME","EMP_ID","DEPT","SAL"
"JOHN","101","IT","10000"
"ROB","102","SALES","8000"
第一行是来自 all_tab_columns 的标题,行来自作为参数传递的表。
请让我知道上述方法是否有效,或者是他们的任何方式。谢谢