IntroductionIn this article, i have given another few no of useful functions and alternatives way demonstration in oracle 11g - DDL, DML and DCL commands
- Date Difference in Days, Months and Years
- Fibonacci Series by SQL
DDL, DML and DCL commandshttp://nimishgarg.blogspot.com/2010/08/oracle-ddl-dml-and-dcl-commands.html DDLData 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
DMLData 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
DCLData Control Language. Some examples: - GRANT - gives user's access privileges to database
- REVOKE - withdraw access privileges given with the GRANT command
TCLTransaction 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 Yearshttp://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 SQLhttp://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 / 5½
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. |