这让我发疯了:D所以我很想定义oracle 12函数来简化日期但是我无法让它编译(告诉我有些东西丢失了......)。所以功能如下: PS:这是一个写入的函数,用于转换月份,但是我无法编译它:
功能1:
CREATE OR REPLACE FUNCTION replace_abreviated_Month(str IN VARCHAR2)
RETURN VARCHAR2
IS
z VARCHAR2;
BEGIN
IF str like '%Jan%' THEN
z:= REGEXP_REPLACE (str, 'Jan', '01');
ELSE if str like '%Feb%' THEN
z:= REGEXP_REPLACE (str, 'Feb', '02');
ELSE if str like '%Mar%' THEN
z:= REGEXP_REPLACE (str, 'Mar', '03');
ELSE if str like '%Apr%' THEN
z:= REGEXP_REPLACE (str, 'Apr', '04');
ELSE if str like '%May%' THEN
z:= REGEXP_REPLACE (str, 'May', '05');
ELSE if str like '%Jun%' THEN
z:= REGEXP_REPLACE (str, 'Jun', '06');
ELSE if str like '%Jul%' THEN
z:= REGEXP_REPLACE (str, 'Jul', '07');
ELSE if str like '%Aug%' THEN
z:= REGEXP_REPLACE (str, 'Aug', '08');
ELSE if str like '%Sep%' THEN
z:= REGEXP_REPLACE (str, 'Sep', '09');
ELSE if str like '%Oct%' THEN
z:= REGEXP_REPLACE (str, 'Oct', '10');
ELSE if str like '%Nov%' THEN
z:= REGEXP_REPLACE (str, 'Nov', '11');
ELSE
z:= REGEXP_REPLACE (str, 'Dec', '12');
END IF;
RETURN z;
END replace_abreviated_Month;
功能2:
CREATE OR REPLACE FUNCTION delete_time_zone(str IN VARCHAR2)
RETURN VARCHAR2
IS
toReturn VARCHAR2;
BEGIN
IF str like '%CET%' THEN
toReturn:= REGEXP_REPLACE (REF_AUTRE, 'CET ', '');
ELSE if str like '%CEST%' THEN
toReturn:= REGEXP_REPLACE (REF_AUTRE, 'CEST ', '');
END IF;
RETURN toReturn;
END delete_time_zone;
答案 0 :(得分:2)
“z”需要声明这样的东西。 z VARCHAR(100);
语法需要阅读 ELSE if - >应阅读ELSIF
答案 1 :(得分:0)
这应该有效:
CREATE OR REPLACE FUNCTION replace_abreviated_Month(str IN VARCHAR2)
RETURN VARCHAR2 IS
z VARCHAR2(3000);
BEGIN
IF (str like '%Jan%') THEN
z:= REGEXP_REPLACE (str, 'Jan', '01');
ELSIF (str like '%Feb%') THEN
z:= REGEXP_REPLACE (str, 'Feb', '02');
ELSIF (str like '%Mar%') THEN
z:= REGEXP_REPLACE (str, 'Mar', '03');
ELSIF (str like '%Apr%') THEN
z:= REGEXP_REPLACE (str, 'Apr', '04');
ELSIF (str like '%May%') THEN
z:= REGEXP_REPLACE (str, 'May', '05');
ELSIF (str like '%Jun%') THEN
z:= REGEXP_REPLACE (str, 'Jun', '06');
ELSIF (str like '%Jul%') THEN
z:= REGEXP_REPLACE (str, 'Jul', '07');
ELSIF (str like '%Aug%') THEN
z:= REGEXP_REPLACE (str, 'Aug', '08');
ELSIF (str like '%Sep%') THEN
z:= REGEXP_REPLACE (str, 'Sep', '09');
ELSIF (str like '%Oct%') THEN
z:= REGEXP_REPLACE (str, 'Oct', '10');
ELSIF (str like '%Nov%') THEN
z:= REGEXP_REPLACE (str, 'Nov', '11');
ELSE
z:= REGEXP_REPLACE (str, 'Dec', '12');
END IF;
RETURN z;
END replace_abreviated_Month;
/
create or replace FUNCTION delete_time_zone(str IN VARCHAR2)
RETURN VARCHAR2
IS
toReturn VARCHAR2(3000);
BEGIN
IF str like '%CET%' THEN
toReturn:= REGEXP_REPLACE(str, 'CET ', '');
ELSIF str like '%CEST%' THEN
toReturn:= REGEXP_REPLACE(str, 'CEST ', '');
END IF;
RETURN toReturn;
END delete_time_zone;
/