我是 PL/SQL 新手。我的要求是创建一个返回单个值的函数。它应该不难,因为它是一个简单的代码。但是,我收到错误“必须声明标识符‘IN_VC_LOW_VALUE’”。请让我知道我哪里出错了:
下面是我的代码:
FUNCTION F_GET_DOMAIN_MEANING (in_vc_domain VARCHAR2,
in_vc_low_value VARCHAR2,
in_vc_option VARCHAR2)
RETURN VARCHAR2
as
vc_result blu_custom_refs.rv_meaning_l1%TYPE := NULL;
CURSOR c_domain_meaning IS
SELECT rv_meaning_l1
FROM blu_custom_refs
WHERE rv_domain = UPPER(in_vc_domain)
AND rv_low_value = UPPER(in_vc_low_value);
CURSOR c_domain_abbrev IS
SELECT rv_abbreviation_l1
FROM blu_custom_refs
WHERE rv_domain = UPPER(in_vc_domain)
AND rv_low_value = UPPER(in_vc_low_value);
BEGIN
IF (in_vc_low_value IS NOT NULL) AND (in_vc_domain IS NOT NULL) THEN
IF (in_vc_option = 'MEANING') THEN
OPEN c_domain_meaning;
FETCH c_domain_meaning INTO vc_result;
IF (c_domain_meaning%NOTFOUND) THEN
vc_result := NULL;
END IF;
CLOSE c_domain_meaning;
ELSIF (in_vc_option = 'ABBREVIATION') THEN
OPEN c_domain_abbrev;
FETCH c_domain_abbrev INTO vc_result;
IF (c_domain_abbrev%NOTFOUND) THEN
vc_result := NULL;
END IF;
CLOSE c_domain_abbrev;
END IF;
END IF;
RETURN (LTRIM(RTRIM(vc_result)));
END;
不接受参数。预先感谢
您尝试执行以
FUNCTION
开头的 SQL 语句。 Oracle中没有这样的SQL语句。编译函数需要使用 CREATE
SQL 语句,如下所示:
CREATE OR REPLACE FUNCTION F_GET_DOMAIN_MEANING (in_vc_domain VARCHAR2,
in_vc_low_value VARCHAR2,
in_vc_option VARCHAR2)
RETURN VARCHAR2
. . .
等等。这将编译函数并在字典中创建函数对象。完成后,您可以通过从另一个 PL/SQL 程序或匿名块调用该函数来执行该函数:
DECLARE
vc_result blu_custom_refs.rv_meaning_l1%TYPE := NULL;
BEGIN
vc_result := f_get_domain_meaning(in_vc_domain => 'whatever',
in_vc_low_value => 'whatever',
in_vc_option => 'whatever');
dbms_output.put_line('function returned value '||vc_result);
END;
结束;