Collection of Useful functions in Oracle 11g Part 05

No.of Views1221
Bookmarked0 times
Downloads 
Votes0
By  Nimish Garg   On  28 Aug 2010 00:08:55
Tag : Oracle , Database Administrator
In this article, i have given samples to another few no of function demonstration here in oracle 11g
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

 

Introduction

In this article, i have given another few no of useful functions and alternatives way  demonstration in oracle 11g

  1. DDL, DML and DCL commands
  2. Date Difference in Days, Months and Years
  3. Fibonacci Series by SQL 

DDL, DML and DCL commands

http://nimishgarg.blogspot.com/2010/08/oracle-ddl-dml-and-dcl-commands.html

DDL

Data Definition Language: statements used to define the database structure or schema. Some examples:

  • CREATE - to create objects in the database
  • ALTER - alters the structure of the database
  • DROP - delete objects from the database
  • TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed
  • COMMENT - add comments to the data dictionary
  • RENAME - rename an object

DML

Data Manipulation Language: statements used for managing data within schema objects. Some examples:

  • SELECT - retrieve data from the a database
  • INSERT - insert data into a table
  • UPDATE - updates existing data within a table
  • DELETE - deletes all records from a table, the space for the records remain
  • MERGE - UPSERT operation (insert or update)
  • CALL - call a PL/SQL or Java subprogram
  • EXPLAIN PLAN - explain access path to data
  • LOCK TABLE - control concurrency

DCL

Data Control Language. Some examples:

  • GRANT - gives user's access privileges to database
  • REVOKE - withdraw access privileges given with the GRANT command

TCL

Transaction Control: statements used to manage the changes made by DML statements. It allows statements to be grouped together into logical transactions.

  • COMMIT - save work done
  • SAVEPOINT - identify a point in a transaction to which you can later roll back
  • ROLLBACK - restore database to original since the last COMMIT
  • SET TRANSACTION - Change transaction options like isolation level and what rollback segment to use

Date Difference in Days, Months and Years

http://nimishgarg.blogspot.com/2010/08/oracle-sql-date-difference-in-days.html

with mytab as(select sysdate dt1, (sysdate-951) dt2 from dual
)selectcase whenround(round(last_day(dt2) - dt2) + round(dt1 - trunc(dt1,'month'))) >to_char(last_day(dt2),'dd')thenround(round(last_day(dt2) - dt2) + round(dt1 - trunc(dt1,'month'))) - to_char(last_day(dt2),'dd')elseround(round(last_day(dt2) - dt2) + round(dt1 - trunc(dt1,'month')))end days,mod(floor(months_between(dt1,dt2)),12) months,floor(months_between(dt1,dt2)/12) years
frommytab;

 

Fibonacci Series by SQL

http://nimishgarg.blogspot.com/2010/08/oracle-fibonacci-series-by-sql.html

You can use phi to compute the nth number in the Fibonacci series (fn).If you consider 0 in the Fibonacci series to correspond to n = 0, use this formula:

fn =  Phi n /

Query to generate 10 fibonacci series numbers

SELECT ROUND(POWER(1.6180339,LEVEL) / POWER(5,0.5)) FROM DUAL CONNECT BY LEVEL < =10

 The value of Phi can be calculated as

(1 + sqrt (5))/2 = 1.61803399

 So we can rewriet our query as

SELECT ROUND(POWER((1 + sqrt (5))/2,LEVEL) / POWER(5,0.5)) FROM DUAL CONNECT BY LEVEL < =10

 That's all, stay tune for more functions.

 
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