I am using SQL Developer Version 21.4.1.349.
I am using the interactive debugger with a procedure that accepts a Date parameter.
When the debugger launches, it presents a dialog so that I can provide a value for the parameter.
But, I don't know how to provide the date value. I have tried the following:
providing a date string in the format of my NLS setting.
providing to_date('12/27/2022 10:20:00','mm/dd/yyyy hh24:mi:ss')
Neither test worked. The date parameter is just set to NULL.
Is there a specific way a Date parameter should be provided when using the debugger?
Thanks
Related
If I try a query as
select * from hr.employees
by sqldeveloper I have an output where the field HIRE_DATE is display so:
21-GIU-07
The data format is in according of the land (Italy)
If I use Tora or Toad (an old version) for the query the same row and the same field is display as
HIRE_DATE 2007-06-21 00:00:00
I am not undestand why there is time value in the field HIRE_DATE. In the example is 0 but I have found table where the time is set.
Why Tora/Toad show the time too and not in sqldeveloper ?
Thanks in advance anyone wants to answer
There is a parameter called NLS_DATE_FORMAT which specifies the default format for date data type.
The NLS_DATE_FORMAT has an order of overriding precedence, and tool specific NLS paramter settings will override it. That is the reason why two different tools has different outputs.
This is the most usual order of overriding precendence :
NLS_DATE_FORMAT is in the database initialization parameters, will be overriden by,
Settings of OS environment variable on the client machine, will be overriden by,
NLS parameter setting at session level with ALTER SESSION statements, will be overriden by,
to_date and to_char functions at the sql statement level.
Having said all that, in your situation, you need to check the NLS_DATE_FORMAT in both the tools.
Last but most important, check this link and learn more about the NLS_DATE_FORMAT.
Looking into a query in WebIntelligence, after running, the prompts are replaced by values provided by user (for instance dates).
When I run the same query on Oracle (because this database I use for my universe) I’m getting error in terms of dates. Dates in query (in BO) are just strings,
like StartDate = '30-06-2020 00:00:00′. When I run the query generated in WebIntelligence on Oracle I’m getting error:
ORA-01843: not a valid month
01843. 00000 – ” not a valid month”
And to fix this I need to use for instance to_date function and then it’s working fine. My question is: how dates are parsed in WebIntelligence while running a query?
so the mentioned error does not occur?
I am getting the same error as you when I try a query directly against Oracle using SQL Developer that works in Web Intelligence. According to this BusinessObjects makes a call to set the date format.
So you can do that either in the preferences of SQL Developer (or presumably whatever database query tool you are using) or explicitly setting it with the alter session command.
alter session set nls_date_format = 'DD-MM-YYYY HH24:MI:SS';
select...[the rest of your query]
Both options are shown in the answer to How can I set a custom date time format in Oracle SQL Developer?.
After upgrading from SSRS 2012 to 2016, we've had to rewrite all of our reports because of an issue with SSRS giving ORA-01830: date format picture ends before converting entire input string.
The code that causes the issue is below:
WHERE (
trunc(date_processed) BETWEEN NVL(:start_date,:subscription_start_date) AND NVL(:end_date,:subscription_end_date)
)
Start/End_date are both null at the beginning of the report execution. subscription_start/end_date is NEVER null and is always set. To make things even more frustrating, the following works fine:
WHERE (
trunc(date_processed) BETWEEN NVL(:start_date ,'01-JAN-1848') AND NVL(:end_date,'31-DEC-2039')
and trunc(date_processed) BETWEEN :subscription_start_date and :subscription_end_date
)
The issue, however, is that now the :start_date parameter can not override the subscription date parameter when it is set by the user.
This did not occur on previous versions. This is happening to ALL reports we have which isn't a few.
Setting the variable parameters in SSRS to text and using TO_DATE resolved similar situations for me using SSRS with an Oracle source.
WHERE ( trunc(date_processed) BETWEEN NVL(TO_DATE(:start_date,'mm/dd/yyyy'),TO_DATE(:subscription_start_date,'mm/dd/yyyy')) AND NVL(TO_DATE(:end_date,'mm/dd/yyyy'),TO_DATE(:subscription_end_date, 'mm/dd/yyyy') )
We were able to get around this issue by using an expression to format the date parameters on the output Dataset Parameter Properties with the following formulas.
=Format(Parameters!BeginDate.Value, "dd/MMM/yyyy")
=Format(Parameters!EndDate.Value, "dd/MMM/yyyy")
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.
I'm calling an Oracle procedure with this code:
begin
PPT2000_AGG_HOURLY.RUNDURATION_HOURLY(4, to_date('01112014', 'DDMMYYYY'), 20);
end;
/
My problem is the date format. On one PC the procedure calculates all fine with the result for the date 01.11.2014 00:00.
On the other PC (same version of Oracle SQL Developer) the procedure returns
0 for the calculation and for the date 01.11.2014
So something seems to be different in converting the date and I don't know why. I tried it with a third PC and get also the return of 01.11.2014.
The PC which gives the correct result has the same operating system (WIN7 German) and the same version of the Oracle SQL Developer. Also the same Oracle database.
So how could this be possible?
Update Solution:
Thanks for the answers, I changed the NLS-Settings from DD.MM.RR to DD.MM.RR HH24:MI and now it works :)
You should handle the display format in the code, and not depend on the client's NLS_DATE_FORMAT. You can't expect 1000 users to change their local NLS settings in their GUI based client tools.
A date doesn't have a format. What you see, is just for display depending on the locale-specific NLS_DATE_FORMAT of the client.
And the NLS_DATE_FORMAT could be overridden at different levels. If you don't want to depend on the client's NLS settings, then always use TO_CHAR with desired format mask to make sure it is overridden at individual statement level.
Remember, for diaplaying DATE values, always use TO_CHAR with desired format. To do date arithmetic, use TO_DATE to convert a literal into DATE.
For example,
TO_CHAR(date_column, '<desired_format>')
It will override the locale-specific NLS_DATE_FORMAT at statement level.
See this similar answer for more understanding.
If you really have a constant date then use the Oracle DateTime literal. It works every time and it's independent of the NLS_DATE_FORMAT:
begin
PPT2000_AGG_HOURLY.RUNDURATION_HOURLY(4, DATE '2014-11-01', 20);
end;
/
Check the NLS preferences in SQL Developer to see if there is a mismatch. Go to Preferences->Database->NLS. You can also override these settings on a per session basis if you want.