Why does Oracle SQL query returning a date field without the time component
Hi,
I'm a novice SQL user & hv just installed Oracle SQL developer (Version 3.0.04, Build MAIN-04.34).
I made the same SQL query using "Oracle SQL developer" & "TOAD for Oracle 9.0.1" but I got 2 different format on the same date field:
On TOAD, I get the date field extracted as *04/26/2011 23:12:58*
On Oracle, I get the date field extracted as *26/APR/11*
Why is the Oracle result in a different format & missing the time component?
Is there any option/preference that I need to set in Oracle SQL developer to get the full date/time format displayed?
I've tried to set my the date format to DD/MON/RR HH12:MI:SSXFF AM under the preference -> database NLS but I still get the same format!
Plse help!
hokim wrote:
Hi,
I'm a novice SQL user & hv just installed Oracle SQL developer (Version 3.0.04, Build MAIN-04.34).
I made the same SQL query using "Oracle SQL developer" & "TOAD for Oracle 9.0.1" but I got 2 different format on the same date field:
On TOAD, I get the date field extracted as *04/26/2011 23:12:58*
On Oracle, I get the date field extracted as *26/APR/11*
Why is the Oracle result in a different format & missing the time component?
Is there any option/preference that I need to set in Oracle SQL developer to get the full date/time format displayed?
I've tried to set my the date format to DD/MON/RR HH12:MI:SSXFF AM under the preference -> database NLS but I still get the same format!
Plse help!http://edstevensdba.wordpress.com/category/nls_date_format/
Similar Messages
-
I have Elements 11. Sometimes, if I edit a photo in Elements Editor, the date gets changed to the current date. Why does that happen? It doesn't happen all the time, so I can't isolate the cause. Any ideas?
I have Elements 11. Sometimes, if I edit a photo in Elements Editor, the date gets changed to the current date. Why does that happen? It doesn't happen all the time, so I can't isolate the cause. Any ideas?
-
[Forum FAQ] How do I have Invoke-SqlCmd return a date value without adding time
Introduction
A select statement executed from Invoke-SqlCmd returns a value from a Date column, the value has "12:00:00 AM" appended. The same select statement executed within SQL Server Management Studio displays the date properly without any time formatting.
Sample data is as follows:
How to have Invoke-SqlCmd return Date values without adding time for multiple Date type columns and pipe the output into CSV file?
Solution
In SQL Server 2012 or onwards, use the FORMAT() function to convert datetime values to date format when executing query from Invoke-SqlCmd. In earlier versions such as SQL Server 2008 R2, use the traditional CONVERT() function to format datetime values to
different date formats(yyyy.mm.dd, mm/dd/yyyy, etc) when executing query from Invoke-SqlCmd. Then pipe the output of SQL query result into CSV file by specifying export-csv parameter. An example is as follows.
Create a table named “Test_invokesqlcmd” that contains Date type columns in SQL Server.
USE Test
Go
CREATE TABLE [dbo].[Test_invokesqlcmd](
[id] [int] NOT NULL,
[name] [varchar](20) NULL,
[test1] [date] NULL,
[test2] [date] NULL
) ON [PRIMARY]
GO
insert into [dbo].[Test_invokesqlcmd]
values(1,'David','2014-10-15','2015-01-07'),(2,'Jane','2011-08-05','2012-11-7'),(3,'Crystal','2013-09-15','2010-02-24')
Define a query string, execute it from Invoke-SqlCmd and save the query result to a CSV file.
Scripts for SQL Server 2012:
$query1 = @"
use Test;
SELECT FORMAT(test1,'d') as newtest1, FORMAT(test2,'d') as newtest2 from dbo.Test_invokesqlcmd
write-host $query1
Invoke-Sqlcmd -Query $query1 -ServerInstance localhost | export-csv -notypeinformation -path c:\Files\test.csv
Scripts for SQL Server 2008 R2:
$query2 = @"
Use Test;
SELECT CONVERT(varchar, test1, 102) as newtest1,CONVERT(varchar, test2, 102) as newtest2
FROM dbo. Test_invokesqlcmd
write-host $query2
Invoke-Sqlcmd -Query $query2 -ServerInstance localhost | export-csv -notypeinformation -path c:\Files\test.csv
Check the results in SQL Server PowerShell window and csv file.
SQL Server 2012:
SQL Server 2008 R2:
Reference
Using the Invoke-Sqlcmd cmdlet
SQL Server Functions that helps to convert date and time values to and from string literals and other date and time formats
Applies to
SQL Server 2014
SQL Server 2012
SQL Server 2008 R2
SQL Server 2008
Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.Cross posted. More appropriate in JSF forum so continue conversation there.
http://forum.java.sun.com/thread.jspa?threadID=717292&messageID=4142615#4142615 -
Why does my Safari Auto-Fill only work part of the time?
First of all, why isn't there a link on the Apple website to provide Feedback? Secondly, I'd love to know why my Safari Auto-Fill only works some of the time, like when entering Sweepstakes information. I realize some websites don't allow Auto-Fill, but on the ones that do, I can't get the second window to open up when I click "Auto-Fill".
Safari 6.1.1 and yes all web forms are checked under Preferences Auto-Fill. I am daily entering sweepstakes for the HGTV dream home, and even though the initial bubble shows up "Auto-Fill your contact information" shows up, when I click on it, the second bubble that lets you confirm the info doesn't always open. I tried it just now in a separate tab, and it opened; then I came back here to write some of the message. Then I went back to try again and it won't open. It drives me crazy. I keep trying with each new data field and sometimes the second bubble will open further down the page.
-
Oracle SQl query to find date range based on another cloumn value
Hi Folks,
I want to extract records for the employees who have consecutive vacation/leave from a table. If an emp has vacation of 3 days (MON-WED), the table contains 3 distinct records for him,
e.g. My table contains records as shown below.
EmpName Paycode ApplyDate Amt. of Hrs
emp1 vacation 5/1/2010 8
emp1 vacation 5/2/2010 8
emp1 vacation 5/3/2010 8
I am trying to get the output like this...
Emp Name Paycode Leave Start Date Leave End Date TotalHrs
emp1 vacation 5/1/2010 5/3/2010 24
Note: If the smae emp has sets of vacation in another month, that should come as a separate record with start date and end date(last date of vacation for that set).
I have a query which does not return any rows. Any help to repair this query or any better one would be of great help.
==================================================================
WITH vpt AS (
select personnum as empname, paycodename as paycode, applydate, timeinseconds/3600 as numhours from VP_TOTALS
where applydate between to_date('05/01/2010','MM/DD/YYYY') AND to_date('12/31/2010','MM/DD/YYYY')
AND paycodename in ('US-Vacation','US-Bereavement','US-Sick','US-Jury Duty')
select
empname,
paycode,
min(applydate) as startdate,
max(applydate) as enddate,
sum(numhours) as totalhours
from (
select
empname,
paycode,
applydate,
numhours,
-- number the blocks sequentially
sum(is_block_start) over (partition by empname, paycode order by applydate) as block_num
from (
select
empname,
paycode,
applydate,
numhours,
-- Mark the start of each block
case
when applydate = prev_applydate + 1 then 0 else 1 end as is_block_start
from (
select
empname,
paycode,
applydate,
numhours,
lag (applydate) over (partition by empname, paycode order by applydate) prev_applydate
from vpt
group by empname, paycode, block_num
===================================================================
Thanks,
MahaHi Dear,
Can I do reverse I mean I can get output as your question from your output as below:
I have this table
FID STARTD ATE END DATE
1 01-MAY-10 03-MAY-10
1 09-MAY-10 11-MAY-10
1 03-JUN-10 04-JUN-10
2 03-JUN-10 04-JUN-10
2 04-AUG-10 04-AUG-10
2 06-AUG-10 06-AUG-10
I want like this.
FID FDATE
1 01-MAY-10
1 02-MAY-10
1 03-MAY-10
1 09-MAY-10
1 10-MAY-10
1 11-MAY-10
1 03-JUN-10
1 04-JUN-10
2 03-JUN-10
2 04-JUN-10
2 04-AUG-10
2 06-AUG-10
And:
How can i get date wise entry from Joining date to relieving date like..
FID START DATE END DATE
1 01-MAY-10 03-MAY-12
1 09-MAY-10 11-MAY-11
2 04-AUG-10 04-AUG-11
I want like this.
FID FDATE
1 01-MAY-10
1 03-MAY-10
1 04-MAY-10
1 05-MAY-10
1 16-MAY-10
1 17-MAY-10
1 08-May-10
1 09-May-10
1 03-May-12
Can you please help me.
Thanks,
Edited by: 978452 on Dec 24, 2012 12:02 AM -
How to write a sql query to retrieve data entered in the past 2 weeks
Hi,
I have file names and last accessed date(java.sql.Date format) stored in my database table, I would like to know how I can write a query to get the name of files accessed in the past 2 weeks,I use open sql server at the back end.
Thanks in advance.This has essentially nothing to do with JDBC. JDBC is just an API to execute the SQL language using Java and thus interact with the databases.
Your problem is related to the SQL language, you don't know how to write the SQL language. I suggest you to go through a SQL tutorial (there is one at w3schools.com) and to read the SQL documentation which come along with the database in question. A decent database manfacturer has a website and probably also a discussion forum / mailinglist as well.
I'll give you a hint: you can just use equality operators in SQL like everywhere. For example: "WHERE date < somedate". -
Get Numbers to display TODAY date but without the time
I have these old excel sheets that you have to constantly fill in the date for the previous week, but I saw that Numbers does this
=TODAY()-4 to give me a real date in the past!
But now I don't know how to get rid of the hours or time that appears as well.
This is all of my two minute journey into numbers today so I am still wetfoot, but ikes is it neat and fast that I got this far alreadyHello
I'm a bit surprised.
NOW() returns the current date_time but TODAY() returns only the current date.
So, if you didn't force an other format before inserting the formula,
a cell containing = TODAY() defaults to
date : xxxxxxx
time : NONE
It's the same if the cell contains = TODAY()-4
Yvan KOENIG (from FRANCE mardi 29 janvier 2008 22:13:47) -
When printing within Firefox, what is the custom print option to print the date (e.g. 06/06/2010) without the date appearing after it (i.e. NOT 06/06/2010 11:15)?
Note: even when the custom print option of "&D" is used, the time still appears...As far as I can tell, there's no built-in option to get the date printed without the time. It's hardcoded in a C++ file.
As a workaround, you can enter custom text for the footer, but it would need to be updated every time the date changed. I can think of a couple ways to automate that:
* An add-on (but I'm not aware of any add-on for this)
* External process to push a new date into prefs.js, a settings file that stores your header/footer preferences, among others (but Firefox should be closed when you update this file, and it will be read when you restart)
Not easy enough, I know. -
How to get only the date without the time in the footer of a printout?
Is there a way to get only the date without the time in the footer of a printout?
As far as I can tell, there's no built-in option to get the date printed without the time. It's hardcoded in a C++ file.
As a workaround, you can enter custom text for the footer, but it would need to be updated every time the date changed. I can think of a couple ways to automate that:
* An add-on (but I'm not aware of any add-on for this)
* External process to push a new date into prefs.js, a settings file that stores your header/footer preferences, among others (but Firefox should be closed when you update this file, and it will be read when you restart)
Not easy enough, I know. -
Why does not my query use an index?
I have a table with some processed rows (state: 9) and some unprocessed rows (states: 0,1,2,3,4).
This table has over 120000 rows, but this number will grow.
Most of the rows are processed and most of them also contain a group id. Number of groups is relatively small (let's assume 20).
I would like to obtain the oldest some_date for every group. This values has to be outer joined to a on-line report (contains one row for each group).
Here is my set-up:
Tested on: 10.2.0.4 (Solaris), 10.2.0.1 (WinXp)
drop table t purge;
create table t(
id number not null primary key,
grp_id number,
state number,
some_date date,
pad char(200)
insert into t(id, grp_id, state, some_date, pad)
select level,
trunc(dbms_random.value(0,20)),
9,
sysdate+dbms_random.value(1,100),
'x'
from dual
connect by level <= 120000;
insert into t(id, grp_id, state, some_date, pad)
select level + 120000,
trunc(dbms_random.value(0,20)),
trunc(dbms_random.value(0,5)),
sysdate+dbms_random.value(1,100),
'x'
from dual
connect by level <= 2000;
commit;
exec dbms_stats.gather_table_stats(user, 'T', estimate_percent=>100, method_opt=>'FOR ALL COLUMNS SIZE 1');
Tom Kyte's printtab
==============================
TABLE_NAME : T
NUM_ROWS : 122000
BLOCKS : 3834I know, this could be easily solved by fast refresh on commit materialized view like this:
select
grp_id,
min(some_date),
from
t
where
state in (0,1,2,3,4)
grpup by
grp_id;+ I have to create log on (grp_id, some_date, state)
Number of rows with active state will be always relatively small. Let's assume 1000-2000.
So my another idea was to create a selective index. An index which would contain only data for rows with an active state.
Something like this:
create index fidx_active on t (
case state
when 0 then grp_id
when 1 then grp_id
when 2 then grp_id
when 3 then grp_id
when 4 then grp_id
end,
case state
when 0 then some_date
when 1 then some_date
when 2 then some_date
when 3 then some_date
when 4 then some_date
end) compress 1; so a tuple (group_id, some_date) is projected to tuple (null, null) when the state is not an active state and therefore it is not indexed.
We can save even more space by compressing 1st expression.
analyze index idx_grp_state_date validate structure;
select * from index_stats
@pr
Tom Kyte's printtab
==============================
HEIGHT : 2
BLOCKS : 16
NAME : FIDX_ACTIV
LF_ROWS : 2000 <-- we're indexing only active rows
LF_BLKS : 6 <-- small index: 1 root block with 6 leaf blocks
BR_ROWS : 5
BR_BLKS : 1
DISTINCT_KEYS : 2000
PCT_USED : 69
PRE_ROWS : 25
PRE_ROWS_LEN : 224
OPT_CMPR_COUNT : 1
OPT_CMPR_PCTSAVE : 0Note: @pr is a Tom Kyte's print table script adopted by Tanel Poder (I'm using Tanel's library) .
Then I created a query to be outer joined to the report (report contains a row for every group).
I want to achieve a full scan of the index.
select
case state -- 1st expression
when 0 then grp_id
when 1 then grp_id
when 2 then grp_id
when 3 then grp_id
when 4 then grp_id
end grp_id,
min(case state --second expression
when 0 then some_date
when 1 then some_date
when 2 then some_date
when 3 then some_date
when 4 then some_date
end) as mintime
from t
where
case state --1st expression: at least one index column has to be not null
when 0 then grp_id
when 1 then grp_id
when 2 then grp_id
when 3 then grp_id
when 4 then grp_id
end is not null
group by
case state --1st expression
when 0 then grp_id
when 1 then grp_id
when 2 then grp_id
when 3 then grp_id
when 4 then grp_id
end;-------------
Doc's snippet:
13.5.3.6 Full Scans
A full scan is available if a predicate references one of the columns in the index. The predicate does not need to be an index driver. A full scan is also available when there is no predicate, if both the following conditions are met:
All of the columns in the table referenced in the query are included in the index.
At least one of the index columns is not null.
A full scan can be used to eliminate a sort operation, because the data is ordered by the index key. It reads the blocks singly.
13.5.3.7 Fast Full Index Scans
Fast full index scans are an alternative to a full table scan when the index contains all the columns that are needed for the query, and at least one column in the index key has the NOT NULL constraint. A fast full scan accesses the data in the index itself, without accessing the table. It cannot be used to eliminate a sort operation, because the data is not ordered by the index key. It reads the entire index using multiblock reads, unlike a full index scan, and can be parallelized.
You can specify fast full index scans with the initialization parameter OPTIMIZER_FEATURES_ENABLE or the INDEX_FFS hint. Fast full index scans cannot be performed against bitmap indexes.
A fast full scan is faster than a normal full index scan in that it can use multiblock I/O and can be parallelized just like a table scan.
So the question is: Why does oracle do a full table scan?
Everything needed is in the index and one expression is not null, but index (fast) full scan is not even considered by CBO (I did a 10053 trace)
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
| 1 | HASH GROUP BY | | 1 | 85 | 20 |00:00:00.11 | 3841 |
|* 2 | TABLE ACCESS FULL| T | 1 | 6100 | 2000 |00:00:00.10 | 3841 |
Predicate Information (identified by operation id):
2 - filter(CASE "STATE" WHEN 0 THEN "GRP_ID" WHEN 1 THEN "GRP_ID" WHEN 2
THEN "GRP_ID" WHEN 3 THEN "GRP_ID" WHEN 4 THEN "GRP_ID" END IS NOT NULL)Let's try some minimalistic examples. Firstly with no FBI.
create index idx_grp_id on t(grp_id);
select grp_id,
min(grp_id) min
from t
where grp_id is not null
group by grp_id;
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads |
| 1 | HASH GROUP BY | | 1 | 20 | 20 |00:00:01.00 | 244 | 237 |
|* 2 | INDEX FAST FULL SCAN| IDX_GRP_ID | 1 | 122K| 122K|00:00:00.54 | 244 | 237 |
Predicate Information (identified by operation id):
2 - filter("GRP_ID" IS NOT NULL)This kind of output I was expected to see with FBI. Index FFS was used although grp_id has no NOT NULL constraint.
Let's try a simple FBI.
create index fidx_grp_id on t(trunc(grp_id));
select trunc(grp_id),
min(trunc(grp_id)) min
from t
where trunc(grp_id) is not null
group by trunc(grp_id);
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
| 1 | HASH GROUP BY | | 1 | 20 | 20 |00:00:00.94 | 3841 |
|* 2 | TABLE ACCESS FULL| T | 1 | 6100 | 122K|00:00:00.49 | 3841 |
Predicate Information (identified by operation id):
2 - filter(TRUNC("GRP_ID") IS NOT NULL)Again, index (fast) full scan not even considered by CBO.
I tried:
alter table t modify grp_id not null;
alter table t add constraint trunc_not_null check (trunc(grp_id) is not null);I even tried to set table hidden column (SYS_NC00008$) to NOT NULL
It has no effect, FTS is still used..
Let's try another query:
select distinct trunc(grp_id)
from t
where trunc(grp_id) is not null
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
| 1 | HASH UNIQUE | | 1 | 20 | 20 |00:00:00.85 | 244 |
|* 2 | INDEX FAST FULL SCAN| FIDX_GRP_ID | 1 | 122K| 122K|00:00:00.49 | 244 |
Predicate Information (identified by operation id):
2 - filter("T"."SYS_NC00008$" IS NOT NULL)Here the index FFS is used..
Let's try one more query, very similar to the above query:
select trunc(grp_id)
from t
where trunc(grp_id) is not null
group by trunc(grp_id)
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
| 1 | HASH GROUP BY | | 1 | 20 | 20 |00:00:00.86 | 3841 |
|* 2 | TABLE ACCESS FULL| T | 1 | 122K| 122K|00:00:00.49 | 3841 |
Predicate Information (identified by operation id):
2 - filter(TRUNC("GRP_ID") IS NOT NULL)And again no index full scan..
So my next question is:
What are the restrictions which prevent index (fast) fullscan to be used in these scenarios?
Thank you very much for your answers.
Edited by: user1175494 on 16.11.2010 15:23
Edited by: user1175494 on 16.11.2010 15:25I'll start off with the caveat that i'm no Johnathan Lewis so hopefully someone will be able to come along and give you a more coherent explanation than i'm going to attempt here.
It looks like the application of the MIN function against the case statement is confusing the optimizer and disallowing the usage of your FBI. I tested this against my 11.2.0.1 instance and your query chooses the fast full scan without being nudged in the right direction.
That being said, i was able to get this to use a fast full scan on my 10 instance, but i had to jiggle the wires a bit. I modified your original query slightly, just to make it easier to do my fiddling.
original (in the sense that it still takes the full table scan) query
with data as
select
case state -- 1st expression
when 0 then grp_id
when 1 then grp_id
when 2 then grp_id
when 3 then grp_id
when 4 then grp_id
end as grp_id,
case state --second expression
when 0 then some_date
when 1 then some_date
when 2 then some_date
when 3 then some_date
when 4 then some_date
end as mintime
from t
where
case state --1st expression: at least one index column has to be not null
when 0 then grp_id
when 1 then grp_id
when 2 then grp_id
when 3 then grp_id
when 4 then grp_id
end is not null
and
case state --second expression
when 0 then some_date
when 1 then some_date
when 2 then some_date
when 3 then some_date
when 4 then some_date
end is not null
select--+ GATHER_PLAN_STATISTICS
grp_id,
min(mintime)
from data
group by grp_id;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL, NULL, 'allstats +peeked_binds'));
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
| 1 | HASH GROUP BY | | 2 | 33 | 40 |00:00:00.07 | 7646 |
|* 2 | TABLE ACCESS FULL| T | 2 | 33 | 4000 |00:00:00.08 | 7646 |
Predicate Information (identified by operation id):
2 - filter((CASE "STATE" WHEN 0 THEN "GRP_ID" WHEN 1 THEN "GRP_ID" WHEN 2
THEN "GRP_ID" WHEN 3 THEN "GRP_ID" WHEN 4 THEN "GRP_ID" END IS NOT NULL AND
CASE "STATE" WHEN 0 THEN "SOME_DATE" WHEN 1 THEN "SOME_DATE" WHEN 2 THEN
"SOME_DATE" WHEN 3 THEN "SOME_DATE" WHEN 4 THEN "SOME_DATE" END IS NOT
NULL))
modified version where we prevent the MIN function from being applied too early, by using ROWNUM
with data as
select
case state -- 1st expression
when 0 then grp_id
when 1 then grp_id
when 2 then grp_id
when 3 then grp_id
when 4 then grp_id
end as grp_id,
case state --second expression
when 0 then some_date
when 1 then some_date
when 2 then some_date
when 3 then some_date
when 4 then some_date
end as mintime
from t
where
case state --1st expression: at least one index column has to be not null
when 0 then grp_id
when 1 then grp_id
when 2 then grp_id
when 3 then grp_id
when 4 then grp_id
end is not null
and
case state --second expression
when 0 then some_date
when 1 then some_date
when 2 then some_date
when 3 then some_date
when 4 then some_date
end is not null
and rownum > 0
select--+ GATHER_PLAN_STATISTICS
grp_id,
min(mintime)
from data
group by grp_id;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL, NULL, 'allstats +peeked_binds'));
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
| 1 | HASH GROUP BY | | 2 | 20 | 40 |00:00:00.01 | 18 |
| 2 | VIEW | | 2 | 33 | 4000 |00:00:00.07 | 18 |
| 3 | COUNT | | 2 | | 4000 |00:00:00.05 | 18 |
|* 4 | FILTER | | 2 | | 4000 |00:00:00.03 | 18 |
|* 5 | INDEX FAST FULL SCAN| FIDX_ACTIVE | 2 | 33 | 4000 |00:00:00.01 | 18 |
Predicate Information (identified by operation id):
4 - filter(ROWNUM>0)
5 - filter(("T"."SYS_NC00006$" IS NOT NULL AND "T"."SYS_NC00007$" IS NOT NULL)) -
SQL Query returns values like "---" and "NA"
Hi
When I execute a sql query in MII it returns values like "---" and "NA" for empty Char and numeric fields respectively.
I have checked the database and made sure that these fields does not have any value. This happens only when I run the query through MII. Can any one know how can we get rid of these values?
Thanks in advance
ShajiShaji,
MII sets those values as a default if it discovers null values in a query result. You can change this default behaviour in several ways.
First, have a look at the document [Setting custom null values in XML|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/70628af0-8ec4-2c10-7da2-f451e412dd8f?quicklink=index&overridelayout=true]. Then you may also use SQL functions like [NVL|http://www.techonthenet.com/oracle/functions/nvl.php] to change the value directly in the SQL query. You can also change the value inside the MII BLT to whatever you need.
Michael -
DATE type returned from function does not return the time component
Hi,
I'm dealing with a strange problem. I have a PL/SQL function (running on Oracle 8.1.4.7) which returns a DATE value. Like we all know the DATE datatype includes a date component and a time component.
The function I used for testing is like this:
FUNCTION ReturnDate return Date is
dReturn Date;
Begin
select sysdate into dReturn from dual;
return dReturn;
end ReturnDate;
When I call this function from .NET using ODP.NET the date value I get does not have the time component included only the day-month-year components.
This is a code-snippet that calls the function :
command.CommandText="Schema.ReturnDate";
command.CommandType=CommandType.StoredProcedure;
command.Parameters.Add("Return_Value",
OracleDbType.Date,0,ParameterDirection.ReturnValue);
command.ExecuteNonQuery();
I use the OracleDbType.Date type which I think is the most logical choice, because the type in the Database is after all DATE.
However this does not include the time componet. But if I change the OracleDbType.Date to OracleDbType.TimeStamp I get the time component. I'm not happy with this "hack" because I'm not sure what will happen when we upgrade our version of the Database to Oracle 9i which uses the new TimeStamp datatype.
Is this a bug that the OracleDbType.Date does not include the time component??How do you examine the output Date value?
If it is from the string, then the time components will
not show because the NLS_DATE format in the client
machine does not contain the time components.
In American, the Date format is 'DD-MON-RR' by default whereas, the TimeStamp format is 'DD-MON-RR HH.MI.SSXFF AM' by default.
Can you take a look at the time components from the OracleDate by accessing the time properties, eg. OracleDate.Hour, OracleDate.Minute..etc to see if the time values are there?
Thanks
Martha -
Hi all...
How does a SQL query basically work? Is there any pseudocode for it?
How ro calculate the cost of query?
Can we find out what would be the execution time for a query before it is executed?
Thanks in advance.
AmeyaHi Avinash,
Look closely mate!!!
You have done set autotrace on... meaning you are executing the statement while i am doing set autotrace traceonly explain meaning the statement would never get executed actually.. oracle optimizer will just select the desired plan and will show the output..
You can even ESTIMATE how many rows the qeury will return before even executing the statement using the same above tech.. i will show you how:
The explain plan gives this -- as long as you are using the CBO (cost based
optimizer). Doesn't matter if you have 1 or 50 tables. The last part of the
plan is the estimate output.
consider:
SQL> set autotrace traceonly explain
SQL> select e1.*, e2.* from emp e1, emp e2;
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=15 Card=196 Bytes=12544)
1 0 MERGE JOIN (CARTESIAN) (Cost=15 Card=196 Bytes=12544)
2 1 TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=14 Bytes=448)
3 1 SORT (JOIN) (Cost=14 Card=14 Bytes=448)
4 3 TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=14 Bytes=448)
196 = 14 * 14 -- thats right....
SQL> select emp.ename, mgr.ename from
2 emp, emp mgr
3 where emp.mgr = mgr.empno;
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=13 Bytes=208)
1 0 MERGE JOIN (Cost=5 Card=13 Bytes=208)
2 1 SORT (JOIN) (Cost=3 Card=14 Bytes=112)
3 2 TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=14 Bytes=112)
4 1 SORT (JOIN) (Cost=3 Card=14 Bytes=112)
5 4 TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=14 Bytes=112)
Here is estimated that about 13 rows would be returned...
SQL> select count(*) from emp;
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1)
1 0 SORT (AGGREGATE)
2 1 INDEX (FULL SCAN) OF 'EMP_PK' (UNIQUE) (Cost=1 Card=14)
one row...
SQL> select ename, dname
2 from emp, dept where emp.deptno = dept.deptno;
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=14 Bytes=252)
1 0 NESTED LOOPS (Cost=5 Card=14 Bytes=252)
2 1 TABLE ACCESS (FULL) OF 'DEPT' (Cost=1 Card=4 Bytes=44)
3 1 TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=14 Bytes=98)
14 rows...
1 select ename, dname
2* from emp, dept where emp.deptno = dept.deptno and emp.ename like '%A%'
SQL> /
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=18)
1 0 NESTED LOOPS (Cost=2 Card=1 Bytes=18)
2 1 TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=1 Bytes=7)
3 1 TABLE ACCESS (BY INDEX ROWID) OF 'DEPT' (Cost=1 Card=4 Bytes=44)
4 3 INDEX (RANGE SCAN) OF 'DEPT_IDX' (NON-UNIQUE)
1 rows.....
and this was all done without executing the query. See EXPLAIN plan and the
PLAN_TABLE. -
Sorting of Date field in the SQL Query useing ORDER BY
Hi
I am facing a problem when I am getting the results of a query from the ORacle 8i database using jdbc connection.
The query is having a date field and I have to sort the query results using ORDER By for the Date field. The query is giving exact results in the SQL PLus interface.
When I am getting this results in the GUI where servlets are being used an Exception is coming as not supported RefreshRow method.
If anyone has faced this problem and have got the solutions please let me know.
thanks
sulfyThat doesn't sound at all like an SQL problem.
More like you trying to do updates on the resultset which is not allowed ...
send a some code (not to much pls :) and we'll be
able to help more
cu
Spieler -
Morning all,
I've just been assigned a report-related project but I have not created much of anything in C# or .Net before!
I was wondering if someone could help me get started. Here are the specifications:
Basically, I am to create an automated report application. I have the query and I will include it further down
in this post. The page is to have a couple blanks to specify the Start Date and End Date and replace those dates in the query, and generate the report. What I need some help on is how to make the SQL query work in the application which I will connect to the
intended database to generate the report (basic I know, but I'm new at this) on Visual Studio 2010. I also need some help on programming the Start Date blank and End Date blank so that what the user types in for those blanks will replace the date fields in
the SQL query, then generate the report with the new dates.
I appreciate the help!
The SQL query and what the dates are replacing:
select
PTH.INST_ID ,
PTH.EMPLOYEE_ID,
DBH.HR_DEDUCTION_AND_BENEFITS_CODE,
replace(DB.DESCRIPTION,',',''),
DB.WITHHOLDING_LIABILITY_ACCOUNT_MASK,
DBH.HR_DEDUCTION_AND_BENEFITS_ID,
DBH.CHECK_DATE,
DBH.CHECK_NO,
DBH.FIN_INST_ACCT_ID,
replace(replace (DBH.COMMENT,CHAR(10),' '),CHAR(13),' '),
DBH.HR_DEDUCTION_AND_BENEFIT_CYCLE_CODE,
DBH.LENGTH,
DBH.EMPLOYEE_COMPUTED_AMOUNT,
DBH.EMPLOYEE_BANK_ROUTING_NUMBER,
DBH.EMPLOYEE_ACCOUNT_TYPE,
DBH.EMPLOYEE_ACCOUNT_NUMBER,
DBH.EMPLOYER_COMPUTED_AMOUNT,
DBH.EMPLOYEE_GROSS_AMOUNT,
DBH.EMPLOYER_GROSS_AMOUNT,
DBH.PAYROLL_EXCLUDE,
PTH.VOID_DATE,
PTH.BATCH_QUEUE_ID,
B.BATCH_CODE,
BQ.FY,
BQ.END_DATE,
BQ.COMMENTS,
BQ.BATCH_CRITERIA_USED,
BP.COLUMN_VALUE,
PTH.REPLACEMENT,
P.LAST_NAME,
P.FIRST_NAME,
P.MIDDLE_NAME
from PY_EMPLOYEE_TAX_HISTORY PTH
INNER JOIN PERSON_EMPLOYEE PE ON
PE.INST_ID=PTH.INST_ID AND
PE.EMPLOYEE_ID=PTH.EMPLOYEE_ID
INNER JOIN PERSON P ON
PE.INST_ID=P.INST_ID AND
PE.PERSON_ID=P.PERSON_ID
LEFT JOIN HR_EMPLOYEE_DEDUCTIONS_AND_BENEFITS_HISTORY DBH ON
PTH.INST_ID=DBH.INST_ID AND
PTH.CHECK_DATE=DBH.CHECK_DATE AND
PTH.CHECK_NO=DBH.CHECK_NO AND
PTH.EMPLOYEE_ID=DBH.EMPLOYEE_ID
LEFT JOIN HR_DEDUCTION_AND_BENEFITS DB ON
DB.INST_ID=DBH.INST_ID AND
DB.HR_DEDUCTION_AND_BENEFITS_CODE=DBH.HR_DEDUCTION_AND_BENEFITS_CODE
LEFT JOIN BATCH_QUEUE BQ ON
PTH.BATCH_QUEUE_ID=BQ.BATCH_QUEUE_ID
LEFT JOIN BATCH B ON
B.BATCH_CODE=BQ.BATCH_CODE
LEFT JOIN BATCH_PARAMETER BP ON
BQ.BATCH_QUEUE_ID=BP.BATCH_QUEUE_ID
AND BP.COLUMN_NAME = 'SUPPRESS_DIRECT_DEPOSIT'
------Please change the WHERE condition for date range of the month you need to run this for.
WHERE PTH.CHECK_DATE >='07/01/2013'
AND PTH.CHECK_DATE <='07/31/2013'
and BQ.BATCH_CODE='BAT_PY_PAYCALC'
and bq.fy=2014
ORDER BY PTH.INST_ID ,
PTH.EMPLOYEE_ID,
DBH.HR_DEDUCTION_AND_BENEFITS_CODE,
DBH.CHECK_DATETry this code. The Server name will be the same name when you use SQL Server Management Studio (SSMS). It is in the login window for SSMS. I assume you are using SQLSTANDARD (not SQLEXPRESS) which is in the connection string in the code
below. I also assume you have remote connection allowed in the database.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication1
class Program
const string DATABASE = "Enter Database Name Here";
const string SERVER = "Enter Server Name Here";
static void Main(string[] args)
DateTime startDate = DateTime.Parse("07/01/2013");
string startDateStr = startDate.ToString("MM/dd/yyyy");
DateTime endDate = new DateTime(startDate.Year, startDate.Month + 1, 1).AddDays(-1);
string endDateStr = endDate.ToString("MM/dd/yyyy");
string connStr = string.Format("Server={0}\\SQLSTANDARD;Database={1};Trusted_Connection= True;", SERVER,DATABASE);
string SQL = string.Format(
"select\n" +
" PTH.INST_ID\n" +
",PTH.EMPLOYEE_ID\n" +
",DBH.HR_DEDUCTION_AND_BENEFITS_CODE,\n" +
",replace(DB.DESCRIPTION,',','')\n" +
",DB.WITHHOLDING_LIABILITY_ACCOUNT_MASK\n" +
",DBH.HR_DEDUCTION_AND_BENEFITS_ID\n" +
",DBH.CHECK_DATE\n" +
",DBH.CHECK_NO\n" +
",DBH.FIN_INST_ACCT_ID\n" +
",replace(replace (DBH.COMMENT,CHAR(10),' '),CHAR(13),' ')\n" +
",DBH.HR_DEDUCTION_AND_BENEFIT_CYCLE_CODE\n" +
",DBH.LENGTH\n" +
",DBH.EMPLOYEE_COMPUTED_AMOUNT\n" +
",DBH.EMPLOYEE_BANK_ROUTING_NUMBER\n" +
",DBH.EMPLOYEE_ACCOUNT_TYPE\n" +
",DBH.EMPLOYEE_ACCOUNT_NUMBER\n" +
",DBH.EMPLOYER_COMPUTED_AMOUNT\n" +
",DBH.EMPLOYEE_GROSS_AMOUNT\n" +
",DBH.EMPLOYER_GROSS_AMOUNT\n" +
",DBH.PAYROLL_EXCLUDE\n" +
",PTH.VOID_DATE\n" +
",PTH.BATCH_QUEUE_ID\n" +
",B.BATCH_CODE\n" +
",BQ.FY\n" +
",BQ.END_DATE\n" +
",BQ.COMMENTS\n" +
",BQ.BATCH_CRITERIA_USED\n" +
",BP.COLUMN_VALUE\n" +
",PTH.REPLACEMENT\n" +
",P.LAST_NAME\n" +
",P.FIRST_NAME\n" +
",P.MIDDLE_NAME\n" +
" from PY_EMPLOYEE_TAX_HISTORY PTH\n" +
" INNER JOIN PERSON_EMPLOYEE PE ON\n" +
" PE.INST_ID=PTH.INST_ID AND\n" +
" PE.EMPLOYEE_ID=PTH.EMPLOYEE_ID\n" +
" INNER JOIN PERSON P ON\n" +
" PE.INST_ID=P.INST_ID AND\n" +
" PE.PERSON_ID=P.PERSON_ID\n" +
" LEFT JOIN HR_EMPLOYEE_DEDUCTIONS_AND_BENEFITS_HISTORY DBH ON\n" +
" PTH.INST_ID=DBH.INST_ID AND\n" +
" PTH.CHECK_DATE=DBH.CHECK_DATE AND\n" +
" PTH.CHECK_NO=DBH.CHECK_NO AND\n" +
" PTH.EMPLOYEE_ID=DBH.EMPLOYEE_ID\n" +
" LEFT JOIN HR_DEDUCTION_AND_BENEFITS DB ON\n" +
" DB.INST_ID=DBH.INST_ID AND\n" +
" DB.HR_DEDUCTION_AND_BENEFITS_CODE=DBH.HR_DEDUCTION_AND_BENEFITS_CODE\n" +
" LEFT JOIN BATCH_QUEUE BQ ON\n" +
" PTH.BATCH_QUEUE_ID=BQ.BATCH_QUEUE_ID\n" +
" LEFT JOIN BATCH B ON\n" +
" B.BATCH_CODE=BQ.BATCH_CODE\n" +
" LEFT JOIN BATCH_PARAMETER BP ON\n" +
" BQ.BATCH_QUEUE_ID=BP.BATCH_QUEUE_ID\n" +
" AND BP.COLUMN_NAME = 'SUPPRESS_DIRECT_DEPOSIT'\n" +
" WHERE PTH.CHECK_DATE >='{0}'\n" +
" AND PTH.CHECK_DATE <='{1}'\n" +
" and BQ.BATCH_CODE='BAT_PY_PAYCALC'\n" +
" and bq.fy=2014\n" +
" ORDER BY PTH.INST_ID\n" +
",PTH.EMPLOYEE_ID\n" +
",DBH.HR_DEDUCTION_AND_BENEFITS_CODE\n" +
",DBH.CHECK_DATE", startDateStr, endDateStr);
SqlDataAdapter adapter = new SqlDataAdapter(SQL, connStr);
DataTable dt = new DataTable();
adapter.Fill(dt);
jdweng
Could you elaborate more on what this code does in general?
Does it generate a table with the data between specified dates? If so, where is the table shown?
Where does one enter in the specified start and end dates on the Web Application? Do I have to create start and end date blanks and link them to the code for it to work?
Sorry for the inconvenience - I'm just really new at this. Thanks!
Maybe you are looking for
-
How to restore/retrieve my files from external HD backed up by Time Machine
I'm recently a victim of car theft and my MacBook Pro, iPad 2 and external hard drive was stolen from the car. A friend of mine is lending me his MacBook Air to temporary use until I get a new MBP. I use Time Machine and Time Capsule to do frequent b
-
We are getting the following error when we try to recover from a specific server ( Recovery Tab | Domain | File Server ) Unable to connect to the DPM Database because the database is in an inconsistent state. (ID943) => There are no double entries fo
-
Emails messages duplicated in the inbox
After various iOS updates, I am still having issues with some email messages being duplicated in the INBOX view. Are others having the same issue?
-
Can I move the Photoshop Elements 6.0 from an older iMac to a new one? The new iMac has no drive? Jerryt
-
I'm trying to build xmlto on the Mac and I'm getting errors like: I/O error : Attempt to load network entity http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl Anyone been able to actually resolve this?