前端之家收集整理的这篇文章主要介绍了
oracle 创建函数例子,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
CREATE OR REPLACE FUNCTION FUN_GET_YJJB(V_score IN NUMBER) RETURN VARCHAR2 IS
/*********************************************************
名称 FUN_GET_YJJB
功能描述:获取预警级别
修改记录
版本号 编辑时间 编辑人 修改描述
1.0.0 2016-11-22 aoliu 创建函数
*********************************************************/
O_YJJB VARCHAR2(1);
O_4_score NUMBER;
O_3_score NUMBER;
O_2_score NUMBER;
O_1_score NUMBER;
O_4_COLO VARCHAR2(1);
O_3_COLO VARCHAR2(1);
O_2_COLO VARCHAR2(1);
O_1_COLO VARCHAR2(1);
BEGIN
SELECT score,COLOR
INTO O_1_score,O_1_COLO
FROM T_PVBDP_MODEL_ALERT_LEVEL
WHERE ID = 1;
SELECT score,COLOR
INTO O_2_score,O_2_COLO
FROM T_PVBDP_MODEL_ALERT_LEVEL
WHERE ID = 2;
SELECT score,COLOR
INTO O_3_score,O_3_COLO
FROM T_PVBDP_MODEL_ALERT_LEVEL
WHERE ID = 3;
SELECT score,COLOR
INTO O_4_score,O_4_COLO
FROM T_PVBDP_MODEL_ALERT_LEVEL
WHERE ID = 4;
SELECT CASE
WHEN V_score >= O_4_score THEN
O_4_COLO
WHEN O_3_score <= V_score AND V_score < O_4_score THEN
O_3_COLO
WHEN O_2_score <= V_score AND V_score < O_3_score THEN
O_2_COLO
WHEN O_1_score <= V_score AND V_score < O_2_score THEN
O_1_COLO
ELSE
'9'
END
INTO O_YJJB
FROM DUAL;
RETURN O_YJJB;
EXCEPTION
WHEN OTHERS THEN
RETURN '9';
END;
原文链接:https://www.f2er.com/oracle/211635.html