1

我正在尝试创建一个存储函数来获取一个称为预算的参数。该函数应返回字符串“LOW”表示预算小于或等于 500000,“MID”表示预算小于或等于 850000,“HIGH”表示预算小于或等于 1200000,“ULTRA”表示预算超过 1200000。但我遇到了一个对我来说没有多大意义的错误。

这是我的功能:

set term # ;

create procedure f_rating(budget int) 
as
begin
if (budget <= 500000) then
    return ('LOW');
else if (budget <= 850000) then
    return ('MID');
else if (budget <= 1200000) then
    return ('HIGH');
else 
    return ('ULTRA');
end #

我对 sql 还是很陌生,所以这个语法是基于网上的例子等等。这是我的错误:

SQL Message : -804
An error was found in the application program input parameters for the SQL statement.

Engine Code    : 335544569
Engine Message :
Dynamic SQL Error
SQL error code = -804
Function unknown
RETURN

谁能帮我弄清楚这意味着什么?

4

2 回答 2

1

过程不返回任何值,函数会。

尝试:

create function f_rating(budget int) 
as

代替

create procedure f_rating(budget int) 
as
于 2016-11-07T15:46:46.047 回答
1

存储函数的语法是

CREATE FUNCTION funcname [ ( [ <in_params> ] ) ]
  RETURNS <domain_or_non_array_type> [COLLATE collation]
  [DETERMINISTIC]
  <module-body>

所以你犯了两个错误,你使用procedure而不是,function你错过了这个RETURNS <type>部分。尝试

create function f_rating(budget int) RETURNS VARCHAR(5)
as
begin
if (budget <= 500000) then
    return 'LOW';
else if (budget <= 850000) then
    return 'MID';
else if (budget <= 1200000) then
    return 'HIGH';
else 
    return 'ULTRA';
end #
于 2016-11-07T16:57:52.707 回答