SlideShare a Scribd company logo
SESSION 01

TOPICS

1.Introduction Retrieving

2.Information from Database Tables

3.Simple Functions

4.Storing and Processing Dates and Times

5.SQL* Plus

6.Sub Queries

DATABASE

      Collection   of data

      It   a structure for storing information.

      They    are typically organized into tables, having collections of records

      You    may think of a table as a collection of columns and rows.

      For   example, a table named Employee might contain the EmpID, Empname,
      Empsalary, Empdesigination and other information about that employee.

      Each    row is called a data record and each column is called a record field.


RELATIONAL DATABASE

A relational database is a database that conforms to the relational model, and
refers to a database's data and schema (the database's structure of how that data
is arranged).
DBMS stands for Database Management System.

It   is a collection of interrelated data and a set of program to access the data.

The  main objective is to provide a convenient environment to retrieve and store
the data from the database.


RDBMS stands for Relational Database Management System.
Itis a software program used to create the database and it allows you to
enter, manipulate, and retrieve data
RDBMS      also structured in database tables, fields and records.
Most     RDBMS use SQL as database query language.

DIFFERENCE BETWEEN DBMS and RDBMS
Both    are used to organize data and provide retrieval of data.
DBMS   permits only one person to access the database at a given time; on the
other hand RDMS allows many users simultaneous access to the database.
RDBMS      leads DBMS in
Security   wise
Used    in large organizations to store large amount of data.
It   has quick retrieval mechanisms.

TYPES OF RDBMS
SYBASE


MS     SQL SERVER

MYSQL


Microsoft    ACCESS

DB2


TERADATA
RULES FOR WRITING SQL STATEMENTS
SQL    statements are not case sensitive.

SQL    statements can be on one or more lines.

Keywords    cannot be abbreviated or split across lines.

Clauses   are usually placed on separate lines.

Tabs   and indents are used to enhance readability.

All   SQL statements must be terminated by ";"


TOOLS IN ORACLE

SQL*PLUS - An Interface between the database and the languages.
SQL*LOADER - An Interface to load the data's from Flat files.




STEPS TO WORK ON ORACLE:




STEP 1 – ENTER INTO SERVER
STEP 2 – ENTERING INTO SQL*PLUS




STEP 3- ENTERING INTO OUR SCHEMA
SQL – STRUCTURED QUERY LANGAUGE
      •It   is used to communicate with a database.
      •It   is a language that provides an interface to relational database systems.

      •It
        is based on the work of Dr.E.F.Codd, in his first implementation SQL was
      developed by IBM in the mid 1970’s.
      •IBM was conducting a research project known as system R, and SQL was
      born from that research project
      •Laterin 1979, a company then known as Relational Software Inc. (now called
      as Oracle Corporation) released the first commercial version of SQL
      •SQL  is fully standardized by ANSI (American National Standards Institute),
      and it is the Standard language for relational database management systems
      •You    can use SQL to access Oracle, SQL server, Sybase, MySQL server. DB2,

ADVANTAGES OF SQL
SQL provides a variety of tasks, including:

      •Querying     data from the database

      •Inserting,   updating, and deleting rows in a table

      •Creating,    replacing, altering, and dropping objects

      •Controlling   access to the database and its objects.


TYPES OF SQL STATEMENTS
(a)QUERY STATEMENT

(b)DML

(c)DDL

(d)DCL

(e)TCL
(a) Query Statements

Select statement.

To display the contents from a table.

Syntax:    select column_name from table_name;

           Select * (view all columns) from table_name;


CLAUSES IN SELECT STATEMENT


(A) WHERE

The WHERE clause allows you to filter the results from an SQL statement.

Syntax:


Select col1, col2 from tab where col1>n;


(B) GROUP BY

The GROUP BY clause can be used in a SELECT statement to collect data across
multiple records and group the results by one or more columns.



Syntax:

Select col1, col2, avg (col1) from tab group by col1, col2;


(C) HAVING

