Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
6Activity
0 of .
Results for:
No results containing your search query
P. 1
Oracle9i Introduction to 9i SQL Handbook

Oracle9i Introduction to 9i SQL Handbook

Ratings:

5.0

(1)
|Views: 1,282|Likes:
Published by emailtorakesh

More info:

Categories:Types, School Work
Published by: emailtorakesh on Aug 08, 2008
Copyright:Traditional Copyright: All rights reserved

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

12/12/2012

pdf

text

original

 
Introduction to 9i SQL Handbook 
Oracle server supports
 ANSI standard SQL and contains extensions
SQL used to communicate server to access, manipulate and control data
SQL
SELECT STATEMENT
CAPABILITIES:
PROJECTION, SELECTION, JOINING
SELECT* from orders; Use this statement to retrieve data from a data table for
 Viewing/Inserting
KEYWORD USED IN UPPERCASE NO USE OF ABBREVIATION OR SPILT ACROSS LINES
CLAUSE SEPARATE LINE
SQL STATEMENT USED BY 1 OR NORE LINE NOT CASE SENSETIVE UNLESS INDICATED
INDENTS USED TO MAKE CODE MORE RELIABLE
 ARTIHMETIC EXPRESSIONS/OPERATORBY PRECEDENCE * / + -
DATE & CHARACTER LITERAL IN
 ‘
02-12-2006
’ single quotes
DISTINCT TO ELIMINATE DUPLICATE ROWS
SQL*Plus command
s are used to manipulate data in tables, to manipulate table definitions in the database.
ISQL*PLUS ORACLE TOOL
DESCRIBE
Isql*plus command
WHERE
CONDITION TO
LIMITING ROWS/SORTING ROWS/restrict ROWS
SQL*Plus feature used to replace values in WHERE clause? Ans.Substitution variables
COMPARISON CONDITIONS
1.EQUAL TO =2.GREATER THAN >3.GREATER THAN EQUAL TO >=4.LESS THAN <5.LESS THAN EQUAL TO <=6.NOT EQUAL TO <> / ^= / !=7.BETWEEN A AND B ONLY 2 VALUES8.IN (SET) LIST OF VALUES9.LIKE A CHARACTER PATTERN10.IS NULL
WILDCARD SEARCH
% DENOTES 0 OR MANY CHARACTER |
 _ DENOTES
1 CHARACTER [underscore] \_P%ESCAPE \[HERE ESCAPE CHARACTE
\
]LOGICAL CONDITION1.AND2.O3.NOTPRECEDENCE OF OPERATOR 1.Arithmetic2.Concatenation3.Comparison Cond.4.Is [not] null, like, [not] in5.[Not] between6.NOT LOGICAL CONDITION7.AND LOGICAL CONDITION8.OR LOGICAL CONDITIONOrder by [asc] desc to sort rows in select statement/multiple columns/column also not in select [column list]Sort by column/column alias/column number.True regarding the ORDER BY clause?
The sort is in ascending by order by default, executes at last after WHERE and GROUP BY clause
The ORDER BY clause comes last in SELECT statement, executes on server side as whole SQLstatementDUAL IS A DUMMY TABLE
Functions
Calculations on data
Modify individual data item
Manipulate o/p for group of rows
Format date and no to display
- 1 -
 
Introduction to 9i SQL Handbook 
Convert column data type
 Always return values
Single Row Functions
return one value
act on each row returned
return one result per row
can be nested
arguments- columns or expressions
 A single row subquery can retrieve only one row but many columns. 
 A single row subquery can retrieve data from more than one table. 
SINGLE ROW FUNCTION NESTED TO ANY DEPTH Argument
User supplied constant
 Variable value
Column name
Expression
1.
Character Function
a.Case ManipulationLower Upper initcapb.Character ManipulationConcatSUBSTR LENGTH INSTR LPAD | RPAD TRIM REPLACE
2.
Number Function
ROUNDTRUNCMOD
3.
Date Function
Sysdate RETURNS CURRENT
DATABASE SERVER DATE AND TIME
INTERNAL NUMERIC FORMAT 7 BYTES
CENTURY YEAR MONTH DAY HOURS MINUTES SECONDS
 VALID DATE BETWEEN January 1,4712 B.C. TO December 31,9999 A.D.
