Showing posts with label query. Show all posts
Showing posts with label query. Show all posts

Thursday, August 9, 2012

add_months Function Quarter start date and end date


how can i get the start date n end date of quarter?eg. if i pass date as 30/07/2012 then start date should be 01/07/2012 to 30/09/2012,If i pass 21/12/2012 then it should be 01/10/2012 to
31/12/2012


SQL> select TRUNC(sysdate+1, 'Q'),TRUNC(ADD_MONTHS(sysdate, +3), 'Q')-1 from dual;

TRUNC(SYS TRUNC(ADD
--------- ---------
01-JUL-12 30-SEP-12



SQL> select TRUNC(to_date('30-jul-12'), 'Q'),TRUNC(ADD_MONTHS('30-jul-12',+3), 'Q')-1 from dual;

TRUNC(TO_ TRUNC(ADD
--------- ---------
01-JUL-12 30-SEP-12


SQL> select TRUNC(to_date('21-dec-12'),'Q'),TRUNC(ADD_MONTHS('21-dec-12',+3), 'Q')-1 from dual;

TRUNC(TO_ TRUNC(ADD
--------- ---------
01-OCT-12 31-DEC-12



references

http://www.dba-oracle.com/job_scheduling/dates_times.htm

http://www.oracle.com/technetwork/issue-archive/2012/12-jan/o12plsql-1408561.html
http://www.techonthenet.com/oracle/functions/add_months.php

http://www.sql-server-helper.com/functions/get-first-day-of-quarter.aspx

http://www.tek-tips.com/viewthread.cfm?qid=1635253
https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3868465700346538981



Thursday, December 22, 2011

Running SQL query


------------old

set heading off

select aa from (
select distinct a.sql_id,a.piece,a.sql_text aa,b.first_load_time from v$sqltext a,v$sqlarea b,v$session c where
a.sql_id=b.sql_id
AND c.command = b.command_type
And C.Username = B.Parsing_Schema_Name
and c.sql_hash_value = b.hash_value
and c.sql_address = b.address
and c.username is not null
And B.Parsing_Schema_Name='LDBO'
and c.module='ld.exe'
order by first_load_time desc,sql_id,piece);




-------------------sqlplus

set heading off

select aa from (
select a.sql_id,a.piece,to_char(b.SQL_FULLTEXT) aa,b.first_load_time from v$sqltext a,v$sqlarea b,v$session c where
a.sql_id=b.sql_id
AND c.command = b.command_type
And C.Username = B.Parsing_Schema_Name
and c.sql_hash_value = b.hash_value
and c.sql_address = b.address
and c.username is not null
And B.Parsing_Schema_Name='LDBO'
and c.module='ld.exe'
order by first_load_time desc,sql_id,piece);



------------full sqltext--------at plsql---- sqldeveloper-----

select aa from (
select a.sql_id,a.piece,to_char(b.SQL_FULLTEXT) aa,b.first_load_time from v$sqltext a,v$sqlarea b,v$session c where
a.sql_id=b.sql_id
AND c.command = b.command_type
And C.Username = B.Parsing_Schema_Name
and c.sql_hash_value = b.hash_value
and c.sql_address = b.address
and c.username is not null
And B.Parsing_Schema_Name='LDBO'
and c.module='ld.exe'
order by first_load_time desc,sql_id,piece);


----------------------------sqltext with operation-----------

SELECT s.sql_fulltext, sp.id, sp.parent_id, sp.operation, sp.object_name
FROM v$sqlarea s, v$sql_plan sp ,v$session c
WHERE s.address = sp.address AND s.hash_value = sp.hash_value
AND s.plan_hash_value = sp.plan_hash_value
And C.Username = s.Parsing_Schema_Name
and c.sql_hash_value = s.hash_value
and s.Parsing_Schema_Name='LDBO'
and c.module='ld.exe'
ORDER BY s.plan_hash_value,sp.id;



Followers