The HAVING clause is used in combination with the GROUP BY clause. It can be used
in a SELECT statement to filter the records that a GROUP BY returns.
Syntax:

Select col1, col2, avg (col1) from tab group by col1, col2 having avg

(col1)>n;


(D) ORDER BY

The ORDER BY clause allows you to sort the records in your result set. The ORDER
BY clause can only be used in SELECT statements.

Syntax:

Select col1, col2 from tab order by [col1/col2];



Example includes all clauses.

Select col1, col2, avg (col1) from table_name where col1 >n group by col1, col2
having avg (col1)>n order by avg (col1)




USING SIMPLE FUNCTIONS



         •SINGLE   ROW FUNCTION

         •AGGREGATE   FUNCTION


SINGLE ROW FUNCTION - it takes single input and has an output for each
input.
TYPES OF SINGLE ROW FUNCTIONS
CHARACTER:
Takes character input and returns character or number as an output
Example: select Chr (65) from dual;

NUMERIC:
Performs calculations and returns number as an output.
Example: select mod (24, 4) from dual;

DATE:
To process dates and times.
Example: select last_day (sysdate) from dual;

CONVERSIONS:
To convert one data type to another.

Example: select to_char (sysdate,'month yyyy dd' ) from dual;

REGULAR EXPRESSION:
Allow to provide regular expression when searching data.
Example: select regexp_instr ('this is a good notes for you', ' g[[ :alpha: ]] {3} ' )
from dual;

AGGREGATE FUNCTIONS

      It can take many inputs and return single output.

Example: select avg (col), sum (col), max (col) from table_name group by col;


STORING AND PROCESSING DATES AND TIME

* CONVERTS DATETIMES USING TO_CHAR () AND TO_DATE ().
* DATETIME FUNCTIONS.



* TIME ZONES.



* TIMESTAMPS.



* TIME INTERVALS.




DEFAULT DATE FORMAT

DD-MON-YY.


Syntax: select sysdate from dual;




CONVERSION FUNCTION
TO_DATE ():


Converts the given string to a DATE format.


Syntax: select to_date ('01/jan/2009', 'dd/mon/yyyy') from dual;


TO_CHAR ():

Converts the datetime or number to a String format.

Syntax: select to_char (to_date ('01/jan/2009', 'dd/mon/yyyy'), 'month dd, yyyy')
              from dual;
DTIME FUNCTION
(i) ADD_MONTHS(x, y):


Returns the result of adding y months to x. If x is negative, y months are subtracted
from x.



Syntax: select add_months ('01-jan-2009', 3) from dual;



(ii) LAST_DAY(x):


Returns the last day for the month (x).


Syntax: select last_day ('01-jan-2009') from dual;


(iii) NEXT_DAY(x, day):


Returns the datetime of the next day following (x).


Syntax: select next_day ('01-jan-2009', 'Sunday') from dual;



(iv) ROUND(X, [UNIT]):


By default, x is rounded to the beginning of the nearest day. If you use an option
UNIT string, x is rounded to that UNIT.



Syntax: select round (to_date ('01-dec- 2009'), 'yyyy') from dual;
(v) SYSDATE ():


Returns the Current Date from the database.


Syntax: select sysdate from dual;




(vi) TRUNC(x, [UNIT]):


By default, x is truncated to the beginning of the day. If you use an option UNIT
string, x is truncated to that UNIT.



Syntax: select trunc (to_date ('06-jun-2009'), 'yyyy') from dual;




Changing the Session Time Zone:

Syntax: alter session set time_zone = 'PST';

Syntax: select sessiontimezone from dual;



Timestamps:

* A timestamp can store a fractional second.

* A timestamp can store a time zone.

TIME INTERVAL:

It is a data type that allows storing time intervals.
TIME INTERVAL TYPES:

(i) Interval Year to Month Type.



Syntax: create table table_name (column_name INTERVAL YEAR (3) TO MONTH);


(ii) Interval Day to Second Type.


