How should I write the following select in delphi:
select to_char(sysdate, 'dd.mm.yyyy hh:mm:ss) from dual
When I try to execute it I receive an error, but this works:
select to_char(sysdate) from dual
Thanks in advance!
Missing single quote possibly at the end of your format string?
*
select to_char(sysdate, 'dd.mm.yyyy hh:mm:ss') from dual
*
You might try going in to SQL*Plus and running the query that works so you can see what format Delphi seems to want.
Share and enjoy.
Related
I'm using jaspersoft server to print some pdf files.
The server is connected to an Oracle Database through oracle.jdbc.OracleDriver.
It's configured as follows :
The server is working nicely. However when running a report that has a query like :
select to_char('Month', sysdate) from dual;
The result is always in english.
Is it possible to change Jaspersoft server connection to Oracle and make it work in another language ?
Thanks.
Regards,
SELECT statement you posted is invalid. It won't work at all:
SQL> select to_char('Month', sysdate) from dual;
select to_char('Month', sysdate) from dual
*
ERROR at line 1:
ORA-01722: invalid number
When fixed:
SQL> select to_char(sysdate, 'Month') from dual;
TO_CHAR(
--------
Studeni
How to use another language (as result I previously got is in Croatian; let's try English):
SQL> select to_char(sysdate, 'Month', 'nls_date_language = english') from dual;
TO_CHAR(S
---------
November
SQL>
I am facing one simple issues in vertica.
select to_char(sysdate, 'MM/DD/YYYY');
OutPut:
01/18/2021
But the requirement is Output should be like below:
OutPut:
1/18/2021
Can anyone please help me to get like this.
You can suppress the leading zero using the FM Modifier:
dbadmin=> select to_char(sysdate, 'FMMM/DD/YYYY');
to_char
-----------
1/18/2021
(1 row)
select TRUNC(TO_DATE('22-AUG-03'), 'YEAR')
from dual;
ORA-01843: not a valid month
1st example -> https://www.techonthenet.com/oracle/functions/trunc_date.php
I know "trunc" function takes in a date and optional fmt parameter.
Why am I getting this error?
I don't think the problem is trunc(). I think the problem is the date format. You are safer using the date keyword and an ISO-standard formatted date:
select TRUNC(DATE '2003-08-22', 'YEAR')
from dual;
The interpretation of a date string depends on the internationalization settings for your particular environment. The above does not have that dependency.
Here is a very simple check: IN THE SAME SESSION where your SELECT fails, and WITHOUT you altering the NLS_DATE_FORMAT, see what happens if you run the simpler statement,
SELECT TO_DATE('22-AUG-03') FROM DUAL
You will get the same error - which proves conclusively that it has nothing to do with TRUNC().
To make everything work exactly as in the tutorial, issue the command
ALTER SESSION SET NLS_DATE_FORMAT = 'dd-MON-yy'
first, before everything else. Note though that formats that have the year as two digits instead of four are a very bad idea in most cases.
It seems that you want to get the year of the date you receive in parameter
If you get '22-AUG-03' as parameter, add to TO_DATE function the date format you expect and then trunc it:
SELECT TRUNC(TO_DATE('22-AUG-03', 'dd-MON-yy'),'YEAR') FROM DUAL
Use SELECT EXTRACT(YEAR FROM TO_DATE('22-AUG-03', 'dd-MON-yy')) FROM DUAL;
to extract year from date.
Is there a way to change the value of the default timestamp in oracle, please find the below output of the query and it is one day behind. The google is returning results only to change the format of the default systimestmap, but i need to change the value itself. Please suggest.
select systimestamp from dual
SYSTIMESTAMP
12-02-17 07:29:26.843712000 PM +05:30
Do you want to provide your own value and turn in into a timestamp like this?
SELECT TO_TIMESTAMP ('10-Sep-02 14:10:10.123000', 'DD-Mon-RR HH24:MI:SS.FF')
FROM DUAL;
Oracle documentation
https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions193.htm
Related question:
Oracle: how to add minutes to a timestamp?
What about this?
SELECT SYSTIMESTAMP + INTERVAL '2' SECOND FROM dual;
With this method you are able to add or remove 'second's, 'minute's, 'hour's and so on...
Hope this helps :-)
I am executing the following sql in Toad. Oracle is RDBMS
I only need Date in yyyymmdd HH24:mi, but I get Date only as shown below
alter session set nls_date_format = 'DD/MM/YYYY HH24:MI';
SELECT to_date('22/07/1980 00:00','dd/mm/yyyy hh24:mi') dt FROM dual
22/07/1980
Required Output
22/07/1980 00:00
You are looking for to_char() -- you want to return the date as a string, not a date. As far as I know, the date is returned without the time, and I don't think the NLS changes that.
So:
SELECT to_char(to_date('22/07/1980 00:00', 'dd/mm/yyyy hh24:mi'
), 'DD/MM/YYYY HH24:MI'
) as dt
FROM dual
I have used sql plus and spooled the file instead of Toad, used NLS Date format conversion here, but as this is command based, wanted to use GUI based TOAD.