Maa Corporate Training Center: Given by Mr. Loknadh
Maa Corporate Training Center: Given by Mr. Loknadh
1. SQL Fundamentals
SQL is the basic Language used for retrieve and manipulate data from database.
SQL is non procedural Language , does not contains Programming constructs like Loops.
ANSI has standards for SQL , Oracle Supports there standards of SQL and extended its SQL to
support it.
Used to access, create, modify, or delete data in the existing structures of the database.
Statements Include:
INSERT,INSERT,UPDATE,DELETE,MERGE
Statements Include :
3. Transaction Control
COMMIT,ROLLBACK,SAVEPOINT,SET TRANSACTION
4. Session Control
5. System Control
ALTER SYSTEM
Oracle rounds the values in the scale part is smaller than inserted number.
Date : 7 Bytes
Occupies 7-Bytes
Century:Year:Month:Day:Hour:Minute:Second
+ - (Unary)
+, - ,* /
Precedence
2 */ Multiplication, division
‘’ ||’’
SET Operators
Literals :
SELECT Statement
Column Alias
DISTINCT /UNIQUE
DUAL Table
Limiting Rows
Comparison Operators
Logical Operators
NOT
TRUE FALSE
FALSE TRUE
NULL NULL
Examples :
Sorting Rows
NULLS FIRST/LAST
CASE Statement
2. SQL*Plus Overview
SQL*Plus is widely used tool by DBAs and Developers to access database.
Sqlplus username/password@connectstring
SQL>DISCONNECT
DEFINE _EDITOR=vi
SQL>I
7777 AND
EMP_NO=110
SQL> 3
SQL>CLEAR SCREEN
SPOOL filename
Comments
/* */ Single/Multiline Comments
Important Variables
SET LINESIZE
SET TIME ON
Formatting output
3. Functions
Functions are programs that take zero or more arguments and returns a single value
Types of Functions:
Group Functions
Analytics Functions
Single row Functions can be incorporated into SELECT, WHERE, ORDER BY Clauses
NVL , NVL2
INSTR(<c1>,<c2>[,<i>[,<j>]])
I : Starting Position
J : J th Occurance
LENGTH
LOWER
UPPER
LTRIM
RTRIM
LPAD
RPAD
REPLACE
SUBSTR
CEIL
FLOOR
ROUND
SELECT ROUND(12345,-2) test1 ,ROUND(12345.54321,2) test2 FROM dual;
SIGN
SELECT SIGN(-2.3) ,SIGN(0) ,SIGN(47) FROM dual;
Date Functions
ADD_MONTHS
CURRENT_DATE
CURRENT_TIMESTAMP
DBTIMEZONE
LAST_DAY
MONTHS_BETWEEN
NEXT_DAY
ROUND
SELECT SYSDATE,ROUND(SYSDATE,'HH24') FROM dual;
TRUNC
SELECT TRUNC(last_analyzed,'HH') FROM user_tables
WHERE table_name='TEST_CASE';
SYSTEMTIMESTAMP/SYSDATE
Conversion Functions
TO_CHAR(<x>,[,<frmt>])
SELECT SYSDATE
,TO_CHAR(SYSDATE,'Mmspth') Month
,TO_CHAR(SYSDATE,'DDth') Day
,TO_CHAR(SYSDATE,'Yyyysp') Year
FROM dual;
Other Functions
DECODE
GREATEST
LEAST
SELECT LEAST(SYSDATE,'15-MAR-2002','17-JUN-2002') oldest
FROM dual;
NULLIF(x1,x2)
Returns NULL if x1=x2 otherwise returns x1;
Group Functions
COUNT
SUM
SELECT SUM(blocks)
FROM user_tables;
GROUP BY
HAVING