分类: Oracle
2010-10-27 11:27:25
在一个函数中必须包含一个或多个RETURN 语句
函数调用是PL/SQL表达式的一部分,而过程调用可以是一个独立的PL/SQL语句
语法结构:
Sql代码
CREATE [OR REPLACE] FUNCTION function_name
(parameter1_name [mode] datatype [DEFAULT|:=value]
[, parameter2_name [mode] datatype [DEFAULT|:=value],…])
RETURN return_datatype
AS |IS
/*Declarative section is here */
BEGIN
/*Executable section is here*/
EXCEPTION
/*Exception section is here*/
END [function_name];
示例:
Sql代码
CREATE OR REPLACE FUNCTION F_FORMATSXDATA(VI_VALUE IN VARCHAR2,
VI_FORMSTR IN VARCHAR2)
RETURN VARCHAR2 IS
RESULT VARCHAR2(200);
V_NUMBERTEMP NUMBER(11, 2);
BEGIN
IF VI_FORMSTR = '001' OR VI_FORMSTR = '003' OR VI_FORMSTR = '005' THEN
RESULT := VI_VALUE;
ELSIF VI_FORMSTR = '002' THEN
RESULT := TO_CHAR(VI_VALUE, 'FM999999999990.00');
ELSIF VI_FORMSTR = '004' THEN
V_NUMBERTEMP := TO_NUMBER(VI_VALUE, 'FM999999999990.0099') * 100;
RESULT := TO_CHAR(V_NUMBERTEMP, 'FM999999999990.00');
END IF;
RETURN(RESULT);
END F_FORMATSXDATA;