Oracle PL / SQL存储过程日期时间间隔精度ORA-30088

时间:2013-12-03 02:49:42

标签: mysql oracle stored-procedures plsql syntax-error

在分配我的日期时间格式时,我在实现PL / SQL过程时遇到了问题。我指的是我的MySQL存储过程,我是Oracle PL / SQL的新手。

这是来自MySQL程序的MY PL / SQL翻译

CREATE OR REPLACE 
PROCEDURE "DateTimeSP" (xType IN VARCHAR2, xResult OUT VARCHAR2)
AS
BEGIN

CASE
    WHEN xType = 'TIME' THEN 

             SELECT CURRENT_TIMESTAMP() FROM dual INTO xResult;

    WHEN xType = 'DATE' THEN 

            SELECT TRUNC(SYSDATE) FROM dual INTO xResult;

    WHEN xType = 'NOW' THEN 

            ( SELECT SYSTIMESTAMP) FROM dual INTO xResult;

    WHEN xType = 'NOWFORMAT' THEN 

              SELECT TO_CHAR(SYSTIMESTAMP,'%m/%d/%Y %l:%i:%s %p') FROM dual INTO xResult;

END CASE;

END;

这是我的错误日志

  

日期时间间隔精度ORA-30088
  PL / SQL:ORA-00933:sql命令未正确结束
  PL / SQL:忽略SQL语句
  PLS-00103:遇到以下

之一时遇到符号SELECT

1 个答案:

答案 0 :(得分:3)

我已经为Oracle修改了一下存储过程 -

CREATE OR REPLACE 
PROCEDURE DateTimeSP (xType IN VARCHAR2, xResult OUT VARCHAR2)
AS
BEGIN
    CASE
        WHEN xType = 'TIME' THEN 
            SELECT TO_CHAR(SYSTIMESTAMP, 'HH24:MI:SS')
              INTO xResult
              FROM dual;
        WHEN xType = 'DATE' THEN 
            SELECT TRUNC(SYSDATE)
              INTO xResult  -- Returns date in the default format
              FROM dual;
        WHEN xType = 'NOW' THEN 
           SELECT TO_CHAR(SYSTIMESTAMP)
             INTO xResult
             FROM dual;
        WHEN xType = 'NOWFORMAT' THEN 
           SELECT TO_CHAR(SYSTIMESTAMP, 'MM/DD/YYYY HH:MI:SS AM')
             INTO xResult
             FROM dual;
    END CASE;
END;
/

不要忘记在Oracle Docs上详细阅读TO_CHAR函数。它是一种非常灵活的函数,用于格式化日期,时间和时间戳。