由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 谁能帮我看看这个oracle function有什么错?
相关主题
PL/SQL 输入DATA这个新功能我喜欢
open cursor for collection?求教mysql数据库构建
SQL run a stored procedure by fetching from a cursor row by row[转载] Hehe,不好意思,another question:)
新手求教,plsql collection 参数传入问题,非常感谢。can I create a recordset with cursor?
菜鸟急问ORACLE里FUNCTION返回ref cursor的问题ORA-01002: fetch out of sequence问题
SQL Server - how to obtain data type nameA question of filling in missing value in SQL
求救!!! 一个oracle的问题! 在procedure中所涉及的表名可以用变量从参数中传入吗SQL query 一问
求救!!! 一个oracl的问题淀请问sql server里面怎么输出变量到文本文件?
相关话题的讨论汇总
话题: lcl话题: cur话题: name话题: rec话题: loop
进入Database版参与讨论
1 (共1页)
j*****4
发帖数: 283
1
REATE OR REPLACE FUNCTION f_test (in_activity_id IN INTEGER)
RETURN VARCHAR2 AS
declare
cursor p_cur is
select coalesce(f.FULL_NAME , g.FULL_NAME) as p_name
from OCER_ACT_PRE e
left join ocer_p f on e.P_ID = f.ID
left join view2 g on f.person_id = g.person_id
where e.activity_id = in_activity_id;
p_rec p_cur%ROWTYPE;
lcl_p_list varchar2;
BEGIN
OPEN pr_cur;
LOOP
FETCH p_cur INTO p_rec;
EXIT WHEN p_cur%NOTFOUND;
lcl_p_list := pr_rec.p_name;
END LOOP;
CLOSE p_cur;
return lcl_p_list;
END;
B*****g
发帖数: 34098
2
干嘛要loop?

【在 j*****4 的大作中提到】
: REATE OR REPLACE FUNCTION f_test (in_activity_id IN INTEGER)
: RETURN VARCHAR2 AS
: declare
: cursor p_cur is
: select coalesce(f.FULL_NAME , g.FULL_NAME) as p_name
: from OCER_ACT_PRE e
: left join ocer_p f on e.P_ID = f.ID
: left join view2 g on f.person_id = g.person_id
: where e.activity_id = in_activity_id;
: p_rec p_cur%ROWTYPE;

j*****4
发帖数: 283
3
想得到所有的 p_name.
Thanks.
改了一下,怎么也不能 compile.
REATE OR REPLACE FUNCTION f_test (in_activity_id IN INTEGER)
RETURN VARCHAR2 AS
declare
cursor p_cur is
select coalesce(f.FULL_NAME , g.FULL_NAME) as p_name
from OCER_ACT_PRE e
left join ocer_p f on e.P_ID = f.ID
left join view2 g on f.person_id = g.person_id
where e.activity_id = in_activity_id;
p_rec p_cur%ROWTYPE;
lcl_p_list varchar2;
BEGIN
OPEN p_cur;
LOOP
FETCH p_cur INTO p_rec;
EXIT WHEN p_cur%NOTFOUND;
lcl_p_list := p_rec.p_name;
END LOOP;
CLOSE p_cur;
return lcl_p_list;
END;
B*****g
发帖数: 34098
4
你这个就是return最后一个pname

【在 j*****4 的大作中提到】
: 想得到所有的 p_name.
: Thanks.
: 改了一下,怎么也不能 compile.
: REATE OR REPLACE FUNCTION f_test (in_activity_id IN INTEGER)
: RETURN VARCHAR2 AS
: declare
: cursor p_cur is
: select coalesce(f.FULL_NAME , g.FULL_NAME) as p_name
: from OCER_ACT_PRE e
: left join ocer_p f on e.P_ID = f.ID

g***l
发帖数: 18555
5
CURSOR还LOOP。这是要做啥,你想讲讲要实现个什么吧
B*****g
发帖数: 34098
6
also "CREATE OR REPLACE"

【在 B*****g 的大作中提到】
: 你这个就是return最后一个pname
j*****4
发帖数: 283
7
Ok, I changed it. But still can not compile.
总说declare错. Any idea?
CREATE FUNCTION f_test (in_activity_id IN INTEGER)
RETURN VARCHAR2 AS
declare
cursor p_cur is
select coalesce(f.FULL_NAME , g.FULL_NAME) as p_name
from OCER_ACT_PRE e
left join ocer_p f on e.P_ID = f.ID
left join view2 g on f.person_id = g.person_id
where e.activity_id = in_activity_id;
p_rec p_cur%ROWTYPE;
lcl_p_list varchar2;
BEGIN
OPEN p_cur;
LOOP
FETCH p_cur INTO p_rec;
EXIT WHEN p_cur%NOTFOUND;
lcl_p_list := lcl_p_list || ';' || p_rec.p_name;
END LOOP;
CLOSE p_cur;
return lcl_p_list;
END;

【在 B*****g 的大作中提到】
: 你这个就是return最后一个pname
B*****g
发帖数: 34098
8
remove declare

【在 j*****4 的大作中提到】
: Ok, I changed it. But still can not compile.
: 总说declare错. Any idea?
: CREATE FUNCTION f_test (in_activity_id IN INTEGER)
: RETURN VARCHAR2 AS
: declare
: cursor p_cur is
: select coalesce(f.FULL_NAME , g.FULL_NAME) as p_name
: from OCER_ACT_PRE e
: left join ocer_p f on e.P_ID = f.ID
: left join view2 g on f.person_id = g.person_id

j*****4
发帖数: 283
9
more error message comming after remove.
Error(5,12): PLS-00341: declaration of cursor 'P_CUR' is incomplete or
malformed

【在 B*****g 的大作中提到】
: remove declare
y****9
发帖数: 144
10

