我是新手,并且想知道是否有人可以告诉我这个功能在做什么?它将'8/20/20118'转换为0。
CREATE OR REPLACE FUNCTION ISDATE(v_date IN VARCHAR2) RETURN number IS
v_date1 DATE;
BEGIN
select to_date(v_date,'mm/dd/yyyy') into v_date1 from dual;
RETURN 1;
Exception WHEN Others THEN
RETURN 0;
END;
我没有得到这一部分。
ISDATE(v_date IN VARCHAR2)RETURN number IS v_date1 DATE
CREATE OR REPLACE FUNCTION -- You are creating or replacing a function in the
-- database
ISDATE -- The name of the function is "ISDATE"
(
v_date IN VARCHAR2 -- The function takes one argument called "v_date"
-- which is an IN(put) parameter of the VARCHAR2
-- (string) data type
)
RETURN number -- The function returns a number
IS
v_date1 DATE; -- The function has one local variable "v_date1"
-- which is of the DATE data type.
BEGIN -- The start of the main body of the function
select to_date(v_date,'mm/dd/yyyy') -- Try to convert the v_date argument to a date
-- using the mm/dd/yyyy format model
into v_date1 -- and put the result into the v_date1 variable
from dual; -- Using the DUAL table supplied by Oracle.
RETURN 1; -- If successful then return 1
Exception -- If there was an error then...
WHEN Others THEN -- When the error was not matched by another rule
RETURN 0; -- return 0
END; -- End the function.
它检查输入字符串是否可以使用指定的格式转换为日期,如果可以或不可以分别返回1或否。
正如in the documentation所解释的那样:
ISDATE
是函数名称。(v_date IN VARCHAR2)
是参数声明;在这种情况下,有一个输入(IN
,表示它在函数内是只读的)参数,它接受一个字符串值;该参数名为v_date
,因此您可以使用该名称来引用函数体中的传入值。RETURN number
说该函数返回的值是number
IS
表示你已经完成了参数/返回声明,并且正在转向可选的局部变量声明和函数体。v_date1 DATE
宣布date
类型的局部变量,称为v_date1
。