Syntax: create table table_name (column_name INTERVAL DAY TO SECOND (4));


SQL*PLUS COMMAND
SPOOL COMMAND

It is used to save the copy of the output from SQL*PLUS to the file specified by
filename.

Syntax: spool filename; spool off;


VERIFY COMMAND.

It is used to control the output of the old and new lines.


Syntax: set verify on;     set verify off;


Set verify on - Displays the old and new lines.

Set verify off – Stops the displaying old and new lines.




ECHO COMMAND.

It is used to display the SQL statements while running a script file on the SQL*PLUS.
Syntax: set echo on;       set echo off;

Set echo on - Displays statement on the SQL*PLUS.

Set echo off – Stops the displaying statements on the SQL*PLUS.

PAGESIZE

Number of Lines in a Page. Maximum Page size is 50,000.


Syntax: set pagesize 50000




LINESIZE

Number of Characters in a Line. Maximum Line size is 32,767.


Syntax: set linesize 32767




VARIABLES

It is used in place of actual values in the SQL statements.It is also known as
substitutions.

Types of Variables

(i) Temporary variables.


A temporary variable is only valid for the SQL statement in which it is used and
Doesn’t persist. '&' acts as a temporary variable.



Syntax: insert into table_name values (&column_name);


(ii) Defined variables.


A defined variable persists until you explicitly remove it, redefine it, or exit

SQL*PLUS.

Syntax: define def_var = 100

Syntax: insert into table_name values (&def_var);


SUBQUERIES
A select statement can be placed with another select, update or delete statement.
The inner select statement is called as sub query.



SUBQUERY TYPES

(i) Single row subqueries:


Returns zero or one row to the outer query.

Syntax: Select column_name from table_name where column_name operator
(Select                         column_name from table_name);



(ii) Multiple row subqueries:

Returns one or more rows to the outer query.
Syntax: select column_name from table_name where column_name operator (IN,
                       ANY, ALL, NOT IN) (select column_name from
table_name);



(iii) Multiple column subqueries:

Returns more than one columns to the outer query.

Syntax: select column_name1, column_name2 from table_name where
                             (column_name1, column_name2) operator (select
column_name1, group                           function (column_name2) from
table_name group by column_name);



(iv) Correlated subqueries: Refers more than one column in the outer query.

Syntax: select column_name1, column_name2 from table_name outer where
operator (select column_name1 from table_name inner where inner.table_name =
outer.table_name);




(v) Nested subqueries:

Sub queries placed with in another queries.

Syntax: Select column_name from table_name where column_name operator
(Select column_name from table_name where column_name operator (Select
column_name from table_name));



OPERATORS USED WITH SUBQUERIES


(i) Operators used in Single row subqueries:

<,>,<>, =, <=,>=
Syntax: select column_name from table_name where column_name1 = (select
                  column_name1 from table_name where column_name =
'values');



(ii) Operators used in multiple row subqueries:

In, any, all, not in


Syntax: select column_name from table_name where column_name (IN, ANY, ALL,
            NOT IN) (select column_name from table_name);




(iii) Operators used in Correlated subqueries:


Exists, not exists, in, not in


Syntax: select column_name1, column_name2 from table_name outer where
(exists,                not exists, in, not in) (select column_name1 from
table_name inner where                inner.table_name = outer.table_name);




INLINE VIEW
Sub queries can be placed in from clause, where clause or having clause. Sub
queries placed in from clauses of the outer query is called as an inline view.

Syntax: Select column_name from (Select column_name from table_name);

More Related Content

PPT
Sql intro & ddl 1
PPT
MySql slides (ppt)
PPTX
Getting Started with MySQL I
PPT
Sql intro & ddl 1
PPTX
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
PPT
MySQL lecture
Sql intro & ddl 1
MySql slides (ppt)
Getting Started with MySQL I
Sql intro & ddl 1
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
MySQL lecture

What's hot (20)

