Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SYSDATE in ORACLE

I'm trying to get the system date using the SYSDATE function in oracle, but I keep getting results equal to the number of rows in the table I'm requesting the system date from

Here how my code looks like:

SELECT TRUNC(SYSDATE)As Currnt_Time FROM TABLE_NAME

And this is my output:

enter image description here

The result is displaying the current time N times, I just want it to display it one time

like image 666
Michael B Avatar asked May 11 '26 22:05

Michael B


1 Answers

SELECT TRUNC(SYSDATE)As Currnt_Time FROM dual;

DUAL only has 1 column, one row. So you'll get one answer.

You're asking to run a select on a table, so it will apply across all rows, unless you provide a predicate.

So you COULD do this, but don't.

select trunc(SYSDATE)as CURRNT_TIME from TABLE
where rownum < 2;

This will always be more expensive than using the DUAL table. That's why we built it, in fact.

like image 181
thatjeffsmith Avatar answered May 16 '26 14:05

thatjeffsmith