SlideShare uma empresa Scribd logo
1 de 14
Oracle 11g - SQL
Date Document Version V 1.0
Original Date:
Last Revision Date:
Document Revision History
Date Version Section/Page Update Description Contact Name
20.06.2012 V 1.0 Initial document Prathap Narayanappa
References
Document Title Description Owner Location
Copied
Table of Contents
1. Overview………………………………………………………………………………………………………………………………….. 3
2. Oracle – SQL.…………………………………………………………………………………………………………………………….. 3
2.1 Classification of SQLStatements………………………………………………………………………………. 3
2.1.0 Data Types………………………………………………………………………………………………………………..4
VARCHAR2
NUMBER (P,S)
DATE
2.1.1 DDL Statements……………………………………………………………………………………………….. ……..5
CREATE
ALTER
DROP
TRUNCATE
See also (FLASHBACK, RENAME, PURGE, COMMENT, UNDROP, ANALYZE, AUDIT, NOAUDIT, ASSOCIATE
STATISTICS, DISASSOCIATE STATISTICS)
2.1.2 DML Statements……………………………………………………………………….. …………………………….
INSERT
UPDATE
DELETE
MERGE
See also (CALL, EXPLAIN PLAN, LOCK TABLE)
2.1.3 DRL Statements…………………………………………………………………………………………………………
SELECT
2.1.4 TCL Statements…………………………………………………………………………………………………………..
COMMIT
ROLLBACK
SAVEPOINT
SET TRANSACTION
2.1.5 DCL Statements………………………………………………………………………………………………………….
GRANT
REVOKE
2.1.6 Session ControlStatements ……………………………………………………………………………………….
ALTER SESSION
SET ROLE
2.1.7 SystemControl Statements……………………………………………………………………………………….
ALTER SYSTEM
3. Constraints………………………………………………………………………………………………………………………………….
NOT NULL
UNIQUE
PRIMARY KEY
FOREIGN KEY -ON DELETE CASCADE-ON DELETE SET NULL
CHECK
4. Joins…………………………………………………………………………………………………………………………………………….
ANSI (SQL-1999 Standards) JOINS - Types
ORACLE JOINS - Types
5. Set Operators……………………………………………………………………………………………………………………………..
UNION
UNION ALL
MINUS
INTERSECT
6. Clauses…………………………………………………………………………………………………………………………………………
GROUP BY
HAVING
WHERE
DISTINCT
ORDER BY - ASC , DESC
7. SQLExpressions and Operators……………………………………………………………………………………………………
Arithmeticoperators
Comparisonoperators
BETWEEN Operator
Logical Operators
OtherOperators
8. SQLFunctions……………………………………………………………………………………………………………………………….
Character Functions - case conversionfunctions
Character Functions - charactermanipulationfunctions
NumericFunctions
Date Functions
Aggregate Functions
General Functions
Conditional Functions
ConversionFunctions
9. Sub query, Co-Related Sub query, Exist Clause…………………………………………………………………………………
Single rowsubquery
Multiple row subquery
Correlatedsubquery
Multiple Columnsubquery
EXISTS
10. Views, Inline Views and Materialized Views………………………………………………………………………………….
Views – types -Simple Views -Complex Views
Inline View
Materialized View
11. Indexes, Synonym, Dblink, Backup Copies………………………………………………………………………………………
Indexes - types
Sequence - (nextval, currval)
Synonym - Types - Private,-Public
Dblink
Backup Copies
12. Miscellaneous Functions………………………………………………………………………………………………………………
RANK
DENSE RANK
PIVOT
IDENTITY, @@IDENTITY,SCOPE_IDENTITY, IDENT_CURRENT
CAST -(SQL 92), CONVERT
ACID PROPERTIES
ROLLUP
CUBE
COUNT_BIG
BINARY_CHECKSUM
CHECKSUM_AGG
LOCAL TEMPORARY TABLE/ GLOBAL TEMPORARY TABLE
1. Overview
This document provides simplified and detailed level of information with examples about Oracle - SQL
(including 11g new features) based on the syllabus of 11g Oracle SQL - Exam 1Z0-051.
2. Oracle and SQL
Oracle is a Database, which is developed by Oracle Corporation.
Organizations can store data on various media and in different formats, such as hard copy document in a
filing cabinet or data stored in electronic spreadsheets or in databases.
A Database is an organized collection of information.
To manage databases, you need Database Management Systems (DBMS). A DBMS is a program that stores,
retrieves and modifies data in the database on request. There arefour main types of databases: Hierarchical,
Network, Relational and Object relational (ORDBMS).
SQL
SQL (Structured Query Language) is a simple computer language used to create, access, and manipulate the
data and structure in relational Databases.
2.1 Classification of SQLStatements
DDL (Data Definition Language)
 CREATE
 ALTER
 DROP
 TRUNCATE