SQL> CREATE or replace FUNCTION f_test (in_activity_id IN INTEGER)
2 RETURN VARCHAR2
3 AS
4 cursor p_cur is
5 select object_name p_name from user_objects e
6 where e.object_id = in_activity_id;
7 p_rec p_cur%ROWTYPE;
8 lcl_p_list varchar2(4000);
9 BEGIN
10 OPEN p_cur;
11 LOOP
12 FETCH p_cur INTO p_rec;
13 EXIT WHEN p_cur%NOTFOUND;
14 lcl_p_list := lcl_p_list || ';' || p_rec.p_name;
15 END LOOP;
16 CLOSE p_cur;
17 return lcl_p_list;
18 END;
19 /
Function created.
SQL> select f_test(1163615) from dual;
F_TEST(1163615)
----------------------------------------------------------------------------
--------------------------------------------------
-------------------------------------------------
;AUDIT_TRAIL

【在 j*****4 的大作中提到】
: more error message comming after remove.
: Error(5,12): PLS-00341: declaration of cursor 'P_CUR' is incomplete or
: malformed

相关主题
SQL Server - how to obtain data type name这个新功能我喜欢
求救!!! 一个oracle的问题! 在procedure中所涉及的表名可以用变量从参数中传入吗求教mysql数据库构建
求救!!! 一个oracl的问题淀[转载] Hehe,不好意思,another question:)
进入Database版参与讨论
B*****g
发帖数: 34098
11
楼上有人答了。另外你这个根本不用SP, SQL就行
http://www.oracle-base.com/articles/misc/StringAggregationTechn

【在 j*****4 的大作中提到】
: more error message comming after remove.
: Error(5,12): PLS-00341: declaration of cursor 'P_CUR' is incomplete or
: malformed

j*****4
发帖数: 283
12
谢谢,但在我这里怎么老是说 Error(5,16): PLS-00341: declaration of cursor 'P
_CUR' is incomplete or malformed

【在 y****9 的大作中提到】
:
: SQL> CREATE or replace FUNCTION f_test (in_activity_id IN INTEGER)
: 2 RETURN VARCHAR2
: 3 AS
: 4 cursor p_cur is
: 5 select object_name p_name from user_objects e
: 6 where e.object_id = in_activity_id;
: 7 p_rec p_cur%ROWTYPE;
: 8 lcl_p_list varchar2(4000);
: 9 BEGIN

B*****g
发帖数: 34098
13
post your new code

'P

【在 j*****4 的大作中提到】
: 谢谢,但在我这里怎么老是说 Error(5,16): PLS-00341: declaration of cursor 'P
: _CUR' is incomplete or malformed

j*****4
发帖数: 283
14
请指教。 我的版本是11.1, 好多函数用不了

【在 B*****g 的大作中提到】
: 楼上有人答了。另外你这个根本不用SP, SQL就行
: http://www.oracle-base.com/articles/misc/StringAggregationTechn

j*****4
发帖数: 283
15
CREATE OR REPLACE FUNCTION f_test (in_activity_id IN INTEGER)
RETURN VARCHAR2
AS
cursor preceptor_cur is
select coalesce(f.FULL_NAME , g.FULL_NAME) as preceptor_name
from OCER_ACT_PRE e
left join ocer_preceptor f on e.PRECEPTOR_ID = f.ID
left join view2 g on f.person_id = g.person_id
where e.activity_id = in_activity_id;
preceptor_rec preceptor_cur%ROWTYPE;
lcl_preceptor_list varchar2(4000);
BEGIN
OPEN preceptor_cur;
LOOP
FETCH preceptor_cur INTO preceptor_rec;
EXIT WHEN preceptor_cur%NOTFOUND;
lcl_preceptor_list := lcl_preceptor_list ||'~'|| preceptor_rec.preceptor
_name;
END LOOP;
CLOSE preceptor_cur;
return lcl_preceptor_list;
END;

【在 B*****g 的大作中提到】
: post your new code
:
: 'P

j*****4
发帖数: 283
16
Found it. It looks like the permission of the view2.
Thanks all of your help.

【在 j*****4 的大作中提到】
: CREATE OR REPLACE FUNCTION f_test (in_activity_id IN INTEGER)
: RETURN VARCHAR2
: AS
: cursor preceptor_cur is
: select coalesce(f.FULL_NAME , g.FULL_NAME) as preceptor_name
: from OCER_ACT_PRE e
: left join ocer_preceptor f on e.PRECEPTOR_ID = f.ID
: left join view2 g on f.person_id = g.person_id
: where e.activity_id = in_activity_id;
: preceptor_rec preceptor_cur%ROWTYPE;

B*****g
发帖数: 34098
17
下面有9i的solution,当然还有XML的solution,都可以用

【在 j*****4 的大作中提到】
: 请指教。 我的版本是11.1, 好多函数用不了
1 (共1页)
进入Database版参与讨论
相关主题
请问sql server里面怎么输出变量到文本文件?菜鸟急问ORACLE里FUNCTION返回ref cursor的问题
请帮忙读懂这个sql scriptSQL Server - how to obtain data type name
how to make this query求救!!! 一个oracle的问题! 在procedure中所涉及的表名可以用变量从参数中传入吗
如何寫此 SQL 查詢?求救!!! 一个oracl的问题淀
PL/SQL 输入DATA这个新功能我喜欢
open cursor for collection?求教mysql数据库构建
SQL run a stored procedure by fetching from a cursor row by row[转载] Hehe,不好意思,another question:)
新手求教,plsql collection 参数传入问题,非常感谢。can I create a recordset with cursor?
相关话题的讨论汇总
话题: lcl话题: cur话题: name话题: rec话题: loop