create or replace function fun_content(id in Number) return varchar2 is
  return_content varchar2(512);
rown Integer := 0;/*行数*/
nline Integer := 0; /*用户换行次数*/
chnum Integer := 0;/*上次换行位置到下次换行位置之间的字符数(按字节)*/
location Integer := 1;/*当前换行符位置(按字节)*/
temp_content Varchar2(512);
Begin
Select (lengthb(field_content)-lengthb(Replace(field_content,chr(10),Null))) Into nline From tbl_test Where field_id = id;
For i In 1..nline Loop
  Select instrb(field_content,chr(10),1,i) Into chnum From tbl_test Where field_id = id;
  chnum := chnum - location;
  /*这里写成
  Select instrb(field_content,chr(10),1,i)-location Into chnum From tbl_test Where field_id = id;
  的话,跟踪调试时发现chnum不会得到正确的值,始终是null,上面的Integer参数全部改成number也不行,没办法只好分两行实现*/
if (rown + ceil(chnum/90)) <= 5 Then
  select substrb(field_content,location,chnum) Into temp_content From tbl_test Where field_id = id;
  /*这里的temp_content也是得不到正确值,始终是null,将varchar2(512)改成tbl_test.field_content%type也不行*/
  return_content := return_content + temp_content;
  exit when rown >= 5 ;
Else
  select substrb(field_content,location,(5-rown)*90) Into temp_content From tbl_test Where field_id = id;
  return_content := return_content + temp_content;
  Exit;
end if;
  rown := rown + ceil(chnum/90);
  location := location + chnum;
End Loop;
  return(return_content);
end fun_content;
/*
请问为什么会出现这种情况,是不是因为substrb返回的数据类型不一致?
函数是可以正确编译通过的,只是返回的不是期望的结果
*/