在 Pl/SQl 中使用带有 Refcursor 的 if 条件块
我创建了一个 RefCursor 类型的包。
我在存储过程中使用包。
代码如下所示:
CREATE OR REPLACE PACKAGE PRODDB.types
AS
type cursorType is ref cursor;
END;
CREATE OR REPLACE PROCEDURE PRODDB.P_Get_AdminPLCReport
(
Final_Output out TYPES.cursorType
)
AS
BEGIN
IF( Criteria='1') THEN
OPEN Final_Output FOR
SELECT Personal_Information.F_Salutation
FROM Allotment_Information;
END IF;
END P_Get_AdminPLCReport;
我想在此存储过程中使用两个 if 条件。
我是 Pl-Sql 新手。
谁能告诉我这个的语法来帮助我。
感谢
-
更新
感谢贾斯汀 (在这里回复),
但我想使用两个条件,例如:
IF( criteria = '1') then
// some query; end if
IF( criteria = '2') then
// 一些查询;
如果
我将传递参数标准的值,则结束。
根据 criteria 的值,我想执行不同的查询。
I have created a package of of type RefCursor.
I am using package in my stored procedure.
code looks like this:
CREATE OR REPLACE PACKAGE PRODDB.types
AS
type cursorType is ref cursor;
END;
CREATE OR REPLACE PROCEDURE PRODDB.P_Get_AdminPLCReport
(
Final_Output out TYPES.cursorType
)
AS
BEGIN
IF( Criteria='1') THEN
OPEN Final_Output FOR
SELECT Personal_Information.F_Salutation
FROM Allotment_Information;
END IF;
END P_Get_AdminPLCReport;
I want to use two if conditions in this stored procedure.
I am new to Pl-Sql.
Can anybody help me by telling me the syntax for this.
Thanx
--
Update
Thanx Justin (response here),
But i want to use two condition like:
IF( criteria = '1') then
// some query; end if
IF( criteria = '2') then
// some query;
end if
I will pass value of param criteria.
Based on the value of criteria , i want to execute different queries.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,10g 中不需要在 TYPES 包中定义弱类型
REF CURSOR
。这在某些旧版本中是必要的,但 Oracle 现在有一个 SYS_REFCURSOR 类型。其次,您的过程无法编译,因为没有声明变量
Criteria
。我将忽略这一点并假设您已在其他地方声明并初始化了该变量。根据第二个条件是什么,最简单的选择通常是这样的
First off, there is no need to define a weakly typed
REF CURSOR
in a TYPES package in 10g. That was necessary in some older releases, but Oracle has aSYS_REFCURSOR
type now.Second, your procedure doesn't compile because there is no declaration of the variable
Criteria
. I'll ignore that and assume that you have declared and initialized the variable elsewhere.Depending on what the second condition is, the simplest option would generally be something like
sys_refcursor
仍然是一个弱类型引用游标。查看数据字典中sys_refcursor
的定义,你会看到这样的内容:type sys_refcursor
是引用游标;sys_refcursor
is still a weakly typed ref cursor. Look at the definition ofsys_refcursor
in the data dictionary and you will see this:type sys_refcursor
is ref cursor;