sql developer time format - oracle

I have to add a column into my DB oracle SQL DEVELOPER.
This column needs the format HH:MI:SS, but when I set the column as timestamp,
it convert me the column as : DD-MM-YY HH:MI:SS, even if I change NLS Settings.

You can change the preferences as follows:
Go to Tools > Preferences.
In Preferences dialog, select Database > NLS from the left panel.
From the list of NLS parameters, enter HH:MI:SS into the Timestamp Format field.
Save and close the dialog.

The actual value saved in the db in not even that. What is saved in the database is a number that represents the date. What you actually see is how the SQL Developer represents that date, and not how it is actually stored.
You can print the date in the format you want using to_char() :
select to_char(sysdate, 'HH:MI:SS') as "Current Time" from dual;

Related

Converting date from DD-MON-YY to DD-MM-YYYY with NLS_DATE_FORMAT

I'm trying to store date type data from Oracle FORMS with format mask as like DD-MM-YYYY but every time it store as like DD/MON/YY.
I already alter session with NLS_DATE_FORMAT, but result is as same as before.
Oracle internal date format that is written in the table is something you can't change in any way, but, in the same time, it is irrelevant. If you are dealing with DATE type column then you should know that it containes both the date and the time. How, where and when you will show it or use it is on you. Here is a sample of a few formats derived from that original Oracle DATE format...
WITH
t AS
(
Select SYSDATE "MY_DATE_COLUMN" From Dual
)
Select
MY_DATE_COLUMN "DATE_DEFAULT_FORMAT",
To_Char(MY_DATE_COLUMN, 'mm-dd-yyyy') "DATE_1",
To_Char(MY_DATE_COLUMN, 'yyyy/mm/dd') "DATE_2",
To_Char(MY_DATE_COLUMN, 'dd.mm.yyyy') "DATE_3",
To_Char(MY_DATE_COLUMN, 'dd.mm.yyyy hh24:mi:ss') "DATE_4"
From t
DATE_DEFAULT_FORMAT
DATE_1
DATE_2
DATE_3
DATE_4
22-OCT-22
10-22-2022
2022/10/22
22.10.2022
22.10.2022 10:59:44
You can find a lot more about the theme at https://www.oracletutorial.com/oracle-basics/oracle-date/
Regards...
In Oracle, a DATE is a binary data-type consisting of 7-bytes (representing century, year-of-century, month, day, hour, minute and second). It ALWAYS has those 7 components and it is NEVER stored in any particular human-readable format.
every time it store as like DD/MON/YY.
As already mentioned, no, it does not store a date like that; the database stores dates as 7 bytes.
What you are seeing is that the client application, that you are using to connect to the database, is receiving the 7-byte binary date value and is choosing to convert it to something that is more easily comprehensible to you, the user, and is defaulting to converting the date to a string with the format DD/MON/RR.
What you should be doing is changing how the dates are displayed by the client application by either:
Change the settings in the Toad (View > Toad Options > Data Grids > Data and set the Date Format option) and allow Toad to implicitly format the string; or
Use TO_CHAR to explicitly format the date (TO_CHAR(column_name, 'DD-MM-YYYY')).
I'm trying to store data as like DD-MM-YYYY.
If you want to store a date then STORE it as a date (which has no format) and format it when you DISPLAY it.
If you have a valid business case to store it with a format then you will need to store it as a string, rather than as a date, because you can format strings; however, this is generally considered bad practice and should be avoided.
Sadman, to add to what others have posted I suggest you do not write your applications with reliance on the NLS_DATE_FORMAT parameter but rather you screens and application should specify the expected DATE entry format and the code should use the TO_DATE function to store the data into the database. All application SQL should use the TO_CHAR function to format date output for display.

Oracle APEX grid displays only date without time

I have a field in the database that contains date and time - DATE type in the database. When I run the query in Toad, I can see data and time, but when I pull up the data in the APEX report, only date shows up, no time. How can I ensure the time comes up as well?
You can set "Format Mask" column attribute in the Page Designer.
Go to Page Designer, find your report region, open list of columns, find your column and set "Format Mask" e.g. to yyyy-mm-dd hh24:mi:ss.
Another option is to change the SQL query used for the report, make explicit conversion to_char for the desired column.

