【问题标题】:PL/SQL how to make current time variable?PL/SQL如何使当前时间变量?
【发布时间】:2020-12-13 14:15:28
【问题描述】:

我的块:

create or replace procedure currentime IS
    current_time VARCHAR2(50):=  TO_CAHR( SYSDATE, 'YYYY.MM.DD HH24:MI:SS' ) ;

    --current_time VARCHAR2(50):=  SELECT TO_CAHR( SYSDATE, 'YYYY.MM.DD HH24:MI:SS' ) FROM DUAL;
begin
    dbms_output.put_line(current_time);
end;

set serveroutput on;
call currentime();

PL/SQL 错误:

错误(14,1):PLS-00103:“SET”

【问题讨论】:

  • 这是一个 PL/SQL 编译错误,但它看起来不像来自 PL/SQL Developer(在问题中标记)。您正在使用什么工具以及如何运行上面的代码? set serveroutput 来自作为脚本运行的 SQL*Plus 或 SQL Developer。可能在 PL/SQL 块之后需要一个/(即在end; 之后的行),但这取决于工具。
  • TO_CARH 你是说to_cHar 吗?还有,为了更好的解决你的问题,想这样改时间的原因是什么?

标签: oracle plsql plsqldeveloper


【解决方案1】:

试试

create or replace procedure currentime IS
    current_time VARCHAR2(50) ;    

begin
    dbms_output.put_line(TO_CHAR( SYSDATE, 'YYYY.MM.DD HH24:MI:SS' ));

    current_time :=  TO_CHAR( SYSDATE, 'YYYY.MM.DD HH24:MI:SS' );

    dbms_output.put_line(current_time );

end;

set serveroutput on;
call currentime();

【讨论】:

    【解决方案2】:

    编译过程后,您需要有/ 终止符。下面是添加终止符后输出应如何显示的示例。我还稍微修改了过程以不需要变量。

    代码

    CREATE OR REPLACE PROCEDURE currentime
    IS
    BEGIN
        DBMS_OUTPUT.put_line (TO_CHAR (SYSDATE, 'YYYY.MM.DD HH24:MI:SS'));
    END;
    /
    
    SET SERVEROUTPUT ON;
    CALL currentime ();
    

    【讨论】:

      猜你喜欢
      • 2020-06-04
      • 2023-03-28
      • 2018-03-07
      • 2011-11-02
      • 1970-01-01
      • 2016-04-17
      • 1970-01-01
      • 2016-02-18
      • 2020-08-14
      相关资源
      最近更新 更多