Collection of Useful functions in Oracle 11g Part 6

No.of Views620
Bookmarked0 times
Downloads 
Votes0
By  Nimish Garg   On  30 Nov 2010 09:11:47
Tag : Oracle , Database Administrator
In this article,I'm going to publish few more useful functions can use in oracle.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

1.Generate XML of Output of Query

http://nimishgarg.blogspot.com/2010/11/generate-xml-of-output-of-query.html

This is script to help to generate query output as XML format.

Query

select dbms_xmlgen.getxml('select empno, ename, dname from scott.emp e, scott.dept d where d.deptno=e.deptno') from dual;

Output 

Image Loading

2.Compare Two Tables Structures

http://nimishgarg.blogspot.com/2010/11/compare-two-tables-structures.html

In this script help to compare two tables structure in oracle database.

Script

SELECT
    A.COLUMN_NAME, 
    A.DATA_TYPE, 
    A.DATA_LENGTH,
    B.COLUMN_NAME, 
    B.DATA_TYPE, 
    B.DATA_LENGTH
FROM 
    (SELECT * FROM USER_TAB_COLUMNS WHERE TABLE_NAME  = 'TABLE1') A, 
    (SELECT * FROM USER_TAB_COLUMNS WHERE TABLE_NAME  = 'TABLE2') B
WHERE
    A.COLUMN_NAME = B.COLUMN_NAME (+)
UNION
SELECT
    A.COLUMN_NAME, 
    A.DATA_TYPE, 
    A.DATA_LENGTH,
    B.COLUMN_NAME, 
    B.DATA_TYPE, 
    B.DATA_LENGTH
FROM 
    (SELECT * FROM USER_TAB_COLUMNS WHERE TABLE_NAME  = 'TABLE1') A, 
    (SELECT * FROM USER_TAB_COLUMNS WHERE TABLE_NAME  = 'TABLE2') B
WHERE
    A.COLUMN_NAME (+) = B.COLUMN_NAME.

Output

 

Image Loading

3.Date Functions

http://nimishgarg.blogspot.com/2010/11/oracle-some-important-date-queries.html

3.1 How to get today day in oracle ?

select to_char(sysdate,'DAY') AS "TODAYS DAY" from dual

Output

TODAYS DAY
------------------------------------
MONDAY

 

3.2 How to get day of week in oracle?

select to_char(sysdate,'D') AS "DAY OF WEEK" from dual

Output

D
-
2


3.3 How to get week no of current year?
 

select to_char(sysdate,'IW') AS "WEEK OF THE YEAR" from dual

Output

WE
--
23

3.4 How to get current month name (Short name )in Oracle?

select to_char(sysdate,'MON') AS "MONTH" from dual

Output

MONTH
------------
JUN

3.5 How to get full name of the Month in Oracle?

select to_char(sysdate,'MONTH') AS "MONTH" from dual

Output

MONTH
------------------------------------
JUNE

3.6 How to get current month Number in oracle?

select to_char(sysdate,'MM') AS "MONTH" from dual

Output

MO
--
06

I hope these functions are will help to lot.i will publish more in upcoming articles.thank you reading.

 
Sign Up to vote for this article
 
About Author
 
Nimish Garg
Occupation-Software Engineer
Company-Indiamart Intermesh Limited
Member Type-Junior
Location-India
Joined date-04 Jun 2010
Home Page-http://nimishgarg.blogspot.com/
Blog Page-http://nimishgarg.blogspot.com/
Oracle DBA (Performance Tuning and Query Optimization) IndiaMART InterMESH Limited, Noida
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top