DEFAULT DATE FORMAT DD-MON-RR01-JUL-06
DATE + OR – NUMBER = DATE
DATE – DATE = DAYS
DATE+NUMBER/24 = DATEa.MONTHS_BETWEENb.ADD_MONTHSc.NEXT_DAd.LAST_DAe.ROUNDf.TRUNC
4.
Conversion DATA TYPE Function
a.
IMPLICIT Function
i.
 VARCHAR2 OR CHAR TO NUMBER TO_NUMBER 
ii.
 VARCHAR2 OR CHAR TO DATE TO_DATE
iii.
NUMBER TO VARCHAR2 TO_CHAR 
iv.
DATE TO VARCHAR2 TO_CHAR FORMAT MODELTO_CHAR(DATE,’FORMAT MODEL’)TO_NUMBER(CHAR[, ‘FORMAT MODEL’])TO_NUMBER(‘12345.52’,’$999999.99’)TO_DATE(CHAR[, ‘FORMAT MODEL’])fx FOR EXACT MATCHTO_DATE(‘MAY 24, 2006’,’MONTH DD,YYYY’)TO_CHAR(NUMBER,’FORMAT MODEL’)9 0 $ L . , MI PR EEEE V Bb.EXPLICIT
5.
General Function
a.
NVL(EX1,EX2) EX1 NULL PUT/RETURN EX2
- 2 -
 
Introduction to 9i SQL Handbook 
b.NVL2(EX1,EX2,EX3) EX1 NOT NULL RETURN EX2EX1 NULL RETURN EX3c.NULLIF(EX1,EX2) EX1 = EX2 RETURN NULL ELSE RETURN EX1d.COALESCE(EX1,EX2,…EXn) EX1 NULL RETURN EX2 EX1,EX2 NULL RETURN EX3
SELECT COALESCE (COMM_PCT,SALARY,10) COMMISSION FROM EMP; 
CASE
COL/EXP WHEN IF_EXP THEN RETURN_EXPELSE ELSE_EXPEND ALIAS_NAME
DECODE
(COL/EXP,SEARCH1,RESULT1,SEARCH2,RESULT2,DEFAULT_RESULT) ALIAS_NAME
Use: Select /where/order by with case and decodeMultiple Row Functions
 A multiple row subquery can retrieve multiple rows and multiple columns. 
 A multiple row subquery can be compared by using the “>” operator (only case of 
all/any
 
 
). 
The multiple-row subquery cannot be used with the comparison operator
 A multiple-row subquery cannot be used in an INSERT statement to insert multiple rows at a time. 
Group / AGGREGATE functions:
SET OF ROWS ONE RESULT PER GROUP,
IGNORE NULL VALUES
 AUTOMATICALLY SORT RESULT IN ASCENDING ORDER 
Mix single row columns with aggregate functions in the column list of a SELECTstatement by grouping on the single row columns.
Pass column names, expressions, constants, or functions as parameters to an aggregatefunction.
 AVG NUMBER 
COUNT (*)/(EXPR)/(DISTINCT expr) (*) number of rows including duplicate rows
[DATE]
MAX NUMBER 
[DATE]
MIN NUMBER 
[DATE]
STDDEV NUMBER 
SUM NUMBER 
 VARIANCE NUMBER 
Format of using Group FunctionSelect / From / Where / [Having] Group by/Having /Order by;Group by
Divide/spilt table info in groups
Grouping can be more than 1 column
Mix of individual item and group function must use a group by clause
Without group function can use a group by clause
Can use nesting group functions
Include columns in group by clause
If column not in select list still apply group by on this column
Using where exclude rows before divide into groups
Can’t use alias
 AUTOMATICALLY SORT RESULT IN ASCENDING ORDER 
To
restrict groups or ROWS
use
having
after/before group by clause don’t use where
Match criteria in having are displayed
Operator used in FunctionsSingle row
EQUAL TO =
GREATER THAN >
GREATER THAN EQUAL TO >=
LESS THAN <
LESS THAN EQUAL TO <=
NOT EQUAL TO <> / ^= / !=
Subquery Retrieve data based on an unknown condition
- 3 -

Activity (6)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Rangarajesh Jal liked this
payakkamron liked this
Anand Jha liked this
mr_hammerer liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->