Oracle - 基于参数返回查询结果的函数

时间:2013-11-25 16:32:01

标签: sql oracle

我正在尝试编写一个Oracle PL / SQL函数,它将返回应用程序的给定status_id,这样如果返回的status_type是特定值,我可以将数据存档到历史表中。

在本例中,我的状态类型为“已批准”,“待定”或“已拒绝”

我到目前为止编写了这个函数,以便我可以在IF语句中运行该方法,以便在归档数据之前检查当前的状态类型。

CREATE OR REPLACE FUNCTION get_status(curr_id NUMBER)
RETURN VARCHAR2 AS this_type status_type;

BEGIN
    SELECT status_type 
    INTO this_type
    FROM status
    WHERE status_id LIKE curr_id;

    RETURN this_type;
END get_status;

虽然它编译但是我收到一个错误,告诉我我的PL / SQL语句被忽略了 我对Oracle很新,所以我可能在这里找不到一些直截了当的东西,任何人都可以给我任何关于我的代码出错的指示吗?

提前致谢, 亚历克斯。

1 个答案:

答案 0 :(得分:2)

CREATE OR REPLACE FUNCTION get_status(curr_id NUMBER)
RETURN VARCHAR2 
AS 
--%TYPE is used to declare variables with relation to the data type of a column 
--in an existing table 

this_type status.status_type%TYPE; --change is required here 

BEGIN
   SELECT status_type 
   INTO this_type
   FROM status
   WHERE status_id LIKE curr_id;

   RETURN this_type;
END get_status;
/
相关问题