How to return today's date to a variable in Oracle

后端 未结 2 1160
独厮守ぢ
独厮守ぢ 2021-02-19 01:34

I want to do this:

DECLARE @today as smalldatetime
SELECT @today = GetDate()

But i need an oracle translation

2条回答
  •  孤城傲影
    2021-02-19 01:59

    Oracle uses SYSDATE, and there's the ANSI standard CURRENT_TIMESTAMP (supported by both SQL Server and Oracle, besides others) to get the current date & time.

    v_today DATE;
    
    SELECT SYSDATE
      INTO v_today
      FROM DUAL;
    

    ...would be the equivalent to the TSQL you posted. Oracle uses the INTO clause for populating variables, where the variable data type must match the column position in the SELECT clause.

提交回复
热议问题