RE: Quick SQL assistance

  • From: "Taylor, Chris David" <ChrisDavid.Taylor@xxxxxxxxxxxxxxx>
  • To: "'Allen, Brandon'" <Brandon.Allen@xxxxxxxxxxx>, 'Oracle L' <oracle-l@xxxxxxxxxxxxx>, 'Christopher Boyle' <cboyle@xxxxxxxxxxxxxxxxxxxxxx>
  • Date: Mon, 14 Sep 2009 15:33:51 -0500

Interesting....I think this will work, but had to add a TRIM to the TO_CHAR as 
it has spaces around "SUNDAY" (in my case).

select host_name, target_name, to_char(snap_date,'DAY'), snap_date, 
tablespace_size_mb
from
(
select distinct HOST_NAME,
TARGET_NAME,
TARGET_DESC,
TARGET_TYPE,
SNAP_DATE,
round(SUM(TABLESPACE_SIZE/1024/1024),2) as TABLESPACE_SIZE_MB,
round(sum(TABLESPACE_FREE_SIZE/1024/1024),2) as TABLESPACE_FREE_SIZE_MB,
round(sum(TABLESPACE_USED_SIZE/1024/1024),2) as TABLESPACE_USED_SIZE_MB,
round((sum(tablespace_used_size)/sum(tablespace_size))*100,2) as 
TABLESPACE_PERCENT_USED
from db_tablespaces
group by host_name, target_name, target_desc, target_type, snap_date
order by host_name, target_name
)
where trim(to_char(snap_date,'DAY'))='SUNDAY'

or

where to_char(snap_date,'D')=1 (Thanks to Christopher Boyle for that one as 
well)

I've never used TO_CHAR that way before.  Very enlightening!!


Chris Taylor
Sr. Oracle DBA
Ingram Barge Company
Nashville, TN 37205
Office: 615-517-3355
Cell: 615-354-4799
Email: chris.taylor@xxxxxxxxxxxxxxx<mailto:chris.taylor@xxxxxxxxxxxxxxx>

CONFIDENTIALITY NOTICE: This e-mail and any attachments are confidential and 
may also be privileged. If you are not the named recipient, please notify the 
sender immediately and delete the contents of this message without disclosing 
the contents to anyone, using them for any purpose, or storing or copying the 
information on any medium.


________________________________
From: Allen, Brandon [mailto:Brandon.Allen@xxxxxxxxxxx]
Sent: Monday, September 14, 2009 3:25 PM
To: Taylor, Chris David; 'Oracle L'
Subject: RE: Quick SQL assistance

I'm not sure if I understand what you're trying to get - you mean you only want 
it to return records where snap_date is a Tuesday?  If so, you can do that with 
this syntax:

WHERE to_char(snap_date,'DAY') =  'TUESDAY'

Regards,
Brandon


________________________________
Privileged/Confidential Information may be contained in this message or 
attachments hereto. Please advise immediately if you or your employer do not 
consent to Internet email for messages of this kind. Opinions, conclusions and 
other information in this message that do not relate to the official business 
of this company shall be understood as neither given nor endorsed by it.

Other related posts: