完整例子贴出来吧 create or replace function test_1905101 return varchar2 is v_str clob; begin dbms_lob.createtemporary(v_str,true); dbms_lob.append(v_str,'12345'); return(v_str); end ;select test_1905101() from dual;
create or replace function test2 return clob is v_clob CLOB; begin DECLARE v_char VARCHAR2(100); BEGIN v_char := '123456'; dbms_lob.createtemporary(v_clob,TRUE); dbms_lob.append(v_clob,v_char); --dbms_output.put_line(v_clob); end; return v_clob; END test2; 返回的 v_clob 为123 ,如果是执行输出的话就输出123456
说一下你的调用过程 SQL> SQL> create or replace function test2 return clob is 2 v_clob CLOB; 3 begin 4 DECLARE 5 v_char VARCHAR2(100); 6 BEGIN 7 v_char := '123456'; 8 dbms_lob.createtemporary(v_clob,TRUE); 9 dbms_lob.append(v_clob,v_char); 10 end; 11 return v_clob; 12 END test2; 13 / Function created SQL> set serverout on; SQL> declare 2 c clob; 3 d clob; 4 begin 5 select test2 into c from dual; 6 dbms_output.put_line('c=' || c); 7 d := test2; 8 dbms_output.put_line('d=' || d); 9 end; 10 / c=123456 d=123456 PL/SQL procedure successfully completed SQL> drop function test2; Function droppedSQL>
create or replace function test_1905101 return varchar2 is
v_str clob;
begin
dbms_lob.createtemporary(v_str,true);
dbms_lob.append(v_str,'12345');
return(v_str);
end ;select test_1905101() from dual;
v_clob CLOB;
begin
DECLARE
v_char VARCHAR2(100);
BEGIN
v_char := '123456';
dbms_lob.createtemporary(v_clob,TRUE);
dbms_lob.append(v_clob,v_char);
--dbms_output.put_line(v_clob);
end;
return v_clob;
END test2;
返回的 v_clob 为123 ,如果是执行输出的话就输出123456
SQL>
SQL> create or replace function test2 return clob is
2 v_clob CLOB;
3 begin
4 DECLARE
5 v_char VARCHAR2(100);
6 BEGIN
7 v_char := '123456';
8 dbms_lob.createtemporary(v_clob,TRUE);
9 dbms_lob.append(v_clob,v_char);
10 end;
11 return v_clob;
12 END test2;
13 /
Function created
SQL> set serverout on;
SQL> declare
2 c clob;
3 d clob;
4 begin
5 select test2 into c from dual;
6 dbms_output.put_line('c=' || c);
7 d := test2;
8 dbms_output.put_line('d=' || d);
9 end;
10 /
c=123456
d=123456
PL/SQL procedure successfully completed
SQL> drop function test2;
Function droppedSQL>