我想要一个程序,我想检查一个条件,如下所示
我必须检查一个表的两列,如果其中任何一列有值,则返回1,否则返回0
这是我的表格,下面有查询
SELECT BOCID, BUILDING_RJID FROM R4G_OSP.OTHER_FACILITY;
注意我会将两个参数传递给该过程。
更新
尝试过这样,但不知道如何将其返回1或0
PROCEDURE GETVAL_BY_PARAMETER
(
P_BOCID NVARCHAR2,
P_BUILDINGID NVARCHAR2,
P_FLAG OUT NVARCHAR2
)
AS
BEGIN
SELECT BOCID, BUILDING_RJID FROM R4G_OSP.OTHER_FACILITY
where BOCID = P_BOCID or BUILDING_RJID = P_BUILDINGID;
答案 0 :(得分:2)
你可以这样做:
PROCEDURE GETVAL_BY_PARAMETER
(
P_BOCID NVARCHAR2,
P_BUILDINGID NVARCHAR2,
P_FLAG OUT NVARCHAR2
)
AS
BEGIN
SELECT 1
INTO P_FLAG
FROM R4G_OSP.OTHER_FACILITY
WHERE ( BOCID = P_BOCID
OR BUILDING_RJID = P_BUILDINGID )
AND ROWNUM = 1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
P_FLAG := 0; -- Handle the case when neither parameter exists in the table.
END;
/
WHERE
子句仅在行具有值时匹配(因为NULL
永远不会等于任何其他值,即使是另一个NULL
)。