Oragle 10 g Material
4
A set of operations that can act on the relations to produce other relations.
-ata integrity for accuracy and consistency
A &elational database uses relations or t%o dimensional tables to store information.
DATA MODELS :
The -ata 6odels help in eploring ideas and improve the understanding of the database design.
PURPOSE OF DATA MODELS :
-- Communicate HH Categori2e HH -escribe HH "pecify HH Investigate
HH 'volve HH Analy2e HH Imitate
O'.ECTI/E OF THE MODELS :
To produce a model that fits a multitude of uses
"hould be understood by an end user.
"hould contain sufficient detail for a developer to build the database system
RELATIONAL DATA'ASE PROPERTIES :
It can be accessed and modified by eecuting "tructured Euery Language statements.
It contains a collection of tables %ith no physical pointers.
It uses a set of operators.
,e need not specify the access route to the tables
There is no need to identify ho% the data is arranged physically.
COMMUNICATING WITH RD'MS :
The "tructured Euery Language is used to Communicate %ith &-*6".
STRUCTURED ,UER! LANGUAGE :
It allo%s the user to communicate as the server
It is 'fficient
It is easy to learn and use
It is functionally complete( by allo%ing the use to define( retrieve and manipulate the data.
A'OUT ORACLE ; :
It is the first ob#ect capable database.
It provides a ne% engine %hich supports
Ob#ect oriented programming
Comple data types
Comple business ob#ects
<ull compatibility %ith the relational concepts.
Oragle 10 g Material
5
It provides OLTP applications( %ith sharing of runtime data structures( large buffer caches and
deferrable constrains.
It supports Client "erver and ,eb based application %hich are distributed and multitired.
It can scale tens and thousands of concurrent users.
A'OUT ORACLE ;" :
It is the database of Internet Computing.
It provides advanced tools to manage all types of data in ,eb "ites.
The Internet <ile "ystem ( I<"! combines the po%er for ease of use a file system.
'nd users can easily access files and folders in O&ACL' I<" via a variety of protocols.
It enables the users to %ebGenable their multimedia data
It provides full( native integration %ith 6icrosoft Transaction "erver (6T"!.
It provides high performance Internet platform for eGcommerce and data %arehousing.
The core pieces of Oracle Internet Platform are B
*ro%ser based clients to process presentation.
Application servers to eecute business logic and serve presentation logic to
bro%ser based clients.
-atabases to eecute database intensive business logic and serve data.
ENTIT! RELATIONSHIP MODEL :
In an effective system data is divided into discrete categories or entities.
An '& J 6odel is an illustration of various entities in a business and the relationships bet%een
them.
It is built during the analysis phase of the "ystem -eveloping Life Cycle.
'& J 6odel separates the information reFuired & the business from the activities performed.
ER 7 MODEL 'ENEFITS :
It documents information for the organi2ation in a clear( precise format.
Provides a clear picture of the scope of the information reFuirement.
Provides an easily understood pictorial map for the database design
It offers an effective frame%or+ for integrating multiple application.
<E! COMPONENTS IN DIA ER 7 MODEL :
ENTIT! : It is a thing of significance about %hich the information need to be +no%n.
ATTRI'UTES : It is something that describes or Fualifies an entity.
-- 'ach attribute may be mandatory or optional.
RELATIONAL DATA'ASE TERMINOLOG! :
Oragle 10 g Material
6
ROW OR TUPLE B
It represents all data reFuired for a particular instance in an entity.
'ach ro% is an entity is uniFuely identified by declaring it as P&I6A&? ;'? or @DIE@' .
The order of the ro%s is not significant( %hile retrieving the data.
COLUMN OR ATTRI'UTE :
It represents one +ind of data in a table
The column order is not significant %hen storing the data.
A FIELD :
It can be found at the Intersection of a ro% and a column.
A <ield can have only one value( or may not have a value at all( the absence of value in
Oracle is represented as D@LL.
RELATING MULTIPLE TA'LES :
'ach table contains data that describes eactly only one entity.
-ate about different entities is stored in different tables.
&-*6" enables the data in one table to be related to another table by using the foreign +eys.
A <oreign ;ey is a column or a set of Column that refer to a Primary ;ey in the same table or
another table.
RATIONAL DATA'ASE PROPERTIES :
"hould not specify the access route to the tables( and should not reveal the physical arrange.
The -atabase is accessed using "tructured Euery Language ( "EL !
The language is a collection of set of operators.
STRUCTURED ,UER! LANGUAGE STATEMENTS :
O&CL' "EL Compiles %ith industry accepted standards.
The different categories into %hich the "EL statements fall are
Data Retr"e=a State$e*ts :
"'L'CT
Data Ma*"p5at"%* La*g5age State$e*t ( DML )
ID"'&T @P-AT' -'L'T'
Data De#"*"t"%* La*g5age State$e*t (DDL )
C&'AT' ALT'& -&OP
&'DA6' T&@DCAT'
Tra*sact"%* C%*tr% La*g5age State$e*t ( TCL )
CO66IT &OLL*AC; "A$'POIDT
Oragle 10 g Material
7
Data C%*tr% La*g5age ( DCL )
)&ADT &'$O;'
A'OUT THE S,L 'UFFER :
All Commands of "EL are typed at the "EL prompt.
Only one "EL "tatement is managed in the "EL *uffer.
The Current "EL statement replaces the previous "EL statement in the *uffer.
The "EL statement can be divided into different lines %ithin the "EL *uffer.
Only one line i.e.( the current line can be active at a time in the "EL *uffer.
At "EL prompt( editing is possible only in the current "EL *uffer line.
'very statement of "EL should be terminated @sing K
One "EL statement can contains only one.
To run the previous or current "EL statement in the *uffer type L C Lat "EL prompt.
To open the "EL 'ditor type ed at "EL prompt.
CREATING AND MANAGING TA'LES :
DATA'ASE O'.ECTS :
A Oracle database can contain multiple data structures.
The different -atabase ob#ects in Oracle are B
TA'LE : @sed to store date( *asic @nit
/IEW : Logically represents subsets of data from one or more tables.
SE,UENCE : @sed to )enerate Primary ;ey values.
INDE1 : It is used to improve the performance of some Fueries.
S!NON!M : @sed to give alternate names to ob#ects.
Tabes "* ORACLE ; + > + 10 :
Tables can be crated at any time( even %hen the users are using the database.
"i2e of the table need not be specified.
The structure of the table can be modified online.
R5es t% Create A Tabe :
The user should have permission or C&'AT' TA*L' command( and storage area.
The Table name should begin %ith a letter and can be / J 1> characters long.
Dames can contain B
HH A J M HH a G 2 HH > J 9 HH G ( N ( O
Dames can not be duplicated for another ob#ect in the same O&ACL' "erver.
Dames cannot be oracle servers reserved %ord
Oragle 10 g Material
8
Dames are not case sensitive
Create Tabe State$e*t B
S&*ta6 :
"EL P C&'AT' Table Q TableRDame P
(
ColumnRDame/ Q -ata type P (,idth!(
ColumnRDame0 Q -ata type P (,idth!(
B
B
ColumnRDamen Q -ata type P (,idth!
! K
'5"3"*g '%c?s %# S,L State$e*ts :
H -ata types H Literals H <ormat 6odels H Dulls
H Pseudo Columns H Comments H -atabase Ob#ects
H "chema Ob#ect Dames and Eualifiers
H "ynta for "chema ob#ects and parts of "EL "tatements.
Data T&pes "* Orace :
'ach value in O&ACL' is manipulated by a date type.
The data types value associates fied set of properties %ith the value.
The values of one data type are different from another data type.
The data type defines the domain of values that each column can contain.
The *uiltGin data types of O&ACL' are Categori2ed as
CIA&ACT'& -ATA T?P'"
D@6*'& -ATA T?P'"
LOD) AD- &A, -ATA T?P'"
-AT'TI6' -ATA T?P'"
LA&)' O*='CT -ATAT?P'"
&O,I- -ATAT?P'"
C@aracter Data T&pes :
They store character data %hich can be Alphanumaric data
The Information can be
,ords
<ree J <orm Tet
-atabase Character set
Dational Character set
They are less restrictive than other data types an have very fe% properties
The data is stored in strings %ith byte values
The information can belong to either
Oragle 10 g Material
9
7 J list A"CII Character set
'*C-IC
O&ACL' supports both single byte & multi byte character sets.
The different character data types are B
CIA& DCIA& $A&CIA&0 D$A&CIA&0
CHAR DATAT!PE B
It specifies fied length character string.
The si2e should be specified.
If the data is less than the original specified si2e( blan+ pads are applied
The default length is 1 '&te and the 6aimum is 8000 '&tes.
The si2e of a character can range from 1 '&te t% A '&tes depending on the database
character set.
NCHAR DATAT!PE B
It is first time defined in O&ACL' 9i( and contains @nicode data only.
The columnSs maimum length is determined by the Dational Character set definition.
The 6aimum si2e allo%ed is 8000 '&tes and si2e has to be specified.
If the data is shorter than the actual si2e then the blan+ pads are applied.
/arc@ar Datat&pe B
It specifies the variable length character string.
The 6inimum si2e is 1 '&te and the 6aimum si2e is A000 '&tes:
It occupies only that space for %hich the data is supplied.
N=arc@ar Datat&pe B
It is first time defined in O&ACL' 9i.
It is defined for @nicode only date.
The minimum for the si2e is 1 '&te and maimum is A000 '&tes:
NUM'ER DATAT!PES B
N5$ber Data T&pe :
It stores 2ero( positive and negative fied and floating point numbers.
The range of magnitude is
/.> H />
G/1>
to 9.9 ....9 H />
/04
The general declaration is
D@6*'& ( p ( s !
P It specifies the precision( i.e.( the total number of digits ( / to 18 !
" it specifies the scale( i.e.( the number digits to the right of the decimal
point. It can range from J83 to /07.
Oragle 10 g Material
10
F%at Data T&pe :
It specifies to have a decimal point any%here from the first to the last digit( or can have no
decimal point at all.
The scale value is not applicable to floating point numbers( as the number of digits that can
appear after the decimal point is not restricted.
S&*ta6 :
<loat It specifies a floating point number %ith decimal precision 18 or binary
precision of /05.
<loat (*! It specified a floating point number %ith binary precision b.
The precision can range from / to /05.
To convert from binary to decimal precision multiply L b L by 0:90109.
To convert from decimal to binary precision multiply the decimal precision by
9:981>9.
The maimum of /05 digits of binary precision is roughly eFuivalent to 18 digits of decimal
precision.
L%*g 0 RaB Data T&pes :
L%*g Data T&pe :
This datatype stores variable length charcgter strings.
It is used to store very lengthy tet strings
The length of LOD) values may be limited by the memory available on the computer.
LOD) columns can be referenced in
HH "'L'CT Lists HH "'T Clauses of @P-AT' statements
HH $AL@'" clauses of ID"'&T statements.
Restr"ct"%*s :
A single table can contain only one LOD) column.
Ob#ect types cannot be created on LOD) attribute.
LOD) columns cannot appear in ,I'&' clauses or in Integrity Constraints.
Indees cannot be created on LOD) Columns
LOD) can be returned through a functions( but not through a stored procedure.
It can be declared in a PLC"EL unit but cannot be referenced in "EL.
DATE 0 TIMME DATA T!PES :
Date Data T&pe :
It is used to store data and time information.
The dates can be specified as literals( using the )regorian Calender.
The information revealed by date is B
H Century H ?ear H 6onth
H -ate H Iour H 6inute H "econd
Oragle 10 g Material
11
The default date format in O&ACL' is --G6ODG??( and is specified in
DL" J -AT' J <O&6AT.
The default time accepted by O&ACL' date is /0 B >> B >> A6 ( 6idnight !
The default date accepted by O&ACL' data is the <irst day of the Current 6onth.
The -ate range provided by Oracle is
=AD@A&? /( 37/0 *C to -'C'6*'& 1/( 9999 A-.
T"$esta$p Data T&pe :
It is an etension of the -AT' data type.
It stores
- Da& - M%*t@ - !ear - H%5r
- M"*5te - Sec%*3
S&*ta6 : TI6'"TA6P T U <ractional J "econds J Precision V W
<ractional J "econds J Precision optionally specifies the number of digits in the
fractional part of the "'COD- datetime field.
It can be a number in the range of > J 9 ( %ith default as 5.
RaB 0 L%*g RaB Data T&pes :
&A, and LOD) &A, data types are intended for storage of binary data or *yte "trings.
&A, and LOD) &A, are variable length data types
They are mostly used to store graphics( sounds documents etc.
The O&ACL' converts the &A, & LOD) &A, data into Ieadecimal form.
'ach Ieadecimal character represents four bits of &A, data.
Large Ob2ect ( LO' ) Data T&pes :
The *uilt in LO* data types are
H *LO* H CLO* H DCLO*
These data types are stored inernally.
The *file is an LO* %hich is stored eternally
The LO* data types can store large and unstructured data li+e Tet( Image( $ideo and
"patial data.
The maimum si2e is upto 3 )*
LO* columns contain LO* locators( %hich can refer to outGofGline or inGline LO* values.
LO*Ss selection actually returns the LO*Ss locator.
'FILE Data T&pe :
Oragle 10 g Material
12
It enables access to binary file LO*Ss %hich are stored in the file systems outside O&ACL'.
A *<IL' column or the attributes stores the *<IL' locator.
The *<IL' locator maintains the directory alias and the filename.
The *inary <ile LO*Ss do not participate in transactions and are not recoverable.
The maimum si2e is 3 )*.
'LOG Data T&pe :
It stored unstructured *inary Large Ob#ects
They are *it streams %ith no character set semantics.
They are provided %ith full transactional support.
CLO' Data T&pe :
It stores single byte and multi byte character data
*oth fied %idth and variable %idth character sets are supported
They are provided %ith full transactional support.
NCLO' Data T&pe :
It stores @nicode data using the Dational Character set.
ROWID Data T&pe :
'ach ro% in the database has as address.
The ro%s address can be Fueried using the pseudo column &O,I-.
&O,I-Ss efficiently support partitioned tables and Indees.
'ample B
"ELP Create Table "tudents
(
"tuId Dumber (5!(
<name $archar0(1>!(
Lname $archar0(1>!(
-O* -ate(
-O= -ate(
<ees Dumber(7(0!(
)ender $archar0(/!
! K
"EL P Create Table Lab"pecification
(
ProdId Dumber(5!(
ProdPhoto *LO*(
Prod)raphic *<IL'(
Prod-esc LOD)
! K
P%p5at"*g t@e Data "*t% Tabes :
Oragle 10 g Material
13
INSERT "tatement B
The ID"'&T statement is used to add ro%s to a
Table
$ie%s *ase Tables
A partition of a Partition Table.
A subpartition of a CompositeRPartitioned Table
An ob#ect table
An ob#ect vie%Ss base Table.
Insertion of data into a table can be eecuted in t%o %ays.
o Conventional ID"'&T
o -irect J path ID"'&T
In Conventional Insert statement( O&ACL' reuses free space in the table into %hich the data in
being inserted and maintains referential integrity constraints.
In -irectGpath insert ( O&ACL' appends the inserted data after eisting data in the Table( the free
space is not reused.
S&*ta6 :
INSERT INTO C TA'LEDNAME E ( COL1F COL8F G:: )
/ALUES ( /ALUE1F /ALUE8FG::::) H
E6a$pes:
INSERTING DATA INTO ALL COLUMNS OF A TA'LE :
S,LE ID"'&T IDTO "T@-'DT"
$AL@'" (/01( L "A6PATIS( L;@6A&S( S09G=ADG8>S( 1>G6A&G94S( 04>>>(S6S! K
In this case the values should be provided to all the columns that eist inside the table.
The order in %hich the values are declared in the values clause should follo% the same order as
that of the original table order.
The char( varchar and data type data should be declared in single Fuotes.
INSERTING DATA INTO THE RE,UIRED COLUMNS:
S,LE ID"'&T IDTO "T@-'DT" ("tudno( <name( Lname( -o#( )ender!
$AL@'" (/014(S&a#S( L;umarS( S0>G<ebG84S( L6S! K
In this case the order of the columns declared in the "'L'CT list need not be the same order as
that of the original table.
The data values in the values clause should match %ith that of "'L'CT list.
Oragle 10 g Material
14
The columns for %hich the data is not supplied are filled %ith D@LL values.
If the columns that %ere not supplied %ith data are declared %ith DOT D@LL Constraints then the
ID"'&T "tatement is &e#ected.
INSERTING NULL /ALUES :
D@LL $alues can be inserted in t%o %ays
1. I6PLICIT Omit the column from the list.
2. 'APLICT "pecify the D@LL ;ey%ord.
"pecify 'mpty "tring L L ( only for character strings and dates.
The targeted column should not be set as DOT D@LL Constraint.
S,LE ID"'&T IDTO "T@-'DT" ("tudDo( <name( Lname( -O*( -O=( <ees( )ender!
$AL@'" (/013(S;rishnaS( D@LL( S08G<'*G>3S( D@LL( L6S! K
INSERTING SPECIAL /ALUES :
S!SDATE FUNCTION
It is a Pseudo column provided by the oracle.
The function returns the current date & time.
S,LE ID"'&T IDTO "tudents ("tudDo( <name( -O=( <ees( )ender!
$alues (/013( L6ohanS( "ysdate( 04>>>(S6S! K
USER FUNCTION :
It is special function( %hich records the current @"'& Dame.
S,LE ID"'&T IDTO "tudents ("tudDO( <name( Lname( -O=( -O*( <ees!
$alues (/013( L"ureshS( @ser( "ysdate( S04G#anG8>S( 1>>>>! K
SU'STITUTION /ARIA'LES :
These variables are used to stored values temporarily.
The values can be stored temporarily through
/. "ingle Ampersand (&!
0. -ouble Ampersand (&&!
1. -'<ID' and ACC'PT Commands
The "ingle Ampersand substitution variable applies for each instance %hen the "EL statement is
create or eecuted.
The -ouble Ampersand substitution variables applied for all instances until that "EL statement is
eisting.
USING SINGLE AMPERSAND SU'STITUTION /ARTIA'LE :
S,LE ID"'&T IDTO "tudents ("tudI-( <name( LDame( -ob( <ees!
$AL@'" (&"tudDo( LDameS( &Last Dame( L-ate Jof J*irth( 04>>>! K
USING DOU'LE AMPERSAND SU'STITUTION /ARIA'LE :
Oragle 10 g Material
15
S,LE ID"'&T IDTO "tudents ("tudDo( <name( Lname( -ob( -o#( <ees( )ender!
$alues (&"tudDo( L&<irstDameS( L& LastDameS( L-obS( "ysdate(
&&<ees( &)ender! K
DEFINING CUSTOMIED PROMPTS :
@sing the ACC'PT Command of "EL HPlus( the prompts can be customi2ed.
ACC'PT Command stores the values in a variable.
P&O6PT Command displays the Customi2ed tet.
After creating a script using the substitutions variable to a file it can called %ith ACC'PT and
P&O6PT %ith greater meaning.
E1AMPLE:
ACC'PT "tudRid P&O6PT LPlease 'nter the "tudent DumberBS
ACC'PT <irRname P&O6PT LPlease 'nter the <irst DameBS
ACC'PT CouRfees P&O6PT LPlease 'nter the Course <eesBS
S,LE ID"'&T IDTO "tudents ("tudDo( <name( <ees!
$AL@'" (&"tudRid (S&<irRnameS( &CouRfees! K
E1AMPLE:
ACC'PT -epartmentRId P&O6PT LPlease 'nter the -epartment DumberBS
ACC'PT -epartmentRDame P&O6PT LPlease 'nter the -epartment DameBS
ACC'PT Location P&O6PT LPlease 'nter the LocationBS
S,LE ID"'&T IDTO -'PT (-eptno( -name( Loc!
$AL@'" (&-apartmentRId( S&-epartmentRDameS( S&LocationS ! K
CREATING AN S,L SCRIPT FILE:
The "A$' Command is used to store the current contents of the "EL *uffer
Steps:
/. At "EL prompt type the full name of the path %here the file has to be created.
0. )ive the name of the file %ith :sI etension.
1. If the file has to be replaced %ith the same eisting name then use &'PLAC'
ALL clause.
E1AMPLE:
S,LE "A$' -BX6y -irX"ELscriptXInsert prompt.sFl
S,LE "A$' -BX6y -irX"ELscriptXInsert prompt.sFl &'PLAC' ALL
,UER!ING THE DATA FROM TA'LES:
,UER!: It is an operation that retrieves data from from one or more tables or vie%s.
SELECT STATEMENT:
The "'L'CT statement is used to retrieve data from one or more tables ( ob#ect tables (vie%s(
ob#ect vie%s or management vie%s.
Oragle 10 g Material
16
PRERE,UISITES :
The user must have the "'L'CT privileges on the specified ob#ect.
The "'L'CT AD? TA*L' allo%s to select the data from any recogni2ed ob#ect.
CAPA'ILITIES IF S,< SE<ECT STATEMENT :
The "'L'CT statement can be used to select or &etrieve data from the ob#ect using any one of
the follo%ing criteria.
o SELECTION :
It chooses the ro%s in a table that are epected to return by a Fuery.
o PRO.ECTION :
It chooses the columns in a table that are epected to return by a Fuery.
o .OIN :
It chooses the data in from one or more numbers of tables by creating a lin+
bet%een them.
'as"c SELECT S&*ta6 :
SELECT J DISTINCT K L - F C%5$* J A"as K F G:: M Fr%$ Tabe H
SELECT Identifies Columns( FROM Identifies Tables .
SELECT "pecifies a list of Column ( one C more !
DISTINCE "uppresses -uplicates
- "elect all Columns.
COLUMN "elects the Damed Column.
A"as )ives selected columns different columns.
FROM Tabe "pecifies the table containing the columns.
WRITING S,L STATEMENTS TO SELECT OR RETRI/E DATA FROM TA'LES :
T@e Sa$pe Tabes Use3 :
Tabe 1 : EMP
Oragle 10 g Material
17
C%5$* Na$e Data T&pe
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
E$p*% NUM'ER
E*a$e /ARCHAR
Dept*% NUM'ER
.%b /ARCHAR
Sa NUM'ER
C%$$ NUM'ER
Mgr NUM'ER
H"re3ate DATE
Tabe 8 : DEPT
C%5$* Na$e Data T&pe
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
Dept*% NUM'ER
D*a$e /ARCHAR
L%c /ARCHAR
Tabe 9 : SALGRADE
C%5$* Na$e Data T&pe
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
H"sa NUM'ER
L%sa NUM'ER
Gra3e NUM'ER
Retr"e="*g Data #r%$ A C%5$*s :
"Fl P "elect H from 'mpK
"Fl P "elect H from -eptK
"Fl P "elect H from "algradeK
In this the N - N is a pro#ection operator.
It pro#ects data from all the columns eisting in the table %ith all records.
The data is displayed in a table format.
Retr"e="*g Data #r%$ Spec"#"c C%5$*s :
"Fl P "elect empno( ename( sal from empK
"Fl P "elect ename( #ob( sal( deptno form empK
"Fl P "elect deptno( dname( loc from deptK
"Fl P "elect Iisal( Losal( )rade from "algradeK
"Fl P "elect empno( ename( sal ( hiredate from empK
Oragle 10 g Material
18
The column names need not be in the same order as table.
The columns should be separated using comma.
The column names can be separated onto different lines %ithin the "EL *uffer.
The casing of column names is not important.
C%5$* Hea3"*g De#a5ts :
The default #ustification of the data after it is retrieved from the table is ...
L'<T -ate and Character -ata
&I)IT Dumeric -ata
The default display of the data is al%ays is UPPER Casing.
The character and date column headings can be truncated( *ut numb ers cannot be
truncated.
App&"*g Ar"t@$et"ca Operat"%*s "* Seect State$e*ts :
Arithmetic 'pressions can be implemented through "'L'CT statement.
Arithmetic 'pressions can be implemented to
o 6odify the %ay the data is displayed.
o Perform calculations.
o Implement ,IAT J I< "cenarios.
An Arithmetic 'pression can contain
o "imple Column names
o Constant numeric values
o Arithmetic operators.
ARITHMETIC OPERATORS :
The Arithmetic operators can be used to create epressions on D@6*'& and -AT' data.
The Arithmetic operators supported are ...
o Addition :
o "ubtraction G
o 6ultiply H
o -ivide C
The Arithmetic operators can be used in any clause of a "EL statement. 'cept the <&O6
clause.
"EL H Plus ignores *ac+ "paces before and after the Arithmetic operator.
"Fl P "elect empno( ename( sal( sal : 4>> from empK
Oragle 10 g Material
19
"Fl P "elect empno( ename( sal( sal J />>> from empK
Operat%r Prece3e*ce :
6ultiplication and -ivision ta+e priority over addition and subtractions ( H C : G !
Operators of the same priority are evaluated from left to right.
To prioriti2e evaluation and to increase clarity parenthesis can be implemented.
"Fl P "elect empno( ename( sal( ( /0 H sal ! : />> from 'mpK
"Fl P "elect empno( ename( sal( /0 H ( sal : 4>> ! from 'mpK
Ha*3"*g N5 /a5es :
NULL : It is a value %hich is
@navailable
@nassigned
@n+no%n
Inapplicable
A NULL is not same as 2ero or blan+ space.
If a ro% lac+s the data for a particular column( than that value is said to be NULL or to contain
NULL:
SI E "elect ename( #ob( sal( comm <rom 'mp K
If any column value is an Arithmetic epression is D@LL( the overall result is also D@LL.
The above situation is termed as D@LL propagation and has to be handled very carefully.
"Fl P "elect ename( #ob( sal( comm( /0 H "al : comm <rom 'mp K
"Fl P "elect ename( #ob( sal( comm( /0 H sal : comm from 'mp K
N/L F5*ct"%* :
The D$L function is used to convert a D@LL value to an actual value.
S&*ta6 :
D$L ( 'pr/ ( 'pr0 !
'pr/ B is the source value or epression that may contain D@LL.
'pr0 B is the target value for converting D@LL.
D$L <unction can be used to convert any data type( the return value is al%ays the same as the
data type of 'pr/.
The -ata types of the "ource and -estination must match
o D$L ( Comm ( > !
o D$L ( Iiredate ( S>/G=@DG99S!
o D$L ( =ob ( LDot AssignedS!
Oragle 10 g Material
20
"Fl P "elect 'name( "al( Comm( "al : D$L ( Comm( > ! <rom 'mpK
"Fl P "elect 'name( "al( Comm( ( "al H /0 ! : D$L (Comm ( > ! <rom 'mpK
"Fl P "elect 'name( "al( Comm( ( "al : 4>> ! : D$L ( Comm ( > ! <rom 'mpK
W%r?"*g B"t@ A"ases :
An Alias is an alternate name given for any Oracle Ob#ect.
Aliases is Oracle are of t%o types
HH Column Alias HH Table Alias
Column Alias &enames a Column Ieading
The Column alias is specified in the "'L'CT list by declaring the Alias after the Column Dame by
using the space separator.
ALIA" Ieadings appear is @PP'& Casing by default.
The Alias should be declared in double Fuotes if it is against the specifications of Daming
Conversions.
The A" +ey%ord can be used bet%een the Column Dame and Alias.
An alias effectively renames the "'L'CT list item for the duration of the Fuery.
An alias cannot be used( any %here in the "'L'CT list for operational purpose.
"Fl P "elect 'mpno Dumbers(
'name Dame(
"al Y*asic "alaryZ(
=ob -esignation
<rom 'mpK
"FlP "elect -eptno A" Y -epartment Id Z (
-name A" Y -epartment Dame Y (
Loc A" Place
<rom -eptK
"FlP "elect Iisal As Y 6aimum &ange Y (
Losal As Y 6inimum &ange Y (
)rade
<rom "algrade K
LITERALS IN ORACLE B
A L"tera and a C%*sta*t value are synonyms to one another and refer to a fied data value.
The types of Literals recogni2ed by Oracle are
o Tet Literals
o Integer Literals
o Dumber Literals
o Interval Literals
Te6t L"teras :
Oragle 10 g Material
21
It specifies a tet or character literal.
It is used to specify values %henever LtetS or CIA& appear in
HH 'pression HH Condition HH "EL <unction HH "EL "tatements.
It should be enclosed in single Fuotes
They have properties of both CIA& and $A&CIA&0 data types.
A tet literal can have a maimum length of 3>>> *ytes.
' B L mployee Information L
L 6anagerZs "pecification L
D Ln char Literal L
Us"*g L"tera C@aracter Str"*gs :
A literal that is declared in a "'L'CT list can be a character( a Dumber( or a -ate.
A literal is not a column name or a column alias.
A literal is printed for each ro%( that is retrieved by the "'L'CT statement.
Literal strings of <reeG<orm test can be included in the Fuery as per the reFuirement.
-ate and character literals must be enclosed %ithin the single Fuotation mar+s L L
Literals increase the readability of the output.
"Fl P "elect 'name [ [ L B L [ [ L 6onth "alary \ L [ [ "al As "alaries <rom 'mp K
"Fl P "elect L The -esignation of L [ [ 'name [ [ L is L [ [ =ob As -esignation <rom
'mpK
"Fl P "elect L The Annual "alary of L [ [ 'name [ [ L is L [ [ "al H /0 As
AnnualR"alary <rom 'mp K
"Fl P "elect -name [ [ L -epartment is Located at L [ [ Loc <rom -ept K
"Fl P "elect 'name [ [ L =oined the Organi2ation on L [ [ Iiredate <rom 'mp K
"Fl P "elect 'name [ [ L ,or+s in -epartment Dumber L [ [ -eptno [ [ L as L
[ [ =ob <rom 'mp K
App&"*g C%*cate*at"%* Operat%r :
The Concatenation operator lin+s columns to other columns( Arithmetic epressions( or constant
values.
Columns on either side of the operator are combined to ma+e a single output column.
The resultant column is treated as an character epression.
The Concatenation operator is represented in Oracle by double pipe symbol ( [ [ !
"Fl P "elect 'mpno [[ 'name [[ L ( -esignation is L [[ =ob Y 'mployees Information Y
<rom 'mp K
"Fl P "elect L The *asic "alary of L [[ 'name [[ L is &s L [[ "al 'mployee <rom 'mp K
E"$"*at"*g t@e D5p"cate R%Bs #r%$ t@e O5tp5t :
@ntil it is instructed "EL H Plus displays the results of a Fuery %ithout eliminating duplicate ro%s.
Oragle 10 g Material
22
To eliminate the duplicate ro%s in the result( the -I"TIDCT +ey%ord is used.
6ultiple columns can be declared after the -I"TIDCT Fualifier.
The -I"TIDCT Fualifier affects all the selected columns( and represents a distinct combination of
the columns.
"Fl P "elect -I"TIDCT -eptno <rom 'mp K
"Fl P "elect -I"TIDCT =ob ( -eptno <rom 'mp K
"Fl P "elect -I"TIDCT -eptno ( =ob <rom 'mp K
F"ter"*g %# Rec%r3s :
The number of ro%s returned by a Fuery can be limited using the WHERE clause.
A ,I'&' Clause contains a condition that must be met and should directly follo% the <rom
Clause.
S&*ta6 :
"'L'CT T -istinct W U H [ Column T alias W ( ..V <rom Table T ,I'&' Condition(s! W K
The ,I'&' clause can compares
HH $alues in Columns
-- Literal $alues
-- Arithmetic 'pressions
-- <unctions
The components of ,I'&' clause are
HH Column Dame
HH Comparison Operator
HH Column Dame( constant or list of values.
The Character strings and dates should be enclosed in single Fuotation mar+s.
Character values are case sensitive and -ate values are format sensitive (--G6ODG??!
The Comparison operator are used in conditions that compare one epression to another.
The different comparison operators are
HH \ HH Q P ( ] \ ( ^ \ ( HH P HH Q HH P \ HH Q \
The format of the ,I'&' clause is ,I'&' 'pr operator value.
'amples B
"Fl P "elect 'name( "al( =ob <rom 'mp ,here =ob \ L 6ADA)'& L
"Fl P "elect 'name( Iiredate ( -eptno( "al <rom 'mp ,here -eptno \ /> K
"Fl P "elect 'mpno( 'name( "al <rom 'mp ,here "al P \ 1>>> K
"Fl P "elect 'name [[ L =oined on L [[ Iiredate Y 'mployees =oining -ates Y
<rom 'mp ,here Iiredate \ L >/ J =AD J 94 L K
Oragle 10 g Material
23
"Fl P "elect 'name [[ L ,or+s in -epartment L [[ -eptno L 'mployees and
-eaprtments L <rom 'mp ,here -eptno Q P 0> K
"Fl P "elect 'name( "al( -eptno( =ob <rom 'mp ,here =ob Q P L CL'&; L K
"Fl P "elect 'name Dame ( "al *asic ( "al H /0 Annual <rom 'mp
,here "al H /0 P 5>>> K
L%g"ca Operat%rs :
The Logical operators combine the results of t%o components conditions to produce a single
result.
The Logical operators provided by Oracle are
HH AD- HH O& HH DOT
AND Operat%r B
It &eturns T&@' if both or all component conditions are T&@'.
It &eturns <AL"' if either is <AL"'( else returns un+no%n.
Tr5t@ Tabe :
AND TRUE FALSE NULL
TRUE T F NULL
FALSE F F F
NULL NULL F NULL
"Fl P "elect 'mpno( 'name( =ob( "al <rom 'mp ,here "al P \ //>> AD-
=ob \ LCL'&;S K
"Fl P "elect 'mpno( 'name ( =ob ( "al <rom 'mp ,here -eptno \ />
AD- =ob \ L6ADA)'&S K
"Fl P "elect 'name( "al ( =ob <rom 'mp ,here "al P \ /4>> AD- "al P 4>>> K
"Fl P "elect 'name( "al( =ob <rom 'mp ,here ( "al P \ /4>> AD- "al Q \ 4>>> !
AD- =ob \ L6ADA)'&S K
OR Operat%r :
It returns T&@' if either component conditions is T&@'
It returns <AL"' if both are <AL"'( else returns un+no%n
Tr5t@ Tabe :
OR TRUE FALSE NULL
TRUE T T T
Oragle 10 g Material
24
FALSE T F NULL
NULL T NULL NULL
"Fl P "elect 'mpno( 'name( =ob( "al <rom 'mp ,here "al P \ //>> O&
=ob \ LCL'&;S K
"Fl P "elect 'mpno( 'name( =ob( "al <rom 'mp ,here -eptno \ />
O& =ob \ L6ADA)'&S K
"Fl P "elect 'name( "al( =ob <rom 'mp ,here "al P \ /4>> O& "al P \ 4>>> K
"Fl P "elect 'name( "al( =ob( -eptno <rom 'mp ,here -eptno \ /> O& -eptno \ 0> K
"Fl P "elect 'name( "al( =ob <rom 'mp ,here =ob \ LCL'&;S O& =ob\S6ADA)'&S K
"Fl P "elect 'name( "al( =ob <rom 'mp ,here ( "al Q \ 04>> O& "al P \ 4>>> ! O&
=ob \ L6ADA)'&S K
NOT Operat%r :
It returns T&@' if the follo%ing condition is <AL"'.
It returns <AL"' if the follo%ing condition is T&@'.
If the condition is @n+no%n( it returns @n+no%n.
Tr5t@ Tabe :
TRUE FALSE NULL
NOT F T NULL
C%$b"*at"%* %# AND a*3 OR Operat%rs :
"Fl P "elect 'mpno( 'name( =ob( "al <rom 'mp ,here ( "al P //>> O& =ob\LCL'&;S !
AD- -eptno \ 0> K
"Fl P "elect 'mpno( 'name( =ob( "al <rom 'mp ,here ( -eptno \ /> AD-
=ob \ L6ADA)'&S ! O& "al P \ 1>>> K
N%t Operat%r E6a$pes :
"Fl P "elect 'name( "al( =ob <rom 'mp ,here DOT =ob \ L6ADA)'&S K
"Fl P "elect 'name( "al( =ob <rom 'mp ,here DOT "al P 4>>> K
"Fl P "elect 'name( "al( =ob <rom 'mp ,here DOT "al Q 4>>> K
"Fl P "elect 'name( "al( Iiredate <rom 'mp ,here Dot Iiredate\S0>G<'*G8/S K
"Fl P "elect 'name( =ob( "al( -eptno <rom 'mp ,here DOT
=ob \ L "AL'"6ADS AD- -eptno \ 1> K
S%$e T@"*gs T% N%te GG:
Oragle 10 g Material
25
"Fl P "elect 'name( "al( =ob <rom 'mp ,here =ob P L6ADA)'&S K
"Fl P "elect 'name( "al( =ob <rom 'mp ,here =ob Q L6ADA)'&S K
"Fl P "elect 'name( "al( Iiredate <rom 'mp ,here Iiredate P 0>G<'*G/98/S K
"Fl P "elect 'name( "al( Iiredate <rom 'mp ,here Iiredate Q S0>G<'*G/98/S K
"Fl P "elect 'name( "al( Iiredate <rom 'mp ,here IiredateQPS0>G<'*G/98/S K
"Fl P "elect 'name( "al( Iiredate <rom 'mp ,here =ob Q P LCL'&;S K
"Fl P "elect 'name( "al( Comm <rom 'mp ,here Comm is D@LL K
"Fl P "elect 'name( "al( =ob <rom 'mp ,here DOT =ob P L6ADA)'&S K
"Fl P "elect 'name( "al( Iiredate <rom 'mp ,here DOT
Iiredate \ S/7G-'CG/98>S K
"Fl P "elect 'name( "al( Iiredate <rom 'mp ,here DOT
Iiredate P S/7G-'CG/98>S K
R5es %# Prece3e*ce :
The default Precedence order is
HH All Comparison Operators
HH DOT Operator
HH AD- Operator
HH O& Operator
The Precedence can be controlled using parenthesis.
S,L - PLUS Operat%rs :
'ETWEEN G: AND G: H NOT 'ETWEEN G:: AND G:
o This Operator is used to display ro%s based on a range of values.
o The declared range is inclusive
o The %Ber limit should be declared first.
"Fl P "elect 'name( "al( =ob <rom 'mp ,here "al *et%een />>> AD- /4>> K
"Fl P "elect 'name( "al( =ob <rom 'mp ,here "al DOT *et%een />>> AD- /4>> K
"Fl P "elect 'name( "al( =ob <rom 'mp ,here =ob *et%een L6ADA)'&S AD-
Oragle 10 g Material
26
L"AL'"6ADS K
"Fl P "elect 'name( "al( =ob <rom 'mp ,here =ob DOT *et%een L6ADA)'& AD-
L"AL'"6ADS K
"Fl P "elect 'name( "al( =ob( Iiredate <rom 'mp ,here Iiredate *et%een
S/7G<'*G/98/S AD- S0>G=@DG/981S K
"Fl P "elect 'name( "al( =ob( Iiredate <rom 'mp ,here Iiredate DOT *et%een
S/7G<'*G/98/S AD- S0>G=@DG/981S K
IN Operat%r H NOT IN Operat%r :
The Operator is used to test for values in a specified list.
The Operator can be used upon any datatype.
"Fl P "elect 'name( "al( =ob <rom 'mp ,here 'name ID( L<O&-S( LALL'DS ! K
"Fl P "elect 'name ( "al( =ob <rom 'mp ,here 'name DOT ID( L<O&-S ( LALL'DS ! K
"Fl P "elect 'name( "al( -eptno <rom 'mp ,here -eptno ID( /> ( 1> ! K
"Fl P "elect 'name( "al( -eptno <rom 'mp ,here -eptno DOT ID( /> ( 1> ! K
"Fl P "elect 'name( "al( Iiredate <rom 'mp ,here
Iiredate ID( S0>G<'I*G/98/S ( S>9G=@DG/98/S ! K
"Fl P "elect 'name( "al( Iiredate <rom 'mp ,here
Iiredate DOT ID( S0>G<'I*G/98/S ( S>9G=@DG/98/S ! K
IS NULL Operat%r H IS NOT NULL Operat%r :
The Operator tests for D@LL values
lt is the only operator that can be sued to test for D@LLSs.
D@LL means the value is unavailable( @nassigned( @n+no%n( or inapplicable.
"Fl P "elect 'name( -eptno( Comm <rom 'mp ,here Comm I" D@LL K
"Fl P "elect 'name( -eptno( =ob <rom 'mp ,here 6gr I" D@LL K
"Fl P "elect 'name( -eptno( Comm <rom 'mp ,here Comm I" DOT D@LL K
"Fl P "elect 'name( -eptno( Comm <rom 'mp ,here 6gr I" DOT D@LL K
LI<E Operat%r H NOT LI<E Operat%r :
The LI;' Operator is used to search to search for a matching character.
The character pattern matching operation is referred as a %ild card search
The available %ild cards in Oracle are
_ @sed to represent any seFuence of Mero or more characters.
C &epresents any single character( only at that position only.
Oragle 10 g Material
27
The ,ild Card symbols can be used in any combination %ith literal characters.
<or finding eact match for L _ L and L J L the '"CAP' option has to be used( %hich is L X L symbol
%ith '"CAP' Option.
"Fl P "elect 'name( =ob <rom 'mp ,here 'name LI;' L"_S K
"Fl P "elect 'name( =ob <rom 'mp ,here 'name DOT LI;' L"_S K
"Fl P "elect 'name( =ob <rom 'mp ,here 'name LI;' LRA_S K
"Fl P "elect 'name =ob <rom 'mp ,here 'name DOT LI;' LRA_S K
"Fl P "elect 'name "al <rom 'mp ,here 'name \ L"6_S K
"Fl P "elect 'name( "al <rom 'mp ,here L"6_S LI;' 'name K
"Fl P "elect 'name( Iiredate <rom 'mp ,here Iiredate LI;' L_G<'*G/98/S K
"Fl P "elect 'name( Iiredate <rom 'mp ,here Iiredate LI;' S>1G_G/98/S K
"Fl P "elect H <rom -ept ,here -name LI;' L_XR_S '"CAP' LXS K
Or3er"*g I*#%r$at"%* :
The Order of ro%s returned in a Fuery result is undefined.
The O&-'& *? Clause can be used to sort the ro%s
The O&-'& *? Clause should be the last clause in the order of all clauses in the "'L'CT
statement.
An epression or an alias can be specified to sort.
-efault ordering of -ata is Ascending
-- N5$bers 1 7 >>>
-- Dates Ear"est 7 Latest
-- Str"*gs A 7 O H NULLS Last:
S&*ta6 :
SELECT 'pr <rom Table Dame T ,I'&' Condition(s! W
T O&-'& *? U Column( 'pr V T A"C C -'"C W W K
The default ordering upon a column is Ascending( to change the default ordering -'"C should
be used after the column name.
"orting can be implemented on column aliases( and can also be implemented upon multiple
columns.
The controversy of sorting is bro+en only %hen there arises a conflict of consistency upon the
data in a column.
Oragle 10 g Material
28
"Fl P "elect 'name( =ob( -eptno( Iiredate <rom 'mp O&-'& *? Iiredate K
"Fl P "elect 'name( =ob( -eptno( Iiredate <rom 'mp O&-'& *? Iiredate -'"C K
"Fl P "elect 'name( =ob( "al <rom 'mp ,here =ob \ L6ADA)'&S O&-'& *? "al K
"Fl P "elect 'name( =ob( "al <rom 'mp ,here "al P \ 04>> O&-'& *? =ob(
'name -'"C K
"Fl P "elect 'mpno( 'name( "al( "al H /0 Annsal <rom 'mp O&-'& *? Annsal K
"Fl P "elect 'mpno( 'name( "al <rom 'mp O&-'& *? -eptno( "al( Iiredate K
"Fl P "elect 'mpno( 'name( "al <rom 'mp ,here "al P \ 0>>> O&-'& *? Iiredate(
"al -'"C K
The single ro% functions can appear in
HH "'L'CT List
HH ,I'&' List
HH "TA&T ,ITI Clause
HH CODD'CT *? Clause
The types of single ro% functions are
HH CIA&ACT'& HH D@6*'& HH -AT' HH COD$'&"IOD
M5t"pe R%B F5*ct"%*s :
These functions manipulate groups of ro%s to give one result per group of ro%s.
S"*ge R%B F5*ct"%*s :
They are used to manipulate data items.
They accept one or more arguments and return one value for each ro% returned by the Fuery.
An argument can be B
HH @ser "upplied Constant.
HH $ariable $alue.
HH Column Dame.
HH 'pression.
S&*ta6 :
<uncRDame ( Column C 'pr( T Arg/( Arg0( ..W !
S"*ge R%B F5*ct"%*s Feat5res :
Acts on each ro% returned in the Euery.
&eturn one result per ro%
6ay return a data value of a different type than that referenced
6ay epert one or more arguments.
Can be used in "'L'CT( ,I'&' and O&-'& *? Clauses.
Oragle 10 g Material
29
Can be nested.
Spec"#"cat"%* 'e@a="%r %# F5*ct"%*s :
C@aracter F5*ct"%*s : Accept Character input and can return both Character and
Dumber $alues.
N5$ber F5*ct"%*s : Accept Dumeric input and return Dumeric $alues.
Date F5*ct"%*s : Operate on values of date data type( can return both -ate and
Dumber.
C%*=ers"%* F5*ct"%* : Covert a value from one data type to another.
Ge*era F5*ct"%*s :
-- N/L Operates on D@LL $alues.
HH DECODE Operates on any data type and can return any data type.
C@aracter F5*ct"%*s :
They are functions that return character values( unless stated.
They return the data type $A&CIA&0( limited to a length of 3>>> *ytes
If the return value length eceeds( then the return value is truncated( %ithout an error.
The functions are categori2ed as
HH CIA&ACT'& 6ADIP@LATIOD <@DCTIOD".
HH CA"' COD$'&"IOD <@DCTIOD".
C@aracter Ma*"p5at"%* F5*ct"%*s :
L%Ber F5*ct"%* :
It converts Alpha character values to lo%er case
The return value has the same data type as argument char type ( CIA& or $A&CIA&0 !
S&*ta6 B LO,'& ( Column C 'pression !
"Fl P "elect LO,'&( LO&ACL' CO&PO&ATIODS ! <rom -ual K
"Fl P "elect 'name( LO,'& ( L 6? ID<O&6ATIODS ! <rom 'mpK
"Fl P "elect 'name( LO,'& ( 'name ! <rom 'mp ,here =ob \ L6ADA)'&S K
"Fl P "elect L The L [[ 'name [[ L Y s -esignation is L [[ =ob <rom 'mp
,here LO,'& ( =ob ! \ L managerS K
Upper F5*ct"%* :
It Converts the Alpha character values to @pper Case.
The return value has the same data type as the argument char.
S&*ta6 B @PP'& ( Column C 'pression !
Oragle 10 g Material
30
"Fl P "elect @pper ( L Oracle CorporationS ! <rom -ual K
"Fl P "elect 'name( @pper ( L 6y Information L ! <rom -ual K
"Fl P "elect 'name( Lo%er ( 'name !( @pper ( 'name ! <rom 'mp
,here =ob \ L6ADA)'&S K
"Fl P "elect 'name( =ob <rom 'mp ,here =ob \ @pper ( L6anagerS ! K
"Fl P "elect 'name( =ob( "al( "al H /0 <rom 'mp ,here =ob \
@pper ( Lo%er ( L6AD)'&S ! ! K
"Fl P "elect L The L [[ 'name [[ L Y s -esignation is L [[ Lo%er ( =ob ! ,here
=ob \ @pper ( LmanagerS ! Order *y "al K
"Fl P "elect @pper ( L The L [[ 'name [[ L Y s *asic "alary is &upees L [[ "al !
Y'm
ployee "alaries Y <rom 'mp ,here =ob In( L6ADA)'&S (
@pper ( Lcler+S ! ! Order *y "al -esc K
INITCAP F5*ct"%* :
It converts the Alpha character values to @ppercase for the first letter of each %ord( +eeping all
other letters in Lo%er case.
,ords are delimited by ,hite spaces or characters that are not alphanumeric.
S&*ta6 : INITCAP ( Column C 'pression !
"Fl P "elect Initcap ( Loracle corporationS ! <rom -ual K
"Fl P "elect L The =ob Title for L [[ Initcap ( 'name ! [[ L is L [[ lo%er ( =ob ! -etails
<rom 'mpK
"Fl P "elect 'name( @pper ( 'name ! ( Lo%er ( 'name ! ( Initcap ( 'name ! <rom 'mp K
"Fl P "elect 'mpno( Initcap ( 'name !( -eptno <rom 'mp ,here
'name \ @pper ( Lbla+eS ! K
CONCAT F5*ct"%* :
It Concatenates the first characters value to the second charactger value. Only t%o parameters
accept .
It return the character data type.
S&*ta6 : CONCAT ( Column/ C 'pr/( Column0 C 'pr0 !
"Fl P "elect Concat ( LOracleS ( LCorporationS ! <rom -ual K
"Fl P "elect 'name( =ob( Concat ( 'name( =ob ! <rom 'mp ,here -eptno \ /> K
Oragle 10 g Material
31
"Fl P "elect Concat ( L The 'mployee Dame is L ( Initcap ( 'name ! ! As
Y'mployee Dames Y <rom 'mp ,here -eptno in( />( 1> ! K
"Fl P "elect Concat ( Concat ( Initcap ( 'name !( L is a L ! ( =ob ! =ob <rom 'mp
,here -eptno in( />( 0> ! K
SU' STRING F5*ct"%* :
&eturns specified characters form character value( starting from a specified position
L m S ( to L n S characters long.
P%"*ts t% Re$e$ber GG:
o If m is > ( it is treated as /.
o If m is positive( Oracle counts from the beginning of char to find the first character.
o If m is Degative( Oracle counts bac+%ards from the end of the Character.
o If n is Omitted ( Oracle returns all characters to the end of Char.
o If n is less than / or > ( A D@LL is returned.
<loating point numbers passed as arguments to "ubstr are automatically converted to Integers.
S&*ta6 : SU'STR ( Col C 'pr( m( n !
"Fl P "elect "ubstr ( LA*C-'<)IS ( 1( 3 ! <rom -ual K
"Fl P "elect "ubstr ( LA*C-'<)IS ( G4( 3 ! <rom -ual K
"Fl P "elect "ubstr ( LA*C-'<)IS ( > (3 ! <rom -ual K
"Fl P "elect "ubstr ( LA*C-'<)IS ( 3 ! <rom -ual K
"Fl P "elect "ubstr ( LA*C-'<)IS( 3( > ! <rom -ual K
"Fl P "elect "ubstr ( LA*C-'<)IS( 3 ( G0 ! <rom -ual K
"Fl P "elect 'name( =ob <rom 'mp ,here "ubstr ( =ob( 3( 1 ! \ @pper( LageS ! K
"Fl P "elect Concat ( Initcap ( 'name ! (
Concat ( L is a L ( Concat ( Initcap ("ubstr ( =ob( /( 1 ! !( L'ater.S ! ! !
<rom 'mp ,here "ubstr ( =ob ( 3( 1 ! \ @pper ( LAgeS ! K
LENGTH F5*ct"%* :
&eturns the number of characters in a value.
If the char has data type CIA&( the length includes all trailing blan+s.
If the char is D@LL ( it return D@LL .
S&*ta6 : LENGTH ( Column C 'pression !
"Fl P "elect Length ( LO&ACL'S! <rom -ual K
"Fl P "elect Length ( 'name ! [[ L Characters eit in L [[ Initcap ( 'name ! [[ L Ys Dame.L
As YDames and Lengths Y <rom 'mp K
Oragle 10 g Material
32
"Fl P "elect Initcap( 'name ! ( =ob from 'mp ,here Length ( =ob ! \ 7 K
"Fl P "elect Inticap ( 'name ! ( =ob <rom 'mp ,here "ubstr ( =ob( 3( Length (
"ubstr ( =ob( 3( 1 ! ! ! \ LA)'S K
INSTRING F5*ct"%* :
It returns the numeric position of a named character.
S&*ta6 : INSTR ( Column C 'pression( Char ( n( m !
"earches for Column C 'pression beginning %ith its L n Lth character for the L m Lth occurrence of
char0( and returns the position of the character in char/( that is the first character of this
occurrence.
L n L can be positive or negative( if negative searches bac+%ard from the end of column C
'pression.
The value of L m L should be positive .
The default values of both m and n are /.
The return value is relative to the beginning of char/ regardless of the value of n( and is
epressed in characters.
If the search is unsuccessful( the return value is 2ero.
"Fl P "elect Instr ( L"tringS ( LrS! <rom -ual K
"Fl P "elect Instr ( LCO&PO&AT' <OO&S( LO&S( 1( 0 ! <rom -ual K
"Fl P "elect Instr ( LCO&PO&AT' <LOO&S( LO&S( G1( 0 ! <rom -ual K
"Fl P "elect =ob( Instr ( =ob( LAS( /( 0! <rom 'mp ,here =ob \ L6ADA)'&S K
"Fl P "elect =ob( Instr ( =ob( LAS( 0( 0 ! <rom 'mp ,here =ob \ L6ADA)'&S K
"Fl P "elect =ob( Instr ( =ob( LAS( 1( 0 ! <rom 'mp ,here =ob \ L6ADA)'&S K
"Fl P "elect =ob( Instr ( =ob( LAS( 0 ! <rom 'mp ,here =ob \ L6ADA)'&S K
LPAD F5*ct"%* :
Pads the character value right #ustified to al total %idth of n character positions.
The default padding character is space.
S&*ta6 : LPAD ( Char/( n( Char 0 !
"Fl P "elect Lpad ( LPage /S( /4( LH.S ! <rom -ual K
"Fl P "elect Lpad ( LPage /S( /4! <rom -ual K
"Fl P "elect 'name( Lpad ('name( />( LGL ! from 'mp ,here "al P \ 04>> K
RPAD F5*ct"%* :
Pads the character value left #ustified to a total %idth of n character positions.
The -efault padding character is space.
Oragle 10 g Material
33
S&*ta6 : RPAD ( Char/( n( Char 0 !
"Fl P "elect &pad ( LPage /S ( /4( LH.S ! <rom -ual K
"Fl P "elect &pad ( LPage /S ( /4 ! <rom -ual K
"Fl P "elect 'name( &pad('name( />( LGL ! <rom 'mp ,here "al P \ 04>> K
"Fl P "elect 'name( Lpad ( 'name( />( LGL ! ( &pad ( 'name( />( LGL ! <rom 'mp K
"Fl P "elect 'name( Lpad ( &pad ( 'name( />( LGL !( /4( LGL ! <rom 'mp K
LTRIM F5*ct"%* :
It enables to trim heading characters from a character string.
All the leftmost characters that appear in the set are removed.
S&*ta6 : LTRIM ( Char( set !
"Fl P "elect Ltrim ( Ly2AyLA"T ,O&-S( LyS ! <rom -ual K
"Fl P "elect =ob( Ltrim ( =ob ! <rom 'mp ,here =ob Li+e L6ADA)'&S K
RTRIM F5*ct"%* :
It enables the trimming of trailing characters from a character "tring.
All the right most characters that appear in the set are removed.
S&*ta6 : RTRIM ( Char( set !
"Fl P "elect &trim ( L*&O,DID)yAyS( LyS ! <rom -ual K
"Fl P "elect &trim ( =ob( L'&S ! ( =ob <rom 'mp ,here Ltrim ( =ob ( L6ADS ! Li+e L)'&S K
TRIM F5*ct"%* ( ; " )
It enables to trim heading or trailing characters or both from a character string.
If Lea3"*g is specified concentrates on leading characters.
If Tra""*g is specified concentrates on trailing characters.
If '%t@ or none is specified concentrates both on leading and trailing.
&eturns the varchar0 type.
S&*ta6 : TRIM ( Leading C Trailing C *oth( Trim character <rom Trim source !
"Fl P "elect Trim ( L"S <rom L6ITI""S ! <rom -ual K
"Fl P "elect Trim ( L"S <rom L""6ITIS ! <rom -ual K
"Fl P "elect Trim ( L"S <rom L""6ITI""S ! <rom -ual K
"Fl P "elect Trim ( Trailing L"S <rom L""6ITI""S ! <rom -ual K
"Fl P "elect Trim ( Leading L"S <rom L""6ITI""S ! <rom -ual K
Oragle 10 g Material
34
"Fl P "elect Trim ( *oth L"S <rom L""6ITI""S ! <rom dual K
REPLACE F5*ct"%* :
It returns the every Occurrence of search string replaced by the replacement string.
If the replacement string is omitted or null( all occurrences of search string are removed.
It substitutes one string for another as %ell as to remove character strings.
S&*ta6 : REPLACE ( Char( "earchR"tr( &eplaceR"tr !
"Fl P "elect &eplace ( L=ac+ and =ueS ( L=S( L*LS! <rom -ual K
"Fl P "elect 'name( &eplace(=ob( L6ADS( L-A6S ! <rom 'mp ,here =ob \ L6ADA)'&S K
"Fl P "elect =ob( &eplace ( =ob( LPS ! <rom 'mp ,here =ob \ LP&'"I-'DTS K
"Fl P "elect =ob( &eplace ( =ob( L6ADS( L'A'C@TI$'S ! <rom 'mp ,here
=ob \ L"AL'" 6ADS K
TRANSLATE F5*ct"%* :
@sed to Translate Character by character in a "tring .
S&*ta6 : TRANSLATE ( char( <rom( To !
It returns a char %ith all occurrences of each character in L <rom L replaced by its corresponding
character in L To L.
Characters in char that are not in <rom are not replaced.
The argument <rom can contain more characters than To.
If the etra characters appear in Char( they are removed from the return value.
"Fl P "elect =ob( Translate ( =ob( LPS( L L ! <rom 'mp ,here =ob \ LP&'"I-'DTS K
"Fl P "elect =ob( Translate ( =ob( L6DS( L-6S ! <rom 'mp ,here =ob \ L6ADA)'&S K
"Fl P "elect =ob( Translate ( =ob( LAS( LOS ! <rom 'mp ,here =ob \ L"AL'"6ADS K
CHR F5*ct"%* :
It returns a character having the binary eFuivalent to L n L.
It returns the eFuivalent for L nS in database character set or national character set.
S&*ta6 : CHR ( n ! CHR ( n @sing DCIA&RC" !
"Fl P "elect Chr ( 57 ! [[ Chr (54 ! [[ Chr ( 83 ! "ample <rom -ual K
"Fl P "elect Chr ( /57>4 @sing DCIA&RC" ! <rom -ual K
ASCII F5*ct"%* :
Oragle 10 g Material
35
It returns the decimal representation in the character database set of the first characters of the
Char.
S&*ta6 : ASCII ( Char !
"Fl P "elect Ascii ( LAS ! ( Ascii ( LAPPL'S! <rom -ual K
NUM'ER F5*ct"%*s :
These functions accept numeric input and return numeric values.
6any functions return values that are accurate to 18 decimal digits.
ROUND F5*ct"%* :
S&*ta6 : ROUND ( n( m !
It returns L n L rounded to n places right of the decimal point.
If L mS is omitted( n is rounded to >( places
L m L can be negative( and rounds off the digits to the left of the decimal point.
6 must be an integer.
"Fl P "elect &ound ( /4./91( / ! <rom -ual K
"Fl P "elect &ound ( /4./91( G/ ! <rom -ual K
"Fl P "elect &ound ( 34901( 0 ! ( &ound ( 34.901( > ! ( &ound ( 34(901( G/ ! <rom -ual K
TRUNCATE F5*ct"%* :
S&*ta6 : TRUNC ( n( m !
It returns n truncated to m decimal places.
If L m L is omitted( n is truncated to > places.
L n L can be negative to truncate m digits left to the decimal point.
"Fl P "elect Trunc ( /4.79( /! <rom -ual K
"Fl P "elect Trunc ( /4.79( G/ ! <rom -ual K
"Fl P "elect Trunc ( 34.901( 0 ! ( Trunc ( 30.901 !( Trunc ( 34.901( G/ ! <rom -ual K
CEIL F5*ct"%* :
S&*ta6 : CEIL ( n !
&eturns the smallest integer greater than or eFual to L n L .
The ad#ustment is done to the highest nearest decimal value.
"Fl P "elect Ceil ( /4.7 ! <rom -ual K
"Fl P "elect Ceil ( /3.07 ! ( Ceil ( /3.0 ! ( Ceil ( /3 ! <rom -ual K
FLOOR F5*ct"%* :
Oragle 10 g Material
36
S&*ta6 : FLOOR ( n !
&eturns the largest integer less than or 'Fual than n .
The ad#ustment is done to the lo%est nearest decimal values.
"Fl P "elect <loor ( /4.7 ! <rom -ual K
"Fl P "elect <loor ( /3.07 ! ( <loor ( /3.0 ! ( <loor ( /3 ! <rom -ual K
MODULUS F5*ct"%* :
S&*ta6 : MOD ( m( n !
It returns remainder m divided by n .
It returns m if n is >.
"Fl P "elect 6od ( //( 3 ! ( 6od ( /> ( 0 ! <rom -ual K
POWER F5*ct"%* :
S&*ta6 : POWER ( m( n !
&eturns m raised to the nth po%er.
The base m and the eponent n can be any numbers.
If m is negative( n must be an integer
"Fl P "elect Po%er ( 1( 0 !( Po%er ( G1( 0 ! <rom -ual K
"Fl P "elect Po%er ( 1( G0 ! ( Po%er ( G1( G0 ! <rom -ual K
"Fl P "elect Po%er ( G1.4( G0 !( Po%er ( 1( G0.4 ! <rom -ual K
"Fl P "elect Po%er ( G1.4( 0.4 ! ( Po%er ( 1.4( G0.4 ! <rom -ual K
S,UARE ROOT F5*ct"%* :
S&*ta6 : S,RT ( n !
It returns sFuare root of n.
The value of n cannot be negative
"E&T returns a real result.
"Fl P "elect "Frt ( 04 ! <rom -ual K
A'SOLUTE F5*ct"%* :
S&*ta6 : A'S ( n !
It returns the absolute value of n.
"Fl P "elect Abs ( G/4 ! <rom -ual K
"Fl P "elect "al( Comm( "al J Comm( Abs ( "al J Comm ! <rom 'mp
,here Comm \ /3>> K
Oragle 10 g Material
37
SIGN F5*ct"%* :
S&*ta6 : SIGN ( n !
It returns the "I)D( specification of a number.
If n Q > ( return J/
If n \ > ( return >
If n P >( return /
"Fl P "elect "ign ( G/4 !( "ign ( /4 ! ( "ign ( > ! <rom -ual K
"Fl P "elect "al( Comm( "ign( "al J Comm ! <rom 'mp ,here "ign( "al J Comm ! \ G/
WOR<ING WITH DATES :
Oracle stores dates in an internal numeric format.
The dates in Oracle range from =anuary /( 37/0 *C to -ecember 1/( 9999 A-.
The default display and input format for any date is --G6ODG??.
The numeric format represents
HH Century HH ?ear HH 6onth HH -ay HH Iours
HH 6inutes HH "econds
S!SDATE :
It is a date function that returns current date and time .
"?"-AT' is generally selected upon a -@66? Table.
"Fl P "elect "?"-AT' <rom -ual K
Date Ar"t@$et"c :
As database stores dates as numbers( Arithmetic operations can be implemented.
Dumber constants can be added or subtracted upon dates.
The operations that can be applied are
o Date : Dumber -ate K Adds number of days to a date
o Date G Dumber -ate B "ubtracts Dumber of days from a date.
o Date 7 -ate Dumber of days K "ubtracts one date from another.
o Date P Dumber C 03 -ate K Adds Dumber of Iours to a date.
"Fl P "elect "ysdate( "ysdate : 1 <rom -ual K
"Fl P "elect "ysdate( "ysdte J 1 ( "ysdate :R 70 C 03 <rom -ual K
"Fl P "elect 'name( Iiredate( Iiredate : 1 <rom 'mp K
"Fl P "elect 'name( Iiredate( Iiredate J 1 <rom 'mp K
"Fl P "elect 'name( Iidrdate( "ysdate J Iiredate <rom 'mp K
Oragle 10 g Material
38
"Fl P "elect 'name( ( "ysdate J Iiredate ! C 7 ,ee+s <rom 'mp ,here -eptno \ /> K
DATE F5*ct"%*s :
A33QM%*t@s F5*ct"%* :
S&*ta6 : A--R6ODTI" ( -( n !
It returns the date d plus n months
The argumennt n can be any integer
"Fl P "elect "ysdate ( AddRmonths ( "ysdate( 0 ! <rom -ual K
"Fl P "elect "al(l Iiredate( AddRmonths ( Iiredate( 0 ! <rom 'mp ,here
-eptno \ 0> K
M%*t@sQ'etBee* F5*ct"%* :
S&*ta6 : M%*t@sQ'etBee* ( D1F D8 )
It returns number of months bet%een dates d/ and d0.
If d/ is later than d0( the result is Positive( else Degative.
If d/ is and d0 are either the same days of the months or both last days of the months(
the result is al%ays an integer.
"Fl P "elect 'mpno( Iiredate( 6onthsR*et%een ( "ysdate ( Iiredate ! <rom 'mp
,here 6onthsR*et%een ( "ysdate( Iiredate ! Q 0>>> K
"Fl P "elect 'name( 6onthsR*et%een ( "ysdate ( Iiredate ! <rom 'mp K
Ne6tQDa& F5*ct"%*:
S&*ta6 : Ne6tQ3a&( 3F C@ar )
It returns the date of the first %ee+ day named by char( that is later than the date d.
The CIA& must be a day of the %ee+ in the sessions date language.
The day of the %ee+ can be full name or the abbreviation.
"Fl P "elect "ysdate( DetRday ( "ysdate( L,'-S ! <rom -ual K
"Fl P "elect "al( Iiredate( DetRday ( Iiredate( L6OD-A?S ! <rom -ual K
LastQDa& F5*ct"%* :
S&*ta6 : LastQ3a& ( d !
It returns the date of the last day of the month that contains d.
6ostly used to determine ho% many days are left in the current month .
"Fl P "elect "ysdate( LastRday ( "ysdate ! Last( LastRday ( "ysdate ! J "ysdate
-aysleft <rom -ual K
R%5*3"*g %# Dates :
Oragle 10 g Material
39
S&*ta6 : R%5*3 ( -ate( L<ormatS !
&eturns -ate rounded to the @nit specified by the format.
If format is omitted( -ate is rounded to the nearest day.
"Fl P "elect &ound ( "ysdate ( L-A?S ! <rom -ual K
"Fl P "elect &ound ( "ysdate( L6ODTIS ! <rom -ual K
"Fl P "elect &ound ( "ysdate ( L?'A&S ! <rom -ual K
Tr5*cat"*g Dates :
S&*ta6 : Tr5*c ( -ate( L<ormatS !
&eturn -ate %ith the time portion of the day truncated to the specified unit.
If format is omitted( date is truncated to the nearest day.
"Fl P "elect &ound ( "ysdate( L-A?S ! ( Trunc ( "ysdate( L-A?S ! <rom -ual K
"Fl P "elect &ound ( "ysdate( L6ODTIS !( Trunc ( "ysdate( L6ODTIS ! <rom -ual K
"Fl P "elect &ound ( "ysdate( L?'A&S ! ( Trunc ( "ysdate( L?'A&S ! <rom -ual K
C%*=ers"%* F5*ct"%*s :
The Conversion functions convert a value from one data type to another .
The -ata type conversion in Oracle is of t%o types
HH Implicit -ata type Conversion
HH 'plicit -ata type Conversion
I$p"c"t Data t&pe C%*=ers"%* :
Implicit -ata type Conversions %or+ according to the conversion specified by Oracle.
The assignment succeeds if the Oracle serves can convert the datatype of the value.
CIA& to D@6*'& Conversions succeed only if the character strings represents a valid
D@6*'&.
CIA& to -AT' Conversions succeed only if the character strings represent the default
format --G6ODG??.
IN ASSIGNMENTS IN E1PRESSIONS
- $archar0 C Char Dumber H $archar0C Char Dumber
H $archar0 C Char -ate H $archar0 C Char -ate
H Dumber $archar0
- -ate $archar0
E6p"c"t Data t&pe C%*=ers"%* :
Oragle 10 g Material
40
"EL provides three functions to convert a value from one data type to another.
The <unctions are
H ToRChar <or Conversion to Characters
H ToR-ate <or Conversion to -ates
H ToRDumber <or Conversion to Dumbers
T%QC@ar C%*=ers"%* F5*ct"%* :
This function can be used in t%o different flavors
ToRChar ( Dumber Conversion !
ToRChar ( -ate Concersion !
T%QC@ar ( Dumber Conversion ! B
S&*ta6 : T%Qc@ar ( Dumber ( fmt( LnlsparmsS !
o Converts number of number data type to a value of $archar0 data type.
o <mt is the optional number format( that can be used.
o The LnlsparmsS specifies the characters returned by the number format elemtns.
T%QC@ar ( -ate Conversion ! B
S&*ta6 : T%QC@ar ( -ate( fmt( LnlsparamsS !
Converts -ate of -AT' data type to a value of $archar0 data type in the format
specified.
<mt is the optional date format( that can be used.
The nlsparams specifies the language in %hich month and day names and
abbreviations are returned.
F%r$att"*g M%3es :
A formatting model is a character literal that describes the format of -AT' or Dumber data stored
in a character string.
D >>D>> B
o It returns the specified position of the decimal character.
o The default decimal delimites is a period ( . !
o Only one decimal character can be specified in a number format model.
"Fl P "elect ToRchar ( /013( L99999-99S ! <rom -ual K
"Fl P "elect ToRchar ( /013( L999-99S ! <rom -ual K
EEEE >:>EEEE :
o &eturns a value using scientific notation.
Oragle 10 g Material
41
"Fl P "elect ToRchar ( /013 ( L9.9''''S ! ( ToRchar ( /013( L9.99''''S ! <rom -ual K
G >G>>> :
o &eturns the specified position of the group separator
o 6ultiple group separators can be specified.
"Fl P "elect ToRchar ( /013457( L99)99)999S ! <rom -ual K
"Fl P "elect "al( ToRchar ( "al( L99)999-99S ! <rom 'mp K
L L>>> :
o &eturns the specified position of the local currency symbol.
"Fl P "elect ToRchar ( /013( LL9999S! <rom -ual K
"Fl P "elect "al( ToRchar ( "al( LL999999S ! Currency <rom 'mp ,here -eptno \ /> K
"Fl P "elect "al( ToRchar ( "al( LL99)999-99S( LDL"RC@&&'DC? \ Ind&upeesS !
"alary <rom 'mp ,here -eptno \ 0> K
MI >>>>MI :
o &eturns Degative value %ith a trailing minus sign ( G !.
o &eturn Positive value %ith a trailing blan+.
o 6I format should be declared as trailing argument only.
"Fl P "elect ToRchar ( G/>>>>( LL99)999-996IS ! <rom -ual K
"Fl P "elect "al( Comm( CommRsal( ToRchar ( Comm J "al ( LL999996IS ! <rom 'mp
,here -eptno in(/>( 0>( 1> ! K
PR >>>>PR :
o &eturns Degative value in Q angle *rac+ets P
o It can appear only as trailing declaration.
"Fl P "elect ToRchar ( G/>>> ( LL99)999-99P&S ! <rom -ual K
"Fl P "elect "al( Comm( Comm J "al ( ToRchar ( Comm J "al ( LL99999P&S ! <rom 'mp
RN Returns a value as &oman Dumber in @pper Case
r* Returns a value as &oman Dumber in Lo%er Case
The $alue can be an integer bet%een / and 9999.
"Fl P "elect ToRchar ( />>> ( L&DS ! ( ToRchar ( />>>( LrnS ! <rom -ual K
"Fl P "elect "al( ToRchar ( "al( L&nS ! ( ToRchar ( "al( LrnS ! <rom 'mp K
S >>>>> :
o &eturns negative value %ith a leading minus sign
Oragle 10 g Material
42
o &eturns positive value %ith a leading plus sign
o >>>>S :
o &eturns negative value %ith trailing minus sign.
o &eturns positive value %ith a trailing plus sign.
" can appear as first or last $alue.
"Fl P "elect ToRchar ( />>>( L"9999S !( ToRchar ( G/>>>( L"9999S ! <rom -ual K
"Fl P "elect toRchar ( />>>( L9999"S ! ( ToRchar ( G/>>>( L9999"S ! <rom -ual K
"Fl P "elect "al( ToRchar ( "al( L"99999S ! ( ToRchar ( "al( L99999"S ! <rom 'mp K
"Fl P "elect "al( Comm( ToRchar ( Comm G "al( L"99999S ! ( ToRchar ( Comm J "al (
L99999"S! <rom 'mp K
1 1111 :
6666 :
o &eturns the headecimal value of the specified number of digits.
o If the number is not an integer( Orcle rounds it to an integer.
o Accepts only positive values or >.
"Fl P "elect ToRchar(/>>>( LAAAAS! <rom -ual K
"Fl P "elect "al( ToRchar ( "al( LAAAAAS ! <rom 'mp K
F ( C%$$a ) >F>>> :
o &eturns a comma in the specified position.
o 6ultiple commas can be specified.
"Fl P "elect ToRchar ( />>>>( S99(999-99S ! <rom -ual K
"Fl P "elect "al( ToRchar ( "al( S99(999-99S ! <rom 'mp K
: ( Per"%3 ) >>:>> :
o &eturns a decimal point( at the specified position.
o Only one period can be specified in a number format model.
"Fl P "elect ToRchar ( />>>>( LL99(999.99S ! from -ual K
"Fl P "elect ToRchar ( "al( LL99(999.99S ! <rom 'mp K
R R>>>> :
o &eturns value %ith a leading -ollar "ign.
"Fl P "elect ToRchar ( />>>>( LN99(999.99S ! <rom -ual K
Oragle 10 g Material
43
"Fl P "elect "al( ToRchar ( "al( LN99(999.99S ! <rom 'mp K
0 ( Oer% ) 0>>> :
o &eturns leading Meros.
>>>0 :
&eturns Trailing Meros.
"Fl P "elect ToRchar ( />>>( L>999999S ! ( ToRchar ( />>>( L>999999>S ! <rom -ual K
"Fl P "elect "al( ToRchar( "al( LN>99(999.99S ! <rom 'mp K
> >>>> :
o &eturn value %ith a specified number of digits %ith a leading space %hen positive or
leading minus %hen negative.
"Fl P "elect ToRchar ( />>> J 5>> ( L99999S ! ( ToRchar( 5>> J />>> ( L99999S !
<rom -ual K
"Fl P "elect ToRchar ( 0>.04 J 0>( L99999S ! <rom -ual K
C C>>>> :
o &eturns specified position of the I"O Currency "ymbol.
"Fl P "elect ToRchar ( />>>( LC9999.99S ! <rom -ual K
"Fl P "elect "al( ToRchar ( "al( LC9999.99S ! <rom 'mp K
Date F%r$at M%3es :
The -ate format models can be used in the ToRchar function to translate a -AT' value from
original format to user <ormat .
The total length of a date format model cannot eceed 00 characters.
Date F%r$at Ee$e*ts :
A date format model is composed of one or more date format elements.
o <or input format models( format items cannot appear t%ice( and format items that
represent similar information cannot be combined.
Capitali2ation in a spelled out %ord( abbreviation( or &oman numeral follo%s capitali2ation in the
corresponding format element.
Punctuation such as hyphens( slashes( commas( periods and colons.
AD %r A:D: + 'C %r ':C: :
Oragle 10 g Material
44
o Indicates A- C *C %ith or ,ithout periods.
"Fl P "elect ToRchar ( "ysdate( LA-S! <rom -ual K
"Fl P "elect ToRchar ( "ysdate( L*.C.S! ( ToRchar ( "ysdate( LA.-.S ! <rom -ual K
"Fl P "elect "al( Iiredate( ToRchar ( Iiredate( LA.-.S ! <rom 'mp K
AM %r A:M: + PM %r P:M: :
o It indicates 6eridian Indicator %ith or %ithout periods.
"Fl P "elect ToRchar ( "ysdate( LA.6.S ! ( ToRchar ( "ysdate( LP6S! <rom -ual K
"Fl P "elect "al( Iiredate( ToRchar ( Iiredate( LA6S ! <rom 'mp K
CC + SCC :
o Indicates the century ( " prefies *C date %ith J
"Fl P "elect ToRchar ( "ysdate( L"CCGA-S ! <rom -ual K
"Fl P "elect "al( Iiredate( ToRchar ( Iiredate ( L"CCGA-S! <rom 'mp K
D -ay of the ,ee+ ( / J 7 !
"Fl P "elect ToRchar ( "ysdate( L-S ! <rom -ual K
"Fl P "elect Iiredate( ToRchar ( Iiredate( L-S ! <rom 'mp K
Da& Indicates spelled name of the ,ee+ -ay.
o Pads to a length of 9 Characters.
"Fl P "elect ToRchar ( "ysdate( L-A?S ! <rom -ual K
"Fl P "elect "al( Iiredate( ToRchar ( Iiredate( L-A?S! <rom 'mp ,here
ToRchar ( Iiredate( L-A?S! \ L,'-D'"-A?S K
DD It Indicates The -ay of the 6onth ( / J 1/ !
"Fl P "elect ToRchar("ysdate(S--G-A?S! from -ual K
"Fl P "elect Iiredate( ToRchar ( Iiredate(S--G-A?S ! <rom 'mp K
"Fl P "elect Iiredate( ToRchar ( Iiredate( S--G-A?S ! <rom 'mp ,here
ToRchar ( Iire-ate. S--G-A?S! \ S>1G,'-D'"-A?S K
H-A? "pecifies in @pper Casing.
H-A? "pecifies in Initcap Casing.
H-A? "pecifies in Lo%er Casing.
DDD It indicates the -ay of the ?ear ( / J 155 !
Oragle 10 g Material
45
"Fl E "elect "ysdate ( ToRchar("ysdate( S---S ! <rom -ual K
"Fl P "elect 'name( Iiredate ( ToRchar ( Iiredate( S---S ! <rom 'mp
,here ToRchar ( Iiredate( S-A?S ! \ S,'-D'"-A?S K
D! It indicates the abbreviated name of the day.
"Fl P "elect "ysdate ( ToRchar ("ysdate( S-G-?G-A?S ! <rom -ual K
"Fl P "elect 'name( Iiredate( ToRchar ( Iiredate( S-G-?G-A?S ! from 'mp
,here -eptno in( /> ( 0> ! K
IW "pecifies the %ee+ of the year ( / G 40 or / J 41 !based on the I"O "tandard.
"Fl P "elect "ysdate( Iiredate( ToRchar ( "ysdate( LI,S ! <rom -ual K
"Fl P "elect 'name( Iiredate( ToRchar ( Iiredate( LI ,S ! <rom -ual K
I!!! "pecifies 3 -igit year based on the I"O "tandard .
I!!
I!
"Fl P "elect "ysdate( ToRchar ( "ysdate( LI???S ! <rom -ual K
"Fl P "elect 'name( Iiredate( ToRchar ( Iiredate( LI???S ! <rom 'mp ,here
ToRchar ( Iiredate( L-A?S ! \ L,'-D'"-A?S ! K
!!!! + S!!!! &eturns <our -igit year( L"S Prefies *C dates %ith L J L .
!!! + !! + !
! F !!! &eturns year %ith comma in this position.
"Fl P "elect "ysdate( ToRchar ( "ysdate( L????S ! <our( ToRchar ( "ysdate( L???S !
Three ( ToRchar ( "ysdate( L?(???S ! Comma <rom -ual K
"Fl P "elect 'name( Iiredate( ToRchar ( Iiredate( L????S ! <rom 'mp
,here -eptno \ 0> K
!EAR + S!EAR &eturns the spelled out year.
"Fl P "elect "ysdate( ToRchar ( "ysdate( L?'A&S ! <rom -ual K
"Fl P "elect 'name( Iiredate( ToRchar ( Iiredate( L?'A&S ! <rom 'mp K
W "pecified the %ee+ of the 6onth ( / J 4 !. ,ee+ starts on the first day of the
6onth and ends on the seventh.
"Fl P "elect "ysdate( ToRchar ( "ysdate( L,S ! <rom -ual K
"Fl P "elect 'name( Iiredate( ToRchar ( Iiredate( L,S! <rom 'mp K
WW "pecifies the %ee+ of the ?ear ( / J 41 ! . ,ee+ / "tarts on the first day of the year and
continues to the seventh day of the year.
Oragle 10 g Material
46
"Fl P "elect "ysdate( ToRchar ( "ysdate( L,,S ! <rom -ual K
"Fl P "elect 'name( Iiredate( toRchar ( Iiredate( L,,S ! <rom 'mp K
, &eturns the Euarter of the ?ear.
"Fl P "elect "ysdate( ToRchar ( "ysdate( LES ! <rom -ual K
"Fl P "elect 'name( Iiredate( ToRchar ( Iiredate( LES ! <rom 'mp ,here
ToRchar ( Iiredate( LES ! \ 3 K
. &eturns the =@LIAD -A?.
i. It is the Dumber of days since =anuary /( 37/0 *C.
ii. Dumbers specified %ith L=S must be integers.
"Fl P "elect "ysdate( ToRchar ( "ysdate( L=S ! <rom -ual K
"Fl P "elect 'name( ToRchar ( Iiredate( L=G---G--G--S ! <rom 'mp K
MM returns the digit numeric abbreviation of the 6onth.
"Fl P "elect "ysdate( ToRchar ( "ysdate( L66G????S ! <rom -ual K
"Fl P "elect 'name( Iiredate( ToRchar ( Iiredate( L66G????S ! <rom 'mp ,here
ToRchar ( Iiredate ( L66S ! \ /0 K
MON &eturns the Abbreviated Dame of the 6onth.
"Fl P "elect "ysdate( ToRchar ( "ysdate( L66G6ODS ! <rom -ual K
MONTH "pells the Dame of the 6onth( padded to a length of 9 characters .
"Fl P "elect "ysdate( ToRchar ( "ysdate( L6ODG6ODTIS ! <rom -ual K
"Fl P "elect 'nbame( Iiredate( ToRchar ( Iiredate( L6ODTI( ????S ! <rom 'mp K
HH + HH18 &eturns the Iour of the day in t%elve hour cloc+ mode.
"Fl P "elect "ysdate( ToRchar ("ysdate( LIIS !( ToRchar ("ysdate( LII/0( A6S !
<rom -ual K
"Fl P "elect 'name( Iiredate ( ToRchar ( Iiredate( LII/0 B A6S ! <rom 'mp K
HH8A &eturns the Iour of the day in t%enty four hour cloc+ mode . ( > J 01 !
"Fl P "elect "ysdate( ToRchar ( "ysdate( LII03S ! <rom -ual K
MI &eturns the 6inutes from the given date ( > J 41 ! .
"Fl P "elect "ysdate( ToRchar ( "ysdaste( L6IS !( ToRchar ( "ysdate( LIIB6IS ! <rom -ualK
"Fl P "elect 'name( "al( ToRchar ( Iiredate( LIIB6IS ! <rom 'mp ,here =ob\LCL'&;S K
Oragle 10 g Material
47
RM &eturns the &oman Dumeral 6onth ( I J AII ! .
"Fl P "elect "ysdate( ToRchar ( "ysdate( Y&6Z ! ( ToRchar ( "ysdate(
L--G&6G??S ! <rom -ual K
"Fl P "elect 'name( "al(. ToRchar ( Iiredate( L--G&6G??S ! <rom 'mp K
SS &eturns "econds from the given date ( > J 49 !
"Fl P "elect "ysdate( ToRchar ( "ysdate( L""S !( ToRchar ( "ysdate( LIIB6IB""S !
<rom -ual K
"Fl P "elect "ysdate( ToRchar ( "ysdate( L--G6ODTIG????( IIB6IB"" A.6.S !
<rom -ual K
"Fl P "elect 'name( "al( Iiredate( ToRchar ( Iiredate( LII03B6IB""S ! <rom 'mp
,here -eptno In( />( 1> ! K
SSSS -isplay "econds past 6idnight ( > J 85199 ! .
"Fl P "elect "ysdate( ToRchar ( "ysdate( L""""S ! <rom -ual K
"Fl P "elect 'name( Iiredate( ToRchar ( Iiredate( L--G66G??( IIB6IB""( """"S !
<rom 'mp K
The Punctuation mar+s that can be used in -ate formats are
D H + H S H : H H H : H Nte6tT
RR Date F%r$at Ee$e*t :
The && date <ormat element is similar to the ?? date format element.
The && format element provides additional fleibility for storing date values in other
Centuries.
The && date format element allo%s to store the date to the previous as %ell as the net
Centuries .
If the Last 0 -igits of The Current ?ear are B
0 D A> U0 D >>
0 D A> Returns date is in the The return date is in the
Current Century. Preceding Century .
U0 D >> The return date is in The return date is in the
t@e net Century Current Century .
Date F%r$at Ee$e*t S5##"6es :
o TH "pecifies the Ordinal Dumber
E6 : DDTI 80
TH
"Fl P "elect "ysdate( ToRchar ( "ysdate( L--TI( 6ODTI( ????S ! <rom -ual K
Oragle 10 g Material
48
"Fl P "elect 'name( "al( Iiredate( ToRchar ( Iiredate( L--TI( 6ODTI( ????S !
<rom 'mp K
o SP "pells Dumbers.
E6 B L--"P T,'DT?
"Fl P "elect "ysdate( ToRchar ( "ysdate( L--"P ( 6ODTI( ????S ! <rom -ual K
"Fl P "elect 'name( "al( ToRchar ( Iiredate( L--"P( 6ODTI( ????S ! <rom 'mp K
o "pelled( Ordinal Dumber
' B --"PTI T,'DTI'TI
"Fl P "elect "ysdate( ToRchar ( "ysdate( L--"PTI( 6ODTI( ????S ! <rom -ual K
"Fl P "elect 'name( "al( ToRchar ( Iiredate( L--"PTI( 6ODTI( ????S ! <rom 'mp K
"Fl P "elect "ysdate( ToRchar ( "ysdate( L--"PTI 6ODTI ????"PS ! <rom -ual K
Date F%r$at Ee$e*ts Restr"ct"%*s :
o The suffies %hen added to date return value al%ays in 'nglish.
o -ate suffies are valid only on output( hence cannot be used to insert a date into the
database.
F%r$at M%3e M%3"#"ers :
o FM Y <ill 6ode Y( It suppresses blan+ padding in the return value of the
ToRchar <unction.
o F1 Y <ormat 'act Y ( It specifies eact matching for the character argument
and date format model.
"Fl P "elect "ysdate( ToRchar ( "ysdate( L--"PTI 6ODTI ????"PS ! (
ToRchar ( "ysdate( L<6--"PTI 6ODTI ????"PS ! <rom -ual K
TOQNUM'ER F5*ct"%* :
S&*ta6 : T%QN5$ber ( C@arF #$tF N*spara$T )
o It Converts a char( value of CIA& or $A&CIA&0 data type containing a Dumber in the
format specified by the optional format model fmt( to a value of D@6*'& data type .
"Fl P "elect ToRnumber ( LN/>(>>>.>>S( LL99(999.99S ! <rom -ual K
"Fl P "elect ToRnumber ( LN/(>>>.>>S( LL9(999.99S ! : 4>> <rom -ual K
Oragle 10 g Material
49
TOQDATE F5*ct"%* :
S&*ta6 : T%QDate ( C@arF #$tF N*spara$T )
o Converts char of CIA& or $A&CIA&0 datatype to a $alue of -AT' data type .
o The fmt is a date format specifying the format of char.
"Fl P "elect 'name( Iiredate( A--R6ODTI" ( ToRchar ( S/7G-'CG/98>S(
L--G6ODG??S ! ( 1 ! <rom 'mp ,here Iiredate \ S/7G-'CG/98>S K
Spec"#"cat"%*a E6a$pes :
"Fl P "elect ToRchar ( A--R6ODTI" ( Iiredate( / !( L--G6ODG????S !
YD'AT 6ODTIZ <rom 'mp ,here 'name \ L"6ITIS K
"Fl P "elect Concat ( Concat ( 'name( Lis aS!( =ob ! -esignation <rom 'mp
,here 'mpno \ 79>> K
"Fl P "elect Trunc( ToR-ate ( S07GOCTG90S ( L--G6ODG??S !( L?'A&S ! YD', ?'A&Z
<rom -ual K
"Fl P "elect ToRchar ( A--R6ODTI"( LA"TR-A? ( Iiredate ! ( 4 !( L--G6ODG????S !
Y<I$' 6ODTI"Z <rom 'mp ,here 'name \ L6A&TIDS K
"Fl P "elect 6onthsR*et%een ( ToR-ate ( S>0G>0G/994S ( L66G--G????S !(
ToR-ate ( S>/G>/G/994S( L66G--G????S ! ! 6ODTI" <rom -ual K
"Fl P "elect DetR-ay ( S/4G6A&G98S( LT@'"-A?S ! Y Det -ay Y <rom -ual K
"Fl P "elect 'name( D$L ( ToRChar ( Comm! ( L Dot Applicable L ! Y Commission Z
<rom 'mp ,here -eptno \ 1> K
"Fl P "elect &ound ( ToR-ate ( S07GOCTG90S ( L?'A&S ! Y De% ?ear Y <rom -ual K
"Fl P "elect ToRChar ( Iiredate ( L6ODTI -- ????S ! <rom 'mp ,here
'name \ L*LA;'S K
"Fl P "elect 'name( ToRchar ( Iiredate( Lfm 6onth --( ????S ! ( Iiredate <rom
'mp ,here -eptno \ 0> K
"Fl P "elect ToRchar ( ToR-ate ( S07GOCTG98S( L--G6ODG&&S !( L????S ! ?ear
<rom -ual K
"Fl P "elect ToRchar ( ToR-ate ( S07GOCTG/7S( L--G6ODG&&S !( L????S ! ?ear
<rom -ual K
o Ass5$pt"%* : Eueries Issued bet%een /94> J /999.
"Fl P "elect ToRchar ( ToR-ate ( S07GOCTG98S( L--G6ODG&&S !( L????S ! ?ear
<rom -ual K
"Fl P "elect ToRchar ( ToR-ate ( S07GOCTG/7S( L--G6ODG&&S ! ( L????S ! ?ear
<rom -ual K
o Ass5$pt"%* : Eueries Issued bet%een 0>>> J 0>39
Oragle 10 g Material
50
"Fl P "elect ToRchar ( "ysdate( Lfm --TIS ! [[ L of L [[ ToRchar ( "ysdate( L6onthS !
L ( L [[ ToRchar ( "ysdate( L????S ! Idea <rom -ual K
"Fl P "elect ToRchar ( "ysdate( Lfm-ayS ! [[ L Ys "pecial L ! Y 6'D@ Y <rom -ual K
"Fl P "elect 'name( =ob( D$L ( ToRchar ( 6gr !( L "upreme Authority L ! Y 6anagers Y
<rom 'mp Order *y "al -esc K
Aggregate %r Gr%5p F5*ct"%*s :
o These functions return a single ro% based on groups of ro%s.
o These functions can appear in "'L'CT lists and IA$ID) clauses.
o These functions operate on sets of ro%s to give one result per group.
o The sets may be the %hole table or the table split into groups.
G5"3e"*es t% 5se Gr%5p F5*ct"%*s :
o -I"TIDCT ma+es the function consider only non duplicate values.
o ALL ma+es the function to consider every value including duplicates.
S&*ta6 : Gr%5pQF5*ct"%*QNa$e ( -istinct C ALL C n !
o The data types for arguments may CIA&( $A&CIA&( D@6*'& O& -AT'.
o All group functions ecept CO@DT( H ! ignore D@LL values. To substitute a value for
D@LL values( use the D$L function.
o ,hen a group function is declared in a "'L'CT list ( no single ro% columns should be
declared.
o ,hen a group function is declared in a "'L'CT list( other columns can be declared( but
they should be grouped columns( and all the non functional columns should be declared
into a )&O@P *? clause.
A=erage F5*ct"%* :
S&*ta6 : A/G ( -I"TIDCT C ALL C n !
o It returns the Average $alue of n.
o It ignores D@LL values.
"Fl P "elect A$) ( "al ! ( A$) ( -I"TIDCT "al ! <rom 'mp K
"Fl P "elect A$) ( Comm ! ( A$) ( -I"TIDCT A$) ! <rom 'mp K
SUM F5*ct"%* :
S&*ta6 : SUM ( -I"TIDCT C ALL C n !
o It returns the "um of the values of n.
o It ignores D@LL values.
o
"Fl P "elect "um ( "al !( "um ( -I"TIDCT "al ! <rom 'mp K
"Fl P "elect "um ( Comm ! ( "um ( -I"TIDCT Comm ! <rom 'mp K
Oragle 10 g Material
51
MA1"$5$ F5*ct"%* :
S&*ta6 : MA1 ( -I"TIDCT C ALL C n !
o It ignores the 6aimum value of n.
o It ignores D@LL values.
"Fl P "elect 6a ( "al !( 6a ( -I"TIDCT "al ! <rom 'mp K
"Fl P "elect 6a ( Comm ! ( 6a ( -I"TIDCT Comm ! <rom 'mp K
MIN"$5$ F5*ct"%* :
S&*ta6 : MIN ( -I"TIDCT C ALL C n !
o It returns the 6inimum value of the n.
o It ignores D@LL values.
"Fl P "elect 6in ( "al ! ( 6in ( -I"TIDCT "al ! <rom 'mp K
"Fl P "elect 6in ( Comm !( 6in ( -I"TIDCT Comm ! <rom 'mp K
Sta*3ar3 De="at"%* F5*ct"%* :
S&*ta6 : STDDE/ ( -I"TIDCT C ALL C n !
o It returns the "tandard -eviation of the n.
o It ignores D@LL $alues.
"Fl P "elect "tddev ( "al ! ( "tddev ( -I"TIDCT "al ! <rom 'mp K
"Fl P "elect "tddev ( Comm !( "tddev ( -I"TIDCT Comm ! <rom 'mp K
/ar"a*ce F5*ct"%* :
S&*ta6 : /ARIANCE ( -I"TIDCT C ALL C n !
o It returns the $ariance of D.
o It ignores the D@LL values.
"Fl P "elect $ariance ( "al ! ( $ariance ( -istinct "al ! <rom 'mp K
"Fl P "elect $ariance ( Comm !( $ariance ( -I"TIDCT Comm ! <rom 'mp K
COUNT F5*ct"%* :
Oragle 10 g Material
52
S&*ta6 : COUNT ( H C -I"TIDCT C ALL C n !
o It returns the number of ro%s in the Fuery.
o D evaluates to something other than D@LL.
o It H is used returns all ro%s( including duplicated and D@LLs.
o It can be used to specify the count of all ro%s or only distinct values of n.
"Fl P "elect Count ( H ! <rom 'mp K
"Fl P "elect Count ( =ob ! ( Count ( -I"TIDCT =ob ! <rom 'mp K
"Fl P "elect Count ( "al ! ( Count ( Comm ! <rom 'mp K
"Fl P "elect Count ( 'mpno ! ( Count ( -I"TIDCT 6gr ! <rom 'mp K
Creat"*g Gr%5ps %# Data :
o The )roup *y Clause is used to decide the ro%s in a table into groups.
S&*ta6 : Seect C%5$*F GrpQF5* ( C%5$* )
Fr%$ Tabe
W@ere C%*3"t"%*
GROUP '! GrpQ'&QE6pr
Or3er '& C%5$* H
G5"3e"*es t% Use Gr%5p '& Ca5se :
If the )roup function is included in a "'L'CT clause( %e should not use individual results
columns.
The 'tra not group functional columns should be declared in the )&O@P *? Clause.
@"ID) ,I'&' Clause( ro%s can be pre ecluded before dividing them into groups.
Column Aliases cannot be used in )roup *y Clause.
*y default( ro%s are sorted by ascending order of the columns included in the )roup *y
List.
The column applied upon )&O@P *? Clause need not be part of "'L'CT list.
"Fl P "elect -eptno( Avg( "al ! <rom 'mp )roup *y -eptno K
"Fl P "elect -eptno( Avg ( "al ! <rom 'mp )roup *y -eptno Order by Avg ( "al ! K
"Fl P "elect -eptno( 6in ( "al ! ( 6a ( "al ! <rom 'mp )roup *y -eptno K
"Fl P "elect -eptno( =ob( "um ( "al ! <rom 'mp )roup *y -eptno( =ob K
The Above specification falls under the principle of )roups %ithin )roups.
"Fl P "elect -eptno( 6in ( "al ! ( 6a ( "al ! <rom 'mp ,here =ob \ LCL'&;S
)roup *y -eptno K
"Fl P "elect -eptno( "um ( "al !( Avg ( "al ! <rom 'mp ,here =ob \ LCL'&;S
Oragle 10 g Material
53
)roup *y -eptno K
E6c53"*g Gr%5ps %# Res5ts :
o Ha="*g Ca5se :
It is used to specify %hich groups are to be displayed.
S&*ta6 : SELECT C%5$*F Gr%5pQF5*ct"%*
Fr%$ Tabe
J WHERE C%*3"t"%* K
J GROUP '! Gr%5pQ'&QE6pr K
J HA/ING Gr%5pQC%*3"t"%* K
J ORDER '! C%5$*QNa$e + A"as K H
Steps Per#%r$s '& Ha="*g Ca5se :
&o%s are )rouped
The )roup <unction is applied to the group.
The )roups that match the criteria in the IA$ID) Clause are displayed.
o The IA$ID) Clause can precede )roup *y Clause( *ut it is more logical to declare it
before )roup *y.
o )roup *y Clause can be used( %ithout a )roup <unction in the "'L'CT list.
o If ro%s are restricted based on the result of a group function( %e must have a )roup *y
Clause as %ell as the Iaving Clause.
"Fl P "elect -eptno( Avg ( "al !R<rom 'mp )roup *y -eptno Iaving
6a ( "al ! P 09>> K
"Fl P "elect =ob( "um ( "al ! Payroll <rom 'mp ,here =ob DOT LI;' L"AL'"_S
)roup *y =ob Iaving "um ( "al ! P 4>>> Order *y "um ( sal ! K
"Fl P "elect -eptno( 6in ( "al !( 6a ( "al ! <rom 'mp ,here =ob \ LCL'&;S
)roup *y -eptno Iaving 6in ( "al ! Q />>> K
"Fl P "elect -eptno( "um ( "al ! <rom 'mp )roup *y -eptno Iaving
Count ( -eptno ! P 1 K
"Fl P "elect -eptno( Avg ( "al ! ( "um ( "al !( 6a ( "al !( 6in ( "al ! <rom 'mp
)roup *y -eptno Iaving Count ( H ! P 1 K
"Fl P "elect -eptno( Avg ( "al ! "um ( "al ! <rom 'mp )roup *y -eptno
Iaving Avg ( "al ! P 04>> K
"Fl P "elect -eptno( =ob( "um ( "al ! ( Avg ( "al ! <rom 'mp )roup *y -eptno( =ob
Iaving Avg ( "al ! P 04>> K
Nest"*g %# Gr%5p F5*ct"%*s :
o )roup functions can be nested to a depth of t%o.
"Fl P "elect 6a ( Avg ( "al ! ! <rom 'mp )roup *y -eptno K
"Fl P "elect 6a ( "um ( "al ! ! ( 6in ( "um ( "al ! ! <rom 'mp )roup *y -eptno K
Oragle 10 g Material
54
"Fl P "elect 6a ( "um ( "al ! ! ( 6in ( Avg ( "al ! ! <rom 'mp )roup *y =ob K
M"scea*e%5s F5*ct"%*s :
o GREATEST F5*ct"%* :
S&*ta6 : GREATEST ( 'pr/( 'pr0( ...!
&eturns the greatest of the list of 'pr.
All 'prs after the first are implicitly converted to the data type of the first 'pr(
before the comparison.
Oracle compares the 'prs using Don padded comparison semantics.
Character comparison is based on the value of the character in the data base
character list.
"Fl P "elect )reatest ( LIA&&?S ( LIA&&IOTS ! <rom -ual K
"Fl P "elect )reatest ( />>>( 0>>>( 0>> ! <rom -ual K
"Fl P "elect )reatest ( S/>G=@LG>4S( S0>G=@LG>4S ! <rom -ual K
o LEAST F5*ct"%* :
S&*ta6 : LEAST ( 'pr/( 'pr0( ...!
It returns the Least of the List of 'prs.
All 'prs after the first are implicitly converted to the data type of the first epr
before the comparison .
"Fl P "elect Least ( LIA&&?S ( LIA&&IOTS ! <rom -ual K
"Fl P "elect Least ( />>>( 0>>>( 0>> ! <rom -ual K
"Fl P "elect Least ( S/>G=@LG>4S( S0>G=@LG>4S ! <rom -ual K
o USER F5*ct"%* :
S&*ta6 : USER
It returns the Current Oracle users %ithin the $A&CIA&0 data type.
The function cannot be used in the condition of the CI'C; Constraint .