PDF
Sql 2009
PPTX
Oracle: DDL
PDF
Sql commands
PPTX
SQL Commands
PPTX
SQL - DML and DDL Commands
PPT
SQL DDL
PPTX
SQL commands
DOC
Database queries
PPTX
Sql and Sql commands
PPTX
Difference Between Sql - MySql and Oracle
PPTX
SQL - Structured query language introduction
DOCX
PPTX
SQL for interview
DOCX
DataBase Management System Lab File
PPTX
Oracle Database DML DDL and TCL
PPTX
Getting Started with MySQL II
PPT
MySQL and its basic commands
PDF
SQL Overview
PDF
Oracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick Learning
Sql 2009
Oracle: DDL
Sql commands
SQL Commands
SQL - DML and DDL Commands
SQL DDL
SQL commands
Database queries
Sql and Sql commands
Difference Between Sql - MySql and Oracle
SQL - Structured query language introduction
SQL for interview
DataBase Management System Lab File
Oracle Database DML DDL and TCL
Getting Started with MySQL II
MySQL and its basic commands
SQL Overview
Oracle/SQL For Beginners - DDL | DML | DCL | TCL - Quick Learning
Ad

Viewers also liked (16)

DOC
11g architecture
PDF
Basic concepts for_clustered_data_ontap_8.3_v1.1-lab_guide
PDF
[OpenStack Day in Korea 2015] Track 3-1 - OpenStack Storage Infrastructure & ...
PDF
DBA oracle
DOC
netapp c-mode terms
PPTX
Oracle Database Architecture - EN
PDF
NetApp Administration and Best Practice, Brendon Higgins, Proact UK
PDF
Oracle dba-concise-handbook
PPTX
NetApp C-mode for 7 mode engineers
PPTX
DBA Commands and Concepts That Every Developer Should Know
PDF
MySQL For Oracle DBA's and Developers
PPTX
NetApp & Storage fundamentals
PPTX
Oracle Basics and Architecture
PPS
The 75 best LIFE photos
PPS
Oracle Database Overview
PPS
National Geographic 50 Best Photographs
11g architecture
Basic concepts for_clustered_data_ontap_8.3_v1.1-lab_guide
[OpenStack Day in Korea 2015] Track 3-1 - OpenStack Storage Infrastructure & ...
DBA oracle
netapp c-mode terms
Oracle Database Architecture - EN
NetApp Administration and Best Practice, Brendon Higgins, Proact UK
Oracle dba-concise-handbook
NetApp C-mode for 7 mode engineers
DBA Commands and Concepts That Every Developer Should Know
MySQL For Oracle DBA's and Developers
NetApp & Storage fundamentals
Oracle Basics and Architecture
The 75 best LIFE photos
Oracle Database Overview
National Geographic 50 Best Photographs
Ad

Similar to PT- Oracle session01 (20)

DOCX
Database Management Lab -SQL Queries
PPT
Module02
PPTX
Using Basic Structured Query Language lo1.pptx
PDF
Sql tutorial
PDF
chapter-14-sql-commands.pdf
PPT
dbs class 7.ppt
PPTX
lovely
DOC
Oracle notes
PPTX
SQL2.pptx
DOC
Sql server
PDF
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
PPTX
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
PPTX
Database COMPLETE
PPTX
SQL commands powerpoint presentation. Ppt
PPT
Sql Commands_Dr.R.Shalini.ppt
PDF
SQL Complete Tutorial. All Topics Covered
PPTX
Data base
PPT
Ms sql server architecture
DOC
Module 3
PPTX
Islamic University Previous Year Question Solution 2018 (ADBMS)
Database Management Lab -SQL Queries
Module02
Using Basic Structured Query Language lo1.pptx
Sql tutorial
chapter-14-sql-commands.pdf
dbs class 7.ppt
lovely
Oracle notes
SQL2.pptx
Sql server
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
Database COMPLETE
SQL commands powerpoint presentation. Ppt
Sql Commands_Dr.R.Shalini.ppt
SQL Complete Tutorial. All Topics Covered
Data base
Ms sql server architecture
Module 3
Islamic University Previous Year Question Solution 2018 (ADBMS)