Force oracle sql developer to show timestamp

I am new to SQL developer but each time i get queries it changes time stamp to readable date format, but i want my result to be in time stamps as they are in database.
Please go to: Tools/Preferences/Database/NLS and set there date format and timestamp format to what you want.
Oracle stores date and timestamp type but display it according to NLS settings. You either call alter session set NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH:MI:SS.FF'; or just set those NLS settings in your client tool.
Documentation

oracle convert DD-MON-YY to DD/MM/YYYY

I am trying to convert the format of a varchar2 column from 'DD-MON-YY' to 'DD/MM/YYYY'.
In example: from '01-JAN-16' to '01/01/2016'
In case you can ask or it may help:
'MON' part is in English however my current NLS settings are in Turkish.
All the years are after 2000.
How can I do this?
Thanks in advance..
If you don't provide the NLS_DATE_LANGUAGE parameter, your own session's parameter will be used.
You can override that like so:
select TO_CHAR(TO_DATE('01-JAN-16','DD-MON-YY', 'NLS_DATE_LANGUAGE = English'),
'DD/MM/YYYY') from dual;
This will affect only this query, nothing else. If you need to work with many dates like this,
ALTER SESSION SET NLS_DATE_LANGUAGE='ENGLISH'
- then you can change it back later, or it will reset to Turkish when this session ends and you start another session.
If you need this change to be made (almost) permanent, put it in your settings in SQL Developer or Toad, or the login.sql for SQL*Plus.
Try this:
TO_CHAR(TO_DATE('01-JAN-16','DD-MON-YY'),'DD/MM/YYYY')
Your data must be clean - everything must conform to the original format or you'll encounter errors on the TO_DATE conversion.
Go to Tools —> Preferences —> Database —-> NLS —> Date Format and change date to DD/MM/YYYY .
Oracle SQL Developer Version 18.4.0.376 Build 376.1900

change date format 'yyyy/mm/dd' to 'mm-dd-yyyy' in Oracle

I have inserted into a table in Oracle. My implementation without PLSQL would be:
SELECT to_date('1900-01-01','YYYY-MM-DD') + (rownum - 1) AS DT_CAL,
rownum AS NUM_JOUR
FROM dual
CONNECT BY to_date('1900-01-01','YYYY-MM-DD') + (rownum - 1) <=
to_date('2000-12-31','YYYY-MM-DD')
result is: 05/28/1900, not 1900-05-28. Can you help me understand what the problem is?
The DATE data type does not have a format; Oracle stores it as either 7- or 8-bytes and it is not until it is passed to a client program (i.e. SQL/Plus, SQL Developer, Toad, Java, Python, etc) and that client program formats it according to whatever rules it has that the date gets a format.
If you are using SQL/Plus or SQL Developer then it will use the NLS_DATE_FORMAT session parameter to format the date. You can change this using:
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';
(Be aware that this will only change the format in the current session and will not change it for any other sessions/users.)
If you want to give the date a particular format then you will need to convert it to a string.
to_date() takes your string parameter, matches it to the format you provide in the second parameter, and constructs a date field from it. The date field isn't using the format you provided in the second parameter - in fact it'll be stored using some internal data representation that has no format at all (a number, in all likelihood).
To present a format back out in the results from a date field, you can either:
Have the client executing the query set the NLS parameters (at session level) to provide a localized format, with an ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'; statement), or
Use to_char(..., 'YYYY-MM-DD') around your existing field to turn the date back into a string formatted the way you want to have it. Where you replace ... with your current column definition in the select.
Approach #1 is already happening, as there'll already be an NLS_DATE_FORMAT set that is producing the current format, but it's with a format you don't want, so if you can control it and change it there, you can do it that way. If you can't and you must have the format a single consistent other way, then #2 could be the way to go.

Resources