PL/SQL 如何让当前时间可变?
PL/SQL how to make current time variable?
我的街区:
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”
尝试
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();
编译程序后需要有/
终止符。下面是添加终止符后输出应该如何显示的示例。我还稍微修改了程序以不需要变量。
代码
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 ();
我的街区:
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”
尝试
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();
编译程序后需要有/
终止符。下面是添加终止符后输出应该如何显示的示例。我还稍微修改了程序以不需要变量。
代码
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 ();