Recently uploaded (20)

PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Classroom Observation Tools for Teachers
PDF
RMMM.pdf make it easy to upload and study
PPTX
Institutional Correction lecture only . . .
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Computing-Curriculum for Schools in Ghana
PDF
01-Introduction-to-Information-Management.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
Anesthesia in Laparoscopic Surgery in India
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
VCE English Exam - Section C Student Revision Booklet
Supply Chain Operations Speaking Notes -ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Classroom Observation Tools for Teachers
RMMM.pdf make it easy to upload and study
Institutional Correction lecture only . . .
PPH.pptx obstetrics and gynecology in nursing
Computing-Curriculum for Schools in Ghana
01-Introduction-to-Information-Management.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Microbial disease of the cardiovascular and lymphatic systems
Renaissance Architecture: A Journey from Faith to Humanism
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Microbial diseases, their pathogenesis and prophylaxis

PT- Oracle session01

  • 1. SESSION 01 TOPICS 1.Introduction Retrieving 2.Information from Database Tables 3.Simple Functions 4.Storing and Processing Dates and Times 5.SQL* Plus 6.Sub Queries DATABASE Collection of data It a structure for storing information. They are typically organized into tables, having collections of records You may think of a table as a collection of columns and rows. For example, a table named Employee might contain the EmpID, Empname, Empsalary, Empdesigination and other information about that employee. Each row is called a data record and each column is called a record field. RELATIONAL DATABASE A relational database is a database that conforms to the relational model, and refers to a database's data and schema (the database's structure of how that data is arranged).
  • 2. DBMS stands for Database Management System. It is a collection of interrelated data and a set of program to access the data. The main objective is to provide a convenient environment to retrieve and store the data from the database. RDBMS stands for Relational Database Management System. Itis a software program used to create the database and it allows you to enter, manipulate, and retrieve data RDBMS also structured in database tables, fields and records. Most RDBMS use SQL as database query language. DIFFERENCE BETWEEN DBMS and RDBMS Both are used to organize data and provide retrieval of data. DBMS permits only one person to access the database at a given time; on the other hand RDMS allows many users simultaneous access to the database. RDBMS leads DBMS in Security wise Used in large organizations to store large amount of data. It has quick retrieval mechanisms. TYPES OF RDBMS SYBASE MS SQL SERVER MYSQL Microsoft ACCESS DB2 TERADATA
  • 3. RULES FOR WRITING SQL STATEMENTS SQL statements are not case sensitive. SQL statements can be on one or more lines. Keywords cannot be abbreviated or split across lines. Clauses are usually placed on separate lines. Tabs and indents are used to enhance readability. All SQL statements must be terminated by ";" TOOLS IN ORACLE SQL*PLUS - An Interface between the database and the languages. SQL*LOADER - An Interface to load the data's from Flat files. STEPS TO WORK ON ORACLE: STEP 1 – ENTER INTO SERVER
  • 4. STEP 2 – ENTERING INTO SQL*PLUS STEP 3- ENTERING INTO OUR SCHEMA
  • 5. SQL – STRUCTURED QUERY LANGAUGE •It is used to communicate with a database. •It is a language that provides an interface to relational database systems. •It is based on the work of Dr.E.F.Codd, in his first implementation SQL was developed by IBM in the mid 1970’s. •IBM was conducting a research project known as system R, and SQL was born from that research project •Laterin 1979, a company then known as Relational Software Inc. (now called as Oracle Corporation) released the first commercial version of SQL •SQL is fully standardized by ANSI (American National Standards Institute), and it is the Standard language for relational database management systems •You can use SQL to access Oracle, SQL server, Sybase, MySQL server. DB2, ADVANTAGES OF SQL SQL provides a variety of tasks, including: •Querying data from the database •Inserting, updating, and deleting rows in a table •Creating, replacing, altering, and dropping objects •Controlling access to the database and its objects. TYPES OF SQL STATEMENTS (a)QUERY STATEMENT (b)DML (c)DDL (d)DCL (e)TCL
  • 6. (a) Query Statements Select statement. To display the contents from a table. Syntax: select column_name from table_name; Select * (view all columns) from table_name; CLAUSES IN SELECT STATEMENT (A) WHERE The WHERE clause allows you to filter the results from an SQL statement. Syntax: Select col1, col2 from tab where col1>n; (B) GROUP BY The GROUP BY clause can be used in a SELECT statement to collect data across multiple records and group the results by one or more columns. Syntax: Select col1, col2, avg (col1) from tab group by col1, col2; (C) HAVING The HAVING clause is used in combination with the GROUP BY clause. It can be used in a SELECT statement to filter the records that a GROUP BY returns.
  • 7. Syntax: Select col1, col2, avg (col1) from tab group by col1, col2 having avg (col1)>n; (D) ORDER BY The ORDER BY clause allows you to sort the records in your result set. The ORDER BY clause can only be used in SELECT statements. Syntax: Select col1, col2 from tab order by [col1/col2]; Example includes all clauses. Select col1, col2, avg (col1) from table_name where col1 >n group by col1, col2 having avg (col1)>n order by avg (col1) USING SIMPLE FUNCTIONS •SINGLE ROW FUNCTION •AGGREGATE FUNCTION SINGLE ROW FUNCTION - it takes single input and has an output for each input.
  • 8. TYPES OF SINGLE ROW FUNCTIONS CHARACTER: Takes character input and returns character or number as an output Example: select Chr (65) from dual; NUMERIC: Performs calculations and returns number as an output. Example: select mod (24, 4) from dual; DATE: To process dates and times. Example: select last_day (sysdate) from dual; CONVERSIONS: To convert one data type to another. Example: select to_char (sysdate,'month yyyy dd' ) from dual; REGULAR EXPRESSION: Allow to provide regular expression when searching data. Example: select regexp_instr ('this is a good notes for you', ' g[[ :alpha: ]] {3} ' ) from dual; AGGREGATE FUNCTIONS It can take many inputs and return single output. Example: select avg (col), sum (col), max (col) from table_name group by col; STORING AND PROCESSING DATES AND TIME * CONVERTS DATETIMES USING TO_CHAR () AND TO_DATE ().
  • 9. * DATETIME FUNCTIONS. * TIME ZONES. * TIMESTAMPS. * TIME INTERVALS. DEFAULT DATE FORMAT DD-MON-YY. Syntax: select sysdate from dual; CONVERSION FUNCTION TO_DATE (): Converts the given string to a DATE format. Syntax: select to_date ('01/jan/2009', 'dd/mon/yyyy') from dual; TO_CHAR (): Converts the datetime or number to a String format. Syntax: select to_char (to_date ('01/jan/2009', 'dd/mon/yyyy'), 'month dd, yyyy') from dual;
  • 10. DTIME FUNCTION (i) ADD_MONTHS(x, y): Returns the result of adding y months to x. If x is negative, y months are subtracted from x. Syntax: select add_months ('01-jan-2009', 3) from dual; (ii) LAST_DAY(x): Returns the last day for the month (x). Syntax: select last_day ('01-jan-2009') from dual; (iii) NEXT_DAY(x, day): Returns the datetime of the next day following (x). Syntax: select next_day ('01-jan-2009', 'Sunday') from dual; (iv) ROUND(X, [UNIT]): By default, x is rounded to the beginning of the nearest day. If you use an option UNIT string, x is rounded to that UNIT. Syntax: select round (to_date ('01-dec- 2009'), 'yyyy') from dual;
  • 11. (v) SYSDATE (): Returns the Current Date from the database. Syntax: select sysdate from dual; (vi) TRUNC(x, [UNIT]): By default, x is truncated to the beginning of the day. If you use an option UNIT string, x is truncated to that UNIT. Syntax: select trunc (to_date ('06-jun-2009'), 'yyyy') from dual; Changing the Session Time Zone: Syntax: alter session set time_zone = 'PST'; Syntax: select sessiontimezone from dual; Timestamps: * A timestamp can store a fractional second. * A timestamp can store a time zone. TIME INTERVAL: It is a data type that allows storing time intervals.
  • 12. TIME INTERVAL TYPES: (i) Interval Year to Month Type. Syntax: create table table_name (column_name INTERVAL YEAR (3) TO MONTH); (ii) Interval Day to Second Type. Syntax: create table table_name (column_name INTERVAL DAY TO SECOND (4)); SQL*PLUS COMMAND SPOOL COMMAND It is used to save the copy of the output from SQL*PLUS to the file specified by filename. Syntax: spool filename; spool off; VERIFY COMMAND. It is used to control the output of the old and new lines. Syntax: set verify on; set verify off; Set verify on - Displays the old and new lines. Set verify off – Stops the displaying old and new lines. ECHO COMMAND. It is used to display the SQL statements while running a script file on the SQL*PLUS.
  • 13. Syntax: set echo on; set echo off; Set echo on - Displays statement on the SQL*PLUS. Set echo off – Stops the displaying statements on the SQL*PLUS. PAGESIZE Number of Lines in a Page. Maximum Page size is 50,000. Syntax: set pagesize 50000 LINESIZE Number of Characters in a Line. Maximum Line size is 32,767. Syntax: set linesize 32767 VARIABLES It is used in place of actual values in the SQL statements.It is also known as substitutions. Types of Variables (i) Temporary variables. A temporary variable is only valid for the SQL statement in which it is used and
  • 14. Doesn’t persist. '&' acts as a temporary variable. Syntax: insert into table_name values (&column_name); (ii) Defined variables. A defined variable persists until you explicitly remove it, redefine it, or exit SQL*PLUS. Syntax: define def_var = 100 Syntax: insert into table_name values (&def_var); SUBQUERIES A select statement can be placed with another select, update or delete statement. The inner select statement is called as sub query. SUBQUERY TYPES (i) Single row subqueries: Returns zero or one row to the outer query. Syntax: Select column_name from table_name where column_name operator (Select column_name from table_name); (ii) Multiple row subqueries: Returns one or more rows to the outer query.
  • 15. Syntax: select column_name from table_name where column_name operator (IN, ANY, ALL, NOT IN) (select column_name from table_name); (iii) Multiple column subqueries: Returns more than one columns to the outer query. Syntax: select column_name1, column_name2 from table_name where (column_name1, column_name2) operator (select column_name1, group function (column_name2) from table_name group by column_name); (iv) Correlated subqueries: Refers more than one column in the outer query. Syntax: select column_name1, column_name2 from table_name outer where operator (select column_name1 from table_name inner where inner.table_name = outer.table_name); (v) Nested subqueries: Sub queries placed with in another queries. Syntax: Select column_name from table_name where column_name operator (Select column_name from table_name where column_name operator (Select column_name from table_name)); OPERATORS USED WITH SUBQUERIES (i) Operators used in Single row subqueries: <,>,<>, =, <=,>=
  • 16. Syntax: select column_name from table_name where column_name1 = (select column_name1 from table_name where column_name = 'values'); (ii) Operators used in multiple row subqueries: In, any, all, not in Syntax: select column_name from table_name where column_name (IN, ANY, ALL, NOT IN) (select column_name from table_name); (iii) Operators used in Correlated subqueries: Exists, not exists, in, not in Syntax: select column_name1, column_name2 from table_name outer where (exists, not exists, in, not in) (select column_name1 from table_name inner where inner.table_name = outer.table_name); INLINE VIEW Sub queries can be placed in from clause, where clause or having clause. Sub queries placed in from clauses of the outer query is called as an inline view. Syntax: Select column_name from (Select column_name from table_name);