Refer also (FLASHBACK, RENAME, PURGE, COMMENT, UNDROP, ANALYZE, AUDIT, NOAUDIT, ASSOCIATE
STATISTICS, DISASSOCIATE STATISTICS)
DML (Data Manipulation Language)
 INSERT
 UPDATE
 DELETE
 MERGE
Refer also (CALL, EXPLAIN PLAN, LOCK TABLE)
DQL or DRL (Data Querying Language or Data Retrieval Language)
 SELECT
DCL (Data Control Language)
 GRANT
 REVOKE
TCL (Transaction Control Language)
 COMMIT
 ROLLBACK
 SAVEPOINT
 SET TRANSACTION
Session Control Statements
 ALTER SESSION
 SET ROLE
System Control Statement
 ALTER SYSTEM
2.1.0 Data types
 VARCHAR2 (length) – Alpha numeric type of data can be stored, length range 1 to 60 can be specified
 NUMBER (P,S) – Number values can be stored, Number having precision P can range1 to 38, scale S
can range -84 to 127
 DATE – Valid date range can be stored
refer also
 (NUMBER - NUMBER (p),NUMBER (S), FLOAT [(P)] )
 (DATE - TIMESTAMP[fractional_seconds_precision], INTERVAL YEAR TO MONTH, INTERVAL DAY TO
SECOND)
 (CHARACTER - CHAR, VARCHAR, VARCHAR2, LONG, NCHAR(n), NVARCHAR2(n),)
 (BINARY - RAW, LONGRAW)
 (BLOB, CLOB, NCLOB, BFILE, ROWID, UROWID(n) )
2.1.1 DDL (Data Definition Language)Statements
DDL statements areused to build and modify the structure of tables and other objects in the Database.
 CREATE – to create tables and other objects
Syntax > CREATE TABLE table_name (column_name1 data_type,column_name2 data_type,column_name3
data_type,....);
Example> CREATE TABLE EMP (EMPNO NUMBER, ENAME VARCHAR2(20), DEPTNO NUMBER, JOB
VARCHAR2(15), MGR NUMBER, HIREDATE DATE, SAL NUMBER, COMM NUMBER)
 ALTER – to alter tables and other objects
Syntax>
>ALTER TABLE EMP RENAME TO EMP_NEW; to rename table name
>ALTER TABLE EMPADD (MAILID VARCHAR2(25)); to add new column into table
>ALTER TABLE EMP DROP COLUMN MAILID; to remove existing column from table
>ALTER TABLE EMP MODIFY MAILID NUMBER; to change datatype of a column
>ALTER TABLE EMP RENAME COLUMN MAILID TO EMAILID; torename a column name
>ALTER TABLE EMP ADD PRIMARY KEY (EMPNO); to add primary key
>ALTER TABLE EMP ADD CONSTRAINT UK1_EMP UNIQUE (EMAILID); to add unique constraint
>ALTER TABLE EMP MODIFY COMM DEFAULT 10; to modify values of a column
>ALTER TABLE EMP MODIFY EMAILID VARCHAR2 (30); to increase & decrease length of a column
>ALTER TABLE EMP MODIFY SAL NOT NULL; to make a column not null constraint
>ALTER TABLE EMP DROP PRIMARY KEY; to remove primary key
>ALTER TABLE EMP READ ONLY; to make table read only access
 DROP – to delete tables and other objects
Syntax> DROP TABLE <TABLE_NAME>;
>DROP TABLE EMP;
 TRUNCATE – to delete data in a table permanently
Syntax> TRUNCATE TABLE <TABLE_NAME>;
>TRUNCATE TABLE EMP;
refer also
(FLASHBACK, RENAME, PURGE, COMMENT, UNDROP, ANALYZE, AUDIT, NOAUDIT, ASSOCIATE STATISTICS,
DISASSOCIATE STATISTICS)
2.1.2 DML (Data Manipulation Language)Statements
DML statements are used to maintain and managedata within tables.
 INSERT – to insert data into tables
Syntax> INSERT INTO table_name VALUES (value1, value2, value3,...);
> INSERT INTOtable_name (column1, column2, column3,...)VALUES (value1, value2, value3,...);
 UPDATE – to update (modify) existing data in tables
Syntax> UPDATE table_name SET column1=value, column2=value2,...WHERE some_column=some_value ;
 DELETE – to delete data from tables
Syntax> DELETE FROM table_name ;
> DELETE FROM table_name WHERE some_column=some_value ;
 MERGE – to perform insert and update in a single statement.
Syntax>
Example>
Refer also (CALL, EXPLAIN PLAN, LOCK TABLE)
The CALL and EXPLAIN PLAN statements are supported in PL/SQL only when executed dynamically. All other
DML statements are fully supported in PL/SQL.
2.1.3 DRL (Data Retrieval Language)Statement
DRL statement is used to read data from tables.
 SELECT - to retrieve data from tables
Syntax> SELECT column_name(s)FROM table_name ;
> SELECT * FROM table_name;
> SELECT * FROM EMP ;
> select * from all_objects where object_type='TABLE' ;
2.1.4 TCL (Transaction ControlLanguage)Statements
 COMMIT – saves the work done
Commit is of two types -
-Implicit Commit : This will be issued by Oracle internally, When DDL is performed.
-Explicit Commit : This will be issued by user.
 ROLLBACK - restore the database to original since the last COMMIT
Rollback will be applied in two methods -
-Upto Previous Commit
-Upto Previous Rollback
 SAVEPOINT – saves the work done up to some point. Used with Rollback.
 SET TRANSACTION -
 Locking Mechanism -
2.1.5 DCL (Data Control Language)Statements
DCL statements areused for access control in the Database.
 GRANT – gives access privileges to users for database
 REVOKE – withdraws access privileges to users for database
Use the GRANT or REVOKE statement to give privileges to a specific user or role, or to all
users, to perform actions on database objects. These privileges can be any combination of select,
insert, update, delete, references, alter, and index. Below is an explanation of what each privilege
means.
Privilege Description
Select Ability to query the table with a select statement.
Insert Ability to add new rows to the table with the insert statement.
Update Ability to update rows in the table with the update statement.
Delete Ability to delete rows from the table with the delete statement.
References Ability to create a constraint that refers to the table.
Alter Ability to change the table definition with the alter table statement.
Index Ability to create an index on the table with the create index statement.
2.1.6 Session ControlStatements
Session control statements dynamically managethe properties of a user session. These statements do not
implicitly commit the current transaction. PL/SQL does not support session control statements.
• ALTER SESSION
> alter session set current_schema = <schemaname> ;
> alter session set optimizer_mode = <mode> ;
• SET ROLE
> SET TIME ZONE
> SET SESSION AUTHORIZATION
> SET SESSION CHARACTERISTICS
2.1.7 SystemControl Statements
 ALTER SYSTEM - dynamically manages the properties of an Oracle Databaseinstance. This statement
does not implicitly commit the current transaction and is not supported in PL/SQL.
Syntax> alter system kill session 'session-id, session-serial' ;
> alter system checkpoint ;
> alter system kill session 'session-id, session-serial' ;
> Alter system archive log [start, stop, all, ...] ;
3. CONSTRAINTS
Constraintsare the rulesdefinedinoracle tablestoimplementdataintegrity.These rulescanbe
placed for each column i.e, at column level, or at the end of the column prototypingi.e, table level.
Wheneveranyactionisdone onthe table,these rules are invokedandraise exceptionupon
violation.
 NOT NULL
 UNIQUE
 PRIMARY KEY
 FOREIGN KEY
 CHECK
 NOT NULL - isusedto restrictNULL valuesina columnof a table.
 UNIQUE - Unique constraintensuresthatthe columnvaluesare distinct,withoutany duplicates.
The columnsof the table withunique constraintare calledunique key.The null able columnswith
unique constraintscancontainNULLS. Unique Constraintcanbe imposedonmultiplecolumns
also(composite uniquekey).
 PRIMARY KEY - ishybrid constraintevolvedfromfunctionalcombinationof NOTNULLandUNIQUE
constraints.The columnsof the table enforcedunderprimarykeyare restrictedfromNULLSand
Duplicate values.
FewkeypointsonPrimaryKey
-A Table can have onlyone primarykey
-Multiple columnscanbe clubbedundercomposite primarykey
-Oracle internallycreatesuniqueindex topreventduplicationinthe columnvalues
 FOREIGN KEY - If primarykeyof one table takespart in anothertable thenitiscalled foreign key,
the table withprimarykeyiscalledparenttable andtable withforeignkeyiscalledchildtable.
-ON DELETE CASCADE
-ON DELETE SET NULL
 CHECK - usedtolimitthe value range thatcan be placedina column.
4. Joins
 ANSISQL-1999 Standards
JOINS–types
1) Natural Join
-joinwithUSINGclause
-joinwithON clause
2) OuterJoin
-Leftouterjoin
-RightOuterJoin
-Full OuterJoin
3) Cross Join
 ORACLE JOINS
JOINS– types
1) InnerJoin(simple join),
-Equi Join
-NonEqui Join
-Self Join
2) OuterJoin
-LeftOuterJoin
-RightOuterJoin
-Full OuterJoin
3) CartesianProduct
5. SetOperators
 UNION
 UNION ALL
 MINUS
 INTERSECT
6. Clauses
 GROUP BY
 HAVING
 WHERE
 DISTINCT
 ORDER BY - ASC , DESC
7. SQL Expressionsand Operators
 Arithmeticoperators[ +, -, *, /, (),]
 Comparisonoperators(single rowandmultiple row operators)
-Equality( = )
-Inequalityoperator( >,< )
-Composite inequalityoperator( <=, >= )
 BETWEEN Operator( BETWEEN expression1ANDexpression2)
 Logical Operators (AND,OR,NOT)
 IN,NOT IN
 EXIST,NOT EXIST
 LIKE
 ESCAPEIdentifier
 IS NULL
 IS NOTNULL
 StringConcatenationoperators
 Literals
 Quote Operator(from10g onwards)
 NULL
 DESCRIBE
 Escape Identifier
 SubstitutionVariables( &), Double ampersandSubstitutionVariables( &&)
 Define andVerifyCommands
8. SQL Functions- (single row functions, multiple row functions)
-CharacterFunctions - case conversionfunctions
 INITCAP
 UPPER
 LOWER
-CharacterFunctions - character manipulationfunctions
 CONCAT
 LENGTH
 Padding(LPAD,RPAD)
 TRIM (RTRIM,LTRIM)
 INSTR
 SUBSTR
 REPLACE
-NumericFunctions
 ROUND
 TRUNC
 MOD
-Date Functions
 MONTHS_BETWEEN
 ADD_MONTHS
 NEXT_DAY
 LAST_DAY
 ROUND (DATE,format)
 TRUNC (DATE,format)
 GETDATE
 DATEDIFF
 DATEPART
 DATEADD
-Aggregate Functions
 COUNT
 SUM
 MAX
 MIN
 AVG
-General Functions
 NVL
 NVL2
 COALESCE
 ALIAS
 ROWNUM
 ROWID
-ConditionalFunctions
 DECODE
 CASE
-ConversionFunctions
 TO_CHAR - isusedto typecasta numericor date inputto character type
 TO_DATE - it takescharacter or numbervaluesandreturnsformatteddate equivalentof the same
 TO_NAUBER - thisfunctiontakescharacterinputsandreturnsnumberoutputaftersuitable
formatting
9. Sub Query,Co-relatedSub Queryand ExistClause
 Single rowsubquery
 Multiple rowsubquery
 Correlatedsubquery
 Multiple Columnsubquery
 EXISTS- thisoperatortestsfor existenceof rowsinthe resultsetof the sub query.
Syntax>
> SELECT DNAME FROM DEPT WHERE EXISTS(SELECT DEPT.DEPTNO= EMP.DEPTNO) ;
10. Views, Inline Views and Materialized Views
 Views - types
 Simple Views
 Complex Views
 Inline View-
 Materialized View-
11. Indexes, Synonym, Dblink, Backup Copies
 Indexes - types
-Unique Index
-Non-Unique Index
-Btree Index
-Bitmap Index
-Composite Index
-Function-based Index
-Cluster Index
 Sequence - (nextval, currval)
 Synonym -
Types -
-Private
-Public
 Dblink - to access tables or views or sequence from one database to another database.
Syntax>
Example> CREATE DATABASE LINK CAASEDW CONNECT TO ITO_ASA IDENTIFIED BY exact123 USING
'CAASEDW'
SQL> SELECT * FROM EMP@ CAASEDW ;
 Backup Copies -
12. Miscellaneous Functions & Terms
 RANK
 DENSE RANK
 PIVOT
 IDENTITY, @@IDENTITY,SCOPE_IDENTITY, IDENT_CURRENT
 CAST -(SQL 92), CONVERT
 ACID PROPERTIES
 ROLLUP
 CUBE
 COUNT_BIG
 BINARY_CHECKSUM
 CHECKSUM_AGG
 LOCAL TEMPORARY TABLE/ GLOBAL TEMPORARY TABLE
########################## SQL END ###########################

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Sql and Sql commands
Sql and Sql commandsSql and Sql commands
Sql and Sql commands
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
Introduction to mysql part 1
Introduction to mysql part 1Introduction to mysql part 1
Introduction to mysql part 1
 
SQL commands
SQL commandsSQL commands
SQL commands
 
Mysql
MysqlMysql
Mysql
 
Sql 2009
Sql 2009Sql 2009
Sql 2009
 
Sql
SqlSql
Sql
 
Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL
 
SQL
SQLSQL
SQL
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 
Sql commands
Sql commandsSql commands
Sql commands
 
Adbms
AdbmsAdbms
Adbms
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
Assignment#02
Assignment#02Assignment#02
Assignment#02
 
SQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate TableSQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate Table
 
Sql commands
Sql commandsSql commands
Sql commands
 
Assignment#07
Assignment#07Assignment#07
Assignment#07
 
8. sql
8. sql8. sql
8. sql
 

Semelhante a Oracle 11g SQL Overview

My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
EliasPetros
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 

Semelhante a Oracle 11g SQL Overview (20)

lovely
lovelylovely
lovely
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
 
SQL2.pptx
SQL2.pptxSQL2.pptx
SQL2.pptx
 
Sql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.pptSql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.ppt
 
Group Members
Group MembersGroup Members
Group Members
 
Database Management System (DBMS).pptx
Database Management System (DBMS).pptxDatabase Management System (DBMS).pptx
Database Management System (DBMS).pptx
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
 
Assignment#01
Assignment#01Assignment#01
Assignment#01
 
Bank mangement system
Bank mangement systemBank mangement system
Bank mangement system
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
 
PO WER - Piotr Mariat - Sql
PO WER - Piotr Mariat - SqlPO WER - Piotr Mariat - Sql
PO WER - Piotr Mariat - Sql
 
SQL_NOTES.pdf
SQL_NOTES.pdfSQL_NOTES.pdf
SQL_NOTES.pdf
 
SQL Query
SQL QuerySQL Query
SQL Query
 
COMPUTERS SQL
COMPUTERS SQL COMPUTERS SQL
COMPUTERS SQL
 
Sql queries
Sql queriesSql queries
Sql queries
 
Mysql Ppt
Mysql PptMysql Ppt
Mysql Ppt
 
BASIC_OF_DATABASE_PPT__new[1].pptx
BASIC_OF_DATABASE_PPT__new[1].pptxBASIC_OF_DATABASE_PPT__new[1].pptx
BASIC_OF_DATABASE_PPT__new[1].pptx
 
Database Management Lab -SQL Queries
Database Management Lab -SQL Queries Database Management Lab -SQL Queries
Database Management Lab -SQL Queries
 
Database models and DBMS languages
Database models and DBMS languagesDatabase models and DBMS languages
Database models and DBMS languages
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Último (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Oracle 11g SQL Overview

  • 1. Oracle 11g - SQL Date Document Version V 1.0 Original Date: Last Revision Date: Document Revision History Date Version Section/Page Update Description Contact Name 20.06.2012 V 1.0 Initial document Prathap Narayanappa References Document Title Description Owner Location Copied
  • 2. Table of Contents 1. Overview………………………………………………………………………………………………………………………………….. 3 2. Oracle – SQL.…………………………………………………………………………………………………………………………….. 3 2.1 Classification of SQLStatements………………………………………………………………………………. 3 2.1.0 Data Types………………………………………………………………………………………………………………..4 VARCHAR2 NUMBER (P,S) DATE 2.1.1 DDL Statements……………………………………………………………………………………………….. ……..5 CREATE ALTER DROP TRUNCATE See also (FLASHBACK, RENAME, PURGE, COMMENT, UNDROP, ANALYZE, AUDIT, NOAUDIT, ASSOCIATE STATISTICS, DISASSOCIATE STATISTICS) 2.1.2 DML Statements……………………………………………………………………….. ……………………………. INSERT UPDATE DELETE MERGE See also (CALL, EXPLAIN PLAN, LOCK TABLE) 2.1.3 DRL Statements………………………………………………………………………………………………………… SELECT 2.1.4 TCL Statements………………………………………………………………………………………………………….. COMMIT ROLLBACK SAVEPOINT SET TRANSACTION 2.1.5 DCL Statements…………………………………………………………………………………………………………. GRANT REVOKE 2.1.6 Session ControlStatements ………………………………………………………………………………………. ALTER SESSION SET ROLE 2.1.7 SystemControl Statements………………………………………………………………………………………. ALTER SYSTEM 3. Constraints…………………………………………………………………………………………………………………………………. NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY -ON DELETE CASCADE-ON DELETE SET NULL CHECK 4. Joins……………………………………………………………………………………………………………………………………………. ANSI (SQL-1999 Standards) JOINS - Types ORACLE JOINS - Types 5. Set Operators…………………………………………………………………………………………………………………………….. UNION UNION ALL MINUS
  • 3. INTERSECT 6. Clauses………………………………………………………………………………………………………………………………………… GROUP BY HAVING WHERE DISTINCT ORDER BY - ASC , DESC 7. SQLExpressions and Operators…………………………………………………………………………………………………… Arithmeticoperators Comparisonoperators BETWEEN Operator Logical Operators OtherOperators 8. SQLFunctions………………………………………………………………………………………………………………………………. Character Functions - case conversionfunctions Character Functions - charactermanipulationfunctions NumericFunctions Date Functions Aggregate Functions General Functions Conditional Functions ConversionFunctions 9. Sub query, Co-Related Sub query, Exist Clause………………………………………………………………………………… Single rowsubquery Multiple row subquery Correlatedsubquery Multiple Columnsubquery EXISTS 10. Views, Inline Views and Materialized Views…………………………………………………………………………………. Views – types -Simple Views -Complex Views Inline View Materialized View 11. Indexes, Synonym, Dblink, Backup Copies……………………………………………………………………………………… Indexes - types Sequence - (nextval, currval) Synonym - Types - Private,-Public Dblink Backup Copies 12. Miscellaneous Functions……………………………………………………………………………………………………………… RANK DENSE RANK PIVOT IDENTITY, @@IDENTITY,SCOPE_IDENTITY, IDENT_CURRENT CAST -(SQL 92), CONVERT ACID PROPERTIES ROLLUP CUBE COUNT_BIG BINARY_CHECKSUM
  • 4. CHECKSUM_AGG LOCAL TEMPORARY TABLE/ GLOBAL TEMPORARY TABLE 1. Overview This document provides simplified and detailed level of information with examples about Oracle - SQL (including 11g new features) based on the syllabus of 11g Oracle SQL - Exam 1Z0-051. 2. Oracle and SQL Oracle is a Database, which is developed by Oracle Corporation. Organizations can store data on various media and in different formats, such as hard copy document in a filing cabinet or data stored in electronic spreadsheets or in databases. A Database is an organized collection of information. To manage databases, you need Database Management Systems (DBMS). A DBMS is a program that stores, retrieves and modifies data in the database on request. There arefour main types of databases: Hierarchical, Network, Relational and Object relational (ORDBMS). SQL SQL (Structured Query Language) is a simple computer language used to create, access, and manipulate the data and structure in relational Databases. 2.1 Classification of SQLStatements DDL (Data Definition Language)  CREATE  ALTER  DROP  TRUNCATE Refer also (FLASHBACK, RENAME, PURGE, COMMENT, UNDROP, ANALYZE, AUDIT, NOAUDIT, ASSOCIATE STATISTICS, DISASSOCIATE STATISTICS) DML (Data Manipulation Language)  INSERT  UPDATE  DELETE  MERGE
  • 5. Refer also (CALL, EXPLAIN PLAN, LOCK TABLE) DQL or DRL (Data Querying Language or Data Retrieval Language)  SELECT DCL (Data Control Language)  GRANT  REVOKE TCL (Transaction Control Language)  COMMIT  ROLLBACK  SAVEPOINT  SET TRANSACTION Session Control Statements  ALTER SESSION  SET ROLE System Control Statement  ALTER SYSTEM 2.1.0 Data types  VARCHAR2 (length) – Alpha numeric type of data can be stored, length range 1 to 60 can be specified  NUMBER (P,S) – Number values can be stored, Number having precision P can range1 to 38, scale S can range -84 to 127  DATE – Valid date range can be stored refer also  (NUMBER - NUMBER (p),NUMBER (S), FLOAT [(P)] )  (DATE - TIMESTAMP[fractional_seconds_precision], INTERVAL YEAR TO MONTH, INTERVAL DAY TO SECOND)  (CHARACTER - CHAR, VARCHAR, VARCHAR2, LONG, NCHAR(n), NVARCHAR2(n),)  (BINARY - RAW, LONGRAW)  (BLOB, CLOB, NCLOB, BFILE, ROWID, UROWID(n) ) 2.1.1 DDL (Data Definition Language)Statements DDL statements areused to build and modify the structure of tables and other objects in the Database.
  • 6.  CREATE – to create tables and other objects Syntax > CREATE TABLE table_name (column_name1 data_type,column_name2 data_type,column_name3 data_type,....); Example> CREATE TABLE EMP (EMPNO NUMBER, ENAME VARCHAR2(20), DEPTNO NUMBER, JOB VARCHAR2(15), MGR NUMBER, HIREDATE DATE, SAL NUMBER, COMM NUMBER)  ALTER – to alter tables and other objects Syntax> >ALTER TABLE EMP RENAME TO EMP_NEW; to rename table name >ALTER TABLE EMPADD (MAILID VARCHAR2(25)); to add new column into table >ALTER TABLE EMP DROP COLUMN MAILID; to remove existing column from table >ALTER TABLE EMP MODIFY MAILID NUMBER; to change datatype of a column >ALTER TABLE EMP RENAME COLUMN MAILID TO EMAILID; torename a column name >ALTER TABLE EMP ADD PRIMARY KEY (EMPNO); to add primary key >ALTER TABLE EMP ADD CONSTRAINT UK1_EMP UNIQUE (EMAILID); to add unique constraint >ALTER TABLE EMP MODIFY COMM DEFAULT 10; to modify values of a column >ALTER TABLE EMP MODIFY EMAILID VARCHAR2 (30); to increase & decrease length of a column >ALTER TABLE EMP MODIFY SAL NOT NULL; to make a column not null constraint >ALTER TABLE EMP DROP PRIMARY KEY; to remove primary key >ALTER TABLE EMP READ ONLY; to make table read only access  DROP – to delete tables and other objects Syntax> DROP TABLE <TABLE_NAME>; >DROP TABLE EMP;  TRUNCATE – to delete data in a table permanently Syntax> TRUNCATE TABLE <TABLE_NAME>; >TRUNCATE TABLE EMP; refer also (FLASHBACK, RENAME, PURGE, COMMENT, UNDROP, ANALYZE, AUDIT, NOAUDIT, ASSOCIATE STATISTICS, DISASSOCIATE STATISTICS) 2.1.2 DML (Data Manipulation Language)Statements DML statements are used to maintain and managedata within tables.  INSERT – to insert data into tables Syntax> INSERT INTO table_name VALUES (value1, value2, value3,...); > INSERT INTOtable_name (column1, column2, column3,...)VALUES (value1, value2, value3,...);
  • 7.  UPDATE – to update (modify) existing data in tables Syntax> UPDATE table_name SET column1=value, column2=value2,...WHERE some_column=some_value ;  DELETE – to delete data from tables Syntax> DELETE FROM table_name ; > DELETE FROM table_name WHERE some_column=some_value ;  MERGE – to perform insert and update in a single statement. Syntax> Example> Refer also (CALL, EXPLAIN PLAN, LOCK TABLE) The CALL and EXPLAIN PLAN statements are supported in PL/SQL only when executed dynamically. All other DML statements are fully supported in PL/SQL. 2.1.3 DRL (Data Retrieval Language)Statement DRL statement is used to read data from tables.  SELECT - to retrieve data from tables Syntax> SELECT column_name(s)FROM table_name ; > SELECT * FROM table_name; > SELECT * FROM EMP ; > select * from all_objects where object_type='TABLE' ; 2.1.4 TCL (Transaction ControlLanguage)Statements  COMMIT – saves the work done Commit is of two types - -Implicit Commit : This will be issued by Oracle internally, When DDL is performed. -Explicit Commit : This will be issued by user.  ROLLBACK - restore the database to original since the last COMMIT Rollback will be applied in two methods - -Upto Previous Commit -Upto Previous Rollback  SAVEPOINT – saves the work done up to some point. Used with Rollback.  SET TRANSACTION -  Locking Mechanism -
  • 8. 2.1.5 DCL (Data Control Language)Statements DCL statements areused for access control in the Database.  GRANT – gives access privileges to users for database  REVOKE – withdraws access privileges to users for database Use the GRANT or REVOKE statement to give privileges to a specific user or role, or to all users, to perform actions on database objects. These privileges can be any combination of select, insert, update, delete, references, alter, and index. Below is an explanation of what each privilege means. Privilege Description Select Ability to query the table with a select statement. Insert Ability to add new rows to the table with the insert statement. Update Ability to update rows in the table with the update statement. Delete Ability to delete rows from the table with the delete statement. References Ability to create a constraint that refers to the table. Alter Ability to change the table definition with the alter table statement. Index Ability to create an index on the table with the create index statement. 2.1.6 Session ControlStatements Session control statements dynamically managethe properties of a user session. These statements do not implicitly commit the current transaction. PL/SQL does not support session control statements. • ALTER SESSION > alter session set current_schema = <schemaname> ; > alter session set optimizer_mode = <mode> ; • SET ROLE > SET TIME ZONE > SET SESSION AUTHORIZATION > SET SESSION CHARACTERISTICS 2.1.7 SystemControl Statements  ALTER SYSTEM - dynamically manages the properties of an Oracle Databaseinstance. This statement does not implicitly commit the current transaction and is not supported in PL/SQL. Syntax> alter system kill session 'session-id, session-serial' ; > alter system checkpoint ; > alter system kill session 'session-id, session-serial' ; > Alter system archive log [start, stop, all, ...] ;
  • 9. 3. CONSTRAINTS Constraintsare the rulesdefinedinoracle tablestoimplementdataintegrity.These rulescanbe placed for each column i.e, at column level, or at the end of the column prototypingi.e, table level. Wheneveranyactionisdone onthe table,these rules are invokedandraise exceptionupon violation.  NOT NULL  UNIQUE  PRIMARY KEY  FOREIGN KEY  CHECK  NOT NULL - isusedto restrictNULL valuesina columnof a table.  UNIQUE - Unique constraintensuresthatthe columnvaluesare distinct,withoutany duplicates. The columnsof the table withunique constraintare calledunique key.The null able columnswith unique constraintscancontainNULLS. Unique Constraintcanbe imposedonmultiplecolumns also(composite uniquekey).  PRIMARY KEY - ishybrid constraintevolvedfromfunctionalcombinationof NOTNULLandUNIQUE constraints.The columnsof the table enforcedunderprimarykeyare restrictedfromNULLSand Duplicate values. FewkeypointsonPrimaryKey -A Table can have onlyone primarykey -Multiple columnscanbe clubbedundercomposite primarykey -Oracle internallycreatesuniqueindex topreventduplicationinthe columnvalues  FOREIGN KEY - If primarykeyof one table takespart in anothertable thenitiscalled foreign key, the table withprimarykeyiscalledparenttable andtable withforeignkeyiscalledchildtable. -ON DELETE CASCADE -ON DELETE SET NULL  CHECK - usedtolimitthe value range thatcan be placedina column. 4. Joins  ANSISQL-1999 Standards JOINS–types
  • 10. 1) Natural Join -joinwithUSINGclause -joinwithON clause 2) OuterJoin -Leftouterjoin -RightOuterJoin -Full OuterJoin 3) Cross Join  ORACLE JOINS JOINS– types 1) InnerJoin(simple join), -Equi Join -NonEqui Join -Self Join 2) OuterJoin -LeftOuterJoin -RightOuterJoin -Full OuterJoin 3) CartesianProduct 5. SetOperators  UNION  UNION ALL  MINUS  INTERSECT 6. Clauses  GROUP BY  HAVING
  • 11.  WHERE  DISTINCT  ORDER BY - ASC , DESC 7. SQL Expressionsand Operators  Arithmeticoperators[ +, -, *, /, (),]  Comparisonoperators(single rowandmultiple row operators) -Equality( = ) -Inequalityoperator( >,< ) -Composite inequalityoperator( <=, >= )  BETWEEN Operator( BETWEEN expression1ANDexpression2)  Logical Operators (AND,OR,NOT)  IN,NOT IN  EXIST,NOT EXIST  LIKE  ESCAPEIdentifier  IS NULL  IS NOTNULL  StringConcatenationoperators  Literals  Quote Operator(from10g onwards)  NULL  DESCRIBE  Escape Identifier  SubstitutionVariables( &), Double ampersandSubstitutionVariables( &&)  Define andVerifyCommands 8. SQL Functions- (single row functions, multiple row functions) -CharacterFunctions - case conversionfunctions  INITCAP  UPPER  LOWER
  • 12. -CharacterFunctions - character manipulationfunctions  CONCAT  LENGTH  Padding(LPAD,RPAD)  TRIM (RTRIM,LTRIM)  INSTR  SUBSTR  REPLACE -NumericFunctions  ROUND  TRUNC  MOD -Date Functions  MONTHS_BETWEEN  ADD_MONTHS  NEXT_DAY  LAST_DAY  ROUND (DATE,format)  TRUNC (DATE,format)  GETDATE  DATEDIFF  DATEPART  DATEADD -Aggregate Functions  COUNT  SUM  MAX  MIN  AVG -General Functions  NVL  NVL2  COALESCE  ALIAS  ROWNUM  ROWID -ConditionalFunctions  DECODE  CASE -ConversionFunctions  TO_CHAR - isusedto typecasta numericor date inputto character type  TO_DATE - it takescharacter or numbervaluesandreturnsformatteddate equivalentof the same
  • 13.  TO_NAUBER - thisfunctiontakescharacterinputsandreturnsnumberoutputaftersuitable formatting 9. Sub Query,Co-relatedSub Queryand ExistClause  Single rowsubquery  Multiple rowsubquery  Correlatedsubquery  Multiple Columnsubquery  EXISTS- thisoperatortestsfor existenceof rowsinthe resultsetof the sub query. Syntax> > SELECT DNAME FROM DEPT WHERE EXISTS(SELECT DEPT.DEPTNO= EMP.DEPTNO) ; 10. Views, Inline Views and Materialized Views  Views - types  Simple Views  Complex Views  Inline View-  Materialized View- 11. Indexes, Synonym, Dblink, Backup Copies  Indexes - types -Unique Index -Non-Unique Index -Btree Index -Bitmap Index -Composite Index -Function-based Index -Cluster Index  Sequence - (nextval, currval)  Synonym -
  • 14. Types - -Private -Public  Dblink - to access tables or views or sequence from one database to another database. Syntax> Example> CREATE DATABASE LINK CAASEDW CONNECT TO ITO_ASA IDENTIFIED BY exact123 USING 'CAASEDW' SQL> SELECT * FROM EMP@ CAASEDW ;  Backup Copies - 12. Miscellaneous Functions & Terms  RANK  DENSE RANK  PIVOT  IDENTITY, @@IDENTITY,SCOPE_IDENTITY, IDENT_CURRENT  CAST -(SQL 92), CONVERT  ACID PROPERTIES  ROLLUP  CUBE  COUNT_BIG  BINARY_CHECKSUM  CHECKSUM_AGG  LOCAL TEMPORARY TABLE/ GLOBAL TEMPORARY TABLE ########################## SQL END ###########################