老是游标调用的时候提示为:什么老是提示游标已经打开??代码如下 create or replace function get_chartdispathunit(tid in integer) return varchar is Result varchar(50); strx varchar(50); cursor rad_cursor(ttid integer) is select ut.tunitname as tunitname from chart_dispatch_tbl cdt,unit ut where cdt.uni_pm_rowid=ut.pm_rowid and cdt.des_pm_rowid=ttid; rad_val rad_cursor%ROWTYPE; begin Result:=''; strx:=''; open rad_cursor(tid); for ral_val in rad_cursor(tid) loop strx:=rad_val.tunitname; Result:=Result+','+strx; end loop; close rad_cursor; return(Result); end get_chartdispathunit; 能否搞个列程玩玩
现在我执行也没有问题了。 可是取到的返回串是空的只有“ ,,,” 这是则么回事 代码如下 create or replace function get_chartdispathunit(tid in integer) return varchar is Result varchar(50); strx varchar(50); cursor rad_cursor(ttid integer) is select ut.tunitname from chart_dispatch_tbl cdt,unit ut where cdt.uni_pm_rowid=ut.pm_rowid and cdt.des_pm_rowid=ttid; rad_val rad_cursor%ROWTYPE; begin Result:=''; strx:=''; /*close rad_cursor; open rad_cursor(tid);*/ for ral_val in rad_cursor(tid) loop strx:=rad_val.tunitname; Result:=Result || ',' || strx; end loop; /*close rad_cursor; */ return(Result); end get_chartdispathunit;bzszp(SongZip)帮我看看。
我的调用语句如下: select t.pm_rowid,t.cha_pm_rowid,t.chart_name, GET_CHARTDISPATHUNIT(t.pm_rowid) unitname, from design_chart t
open rad_cursor(tid);*/这一句可以去掉,oracle以隐式打开游标,并自动关闭 看不出有什么错误 你在end之前加上DBMS_OUTPUT.PUT_LINE(result); 执行之前运行:SET SERVEROUTPUT ON; exec get_chartdispathunit(...);看输出结果是什么
set serveroutput on; .... open rad_cursor(tid);*/ for ral_val in rad_cursor(tid) loop strx:=rad_val.tunitname; Result:=Result || ',' || strx; dbms_output.put_line('Result is:'||Result);//加上输出看取出数据没有, end loop; ...... 你已经检查了游标是正确的吧
把在sql*plus里面的执行过程(包括全部代码,错误信息),都贴出来 show error命令查看错误详细信息
bzszp(SongZip): 调试错误 SQL>EXEC GET_CHARTDISPATHUNIT(232) BEGIN GET_CHARTDISPATHUNIT(232); END; * ERROR at line 1: ORA-06550:line 1,column 7: PLS-00221:'GET_CHARTDISPATHUNIT' is not a procedure or is undefined
close rad_cursor; //之前没游打开为什么要关闭?open rad_cursor;//使用带参数的游标的话,怎么没有参数?建议找个pl/sql例子,或教程看看
bzszp(SongZip)能否提供一个:类似的对带参数游标的记录进行遍历 的列程
谢谢!
create or replace function get_chartdispathunit(tid in integer) return varchar is
Result varchar(50);
strx varchar(50);
cursor rad_cursor(ttid integer) is
select ut.tunitname as tunitname from chart_dispatch_tbl cdt,unit ut
where
cdt.uni_pm_rowid=ut.pm_rowid
and
cdt.des_pm_rowid=ttid;
rad_val rad_cursor%ROWTYPE;
begin
Result:='';
strx:='';
open rad_cursor(tid);
for ral_val in rad_cursor(tid)
loop
strx:=rad_val.tunitname;
Result:=Result+','+strx;
end loop;
close rad_cursor;
return(Result);
end get_chartdispathunit;
能否搞个列程玩玩
可是取到的返回串是空的只有“ ,,,”
这是则么回事
代码如下
create or replace function get_chartdispathunit(tid in integer) return varchar is
Result varchar(50);
strx varchar(50);
cursor rad_cursor(ttid integer) is
select ut.tunitname from chart_dispatch_tbl cdt,unit ut
where
cdt.uni_pm_rowid=ut.pm_rowid
and
cdt.des_pm_rowid=ttid;
rad_val rad_cursor%ROWTYPE;
begin
Result:='';
strx:='';
/*close rad_cursor;
open rad_cursor(tid);*/
for ral_val in rad_cursor(tid)
loop
strx:=rad_val.tunitname;
Result:=Result || ',' || strx;
end loop;
/*close rad_cursor; */
return(Result);
end get_chartdispathunit;bzszp(SongZip)帮我看看。
select t.pm_rowid,t.cha_pm_rowid,t.chart_name,
GET_CHARTDISPATHUNIT(t.pm_rowid) unitname,
from design_chart t
看不出有什么错误
你在end之前加上DBMS_OUTPUT.PUT_LINE(result);
执行之前运行:SET SERVEROUTPUT ON;
exec get_chartdispathunit(...);看输出结果是什么
如果不定义纪录rad_val rad_cursor%ROWTYPE;
那么我则样才可以在循环中提取到我要的字段呢??
现在有什么问题?
问题就是返回的是“,,,,”
我看了这个循环次数和记录条数相比,调用函数后游标里的记录数是正确的。
头很大呀!是不是类型不对,还是没有提取到该字段呀?
....
open rad_cursor(tid);*/
for ral_val in rad_cursor(tid)
loop
strx:=rad_val.tunitname;
Result:=Result || ',' || strx;
dbms_output.put_line('Result is:'||Result);//加上输出看取出数据没有,
end loop;
......
你已经检查了游标是正确的吧
我按你调试方法,
可是我怎么在PL/SQL DEVELOPER 中执行后看不到有输出呀?????
在
sql*plus 中执行exec get_chartdispathunit(232)也有错误呀?
show error命令查看错误详细信息
调试错误
SQL>EXEC GET_CHARTDISPATHUNIT(232)
BEGIN GET_CHARTDISPATHUNIT(232); END; *
ERROR at line 1:
ORA-06550:line 1,column 7:
PLS-00221:'GET_CHARTDISPATHUNIT' is not a procedure or is undefined