SQL SQL
DATA
SQL SQL
Applicat BASE Applicat
ion1 SQL SQL
ion2
2 Cannt write more than one SQL command at the same Time
3 SQL commands are not depended to each other and Not executed in a specific order
1 Improve Performance and reduce network traffic between client and server by agrouping sql statements
together in one block and send it to the server in one call
4 Integration: it can be used as developer tools (in forms and reports)or as administration tools
2 Block require that all SQL Commands to be correct for the execution . if there is one SQL command is
not Correct then the whole block with all SQL Commands will not be exeucted
3 If you write more than one SQL statement you must separate them by using semi comma (;)
Declaration Part
Optional
Body
Mandatory Exception Part
Optional
Variable
Oracle Complete PLSQL Reference 3
Q: What is a Variable?
1. Is a space located in the memory can be used For Impermanent storage of One an ONLY One Value
2. Variable can store value identified by the user himself OR value retrieved form the data base table
3- Reusability:
3.1 After they are declared, variables can be used repeatedly in an application simply by referencing
them in other statements, including other declarative statements such as local variables and global
variables.
4- Ease of maintenance:
4.1 declare new variable has the same data type of other variable
4.2 declare new variable has the same data type of data base column and when changing the value in
the database this value will changed automatically in the variable such as create variable storing the
max value in empno column to create application trigger to increment this value for the next record
Declare
v_job varchar2(20) null ;
v_location varchar2(50) null := 'cairo';
v_deptno number(5) not null := 10
v_total_sal number(9,2) := 0;
v_mgr number(6) DEFAULT 100;
c_comm CONSTANT number(5) null DEFAULT 1400;
v_hire_date date := TO_CHAR('1998/08/16', 'yyyy/mm/dd');
v_orderdate date := SYSDATE + 3;
c_tax_rate CONSTANT numebr(5,2) := 0.15;
v_valid BOOLEAN not null := TRUE;
2. Use TabeName.ColumnName%type
Declare
v_job emp.job%type ;
v_location dept.dname%type := 'cairo' ;
v_deptno dept.deptno%type not null := 10;
v_total_sal emp.sal%type := 0;
v_mgr emp.mgr%type DEFAULT 100;
c_comm CONSTANT emp.comm%type := 1400;
v_hire_date emp.hiredate%type := TO_CHAR('1998/08/16', 'yyyy/mm/dd');
3. Use Variable%type
Declare
v_job emp.job%type ;
v_location v_job%type := 'cairo' ;
v_deptno dept.deptno%type not null := 10;
v_total_sal v_deptno%type := 0;
v_mgr v_deptno%type DEFAULT 100;
c_comm CONSTANT emp.comm%type := 1400;
v_hire_date emp.hiredate%type := TO_CHAR('1998/08/16', 'yyyy/mm/dd');
4. Use TableName%rowtype
4.1 Decalre only one variable that store the value for all row in the table
4.2 you can print the whole row value or print a specific values only
Declare
Emp_Row Emp%RowType;
begin
DBMS_OUTPUT.PUT_LINE (Emp_Row.Empno);
DBMS_OUTPUT.PUT_LINE (Emp_Row.Ename);
DBMS_OUTPUT.PUT_LINE (Emp_Row.Salary);
End;
DBMS_OUTPUT.PUT_LINE:
1. PRINT command. is DBMS_OUTPUT.PUT_LINE. DBMS_OUTPUT is Oracle-supplied package, and
PUT_LINE is a procedure within that package.
2. Within a PL/SQL block, reference DBMS_OUTPUT.PUT_LINE and, in parentheses, specify the string
that you want to print to the screen. The package must first be enabled in your SQL*Plus session. To do
this, execute the SQL*Plus
You must declare variables with the same number of the columns that you retrieve in your select statement
1. Decalre variables for each column you retrive in select statement
2. Select column into variable
3. Print value for the variable by using DBMS_OUTPUT.PUT_LINE
4. you must enable DBMS_OUTPUT.PUT_LINE first by running command
5. SQL> set serveroutput on ;
6. DBMS_OUTPUT.PUT_LINE is used to pring value for one variable only .
7. If you print values for more that one variable then you can use Concat function or write
DBMS_OUTPUT.PUT_LINE more than one time for each varaible you want to pring
Declaration Part
Optional
Body
Mandatory
Declaration Part
Optional
Control Structure
There are three Type of Control Structure
1 IF Condition
2 Case Expression
3 Loop
All conditions in IF statements are Boolean expressions that evaluate to true or false.
All Actions in IF Statements are PL/SQL statements
You can execute many actions as you like when the actions is TRUE
Createorreplaceprocedurerep1(p1number)
Is
V_salnumber(5);
Begin
Selectsal
Intov_sal
Fromscott.Emp
Whereempno=p1;
v_sal:=CASEv_salWhennullthen50;
When<=1000thenv_sal+100;
When<=2000thenv_sal+200;
ELSEv_sal+300;
ENDCASE;
Updateemp
setsal=V_sal
whereempno=p1;
End;
What is Loop ?
It is a technique that can be used to run spefic code more that one time within the block
In loop you must write a condition to exist the loop . If you didnt specify the condition the loop will
continue forever (infinity loop)
To end the loop, you use either an EXIT or EXIT WHEN statement.
Basic Loop
You can use a variable directory in the body without declaring it in the declaration
Where :
6. The upper or lower bounds of the FOR loop can be defined as variables or functions.
Explicit Cursor
Implicit Cursor
Reference Cursor
Cursor
Oracle Complete PLSQL Reference 76
Topics
Cursor
1. Introduction( 13 )
2. Cursor Declaration( 16 )
3. Cursor Open( 3 )
4. Fetch( 17 )
5. LOOP( 10 )
6. Close Cursor( 6 )
7. Cursor Status( 6 )
8. Implicit Cursor( 18 )
9. Explicit Cursor( 2 )
10. Cursor for Update( 5 )
11. Cursor Parameter( 4 )
12. ref cursor( 6 )
13. REFCURSOR( 9 )
14. Cursor Attributes( 9 )
15. refcursor( 3 )
16. Cursor function( 5 )
Q: What is Cursor?
1. Cursor is a space in the memory that can be used to store more than ONE record
2. cursor is basically a set of rows that you can access one at a time.
3. Cursor can accept parameters
Values of %FOUND, %NOTFOUND, and %ROWCOUNT are changed after every fetch.
If you use the %FOUND, %NOTFOUND, and %ROWCOUNT cursor variables before the cursor is opened
or after the cursor is closed, they will raise an exception.
<CursorName>%ISOPEN
<CursorName>%FOUND or <CursorName>%NOTFOUND
Oracle Complete PLSQL Reference 84
<CursorName>%ROWCOUNT
Implicit Cursor
2.
declare
c_weak sys_refcursor
declare
type strong_rcty is ref cursor return employee%ROWTYPE;
c_strong_rcty strong_rcty;
Pre-Defined Exceptions
Exception Oracle Error SQLCODE Value
NO_DATA_FOUND ORA-01403 Single SELECT statement returned no data
TOO_MANY_ROWS ORA-01422 Single SELECT statement returned more than one row of
data.
ZERO_DIVIDE ORA-01476 A program attempts to divide a number by zero.
VALUE_ERROR ORA-06502 An arithmetic, conversion, truncation, or
size-constraint error occurs.
For example, when your program selects a column value
Oracle Complete PLSQL Reference 99
into a character variable,
if the value is longer than the declared length
of the variable,
PL/SQL aborts the assignment and raises
VALUE_ERROR. In procedural statements,
VALUE_ERROR is raised if the conversion of a
character string into a number fails. (In SQL statements,
INVALID_NUMBER is raised.)
DUP_VAL_ON_INDEX ORA-00001 A program attempts to store duplicate values in a
database column that is constrained by a unique index.
INVALID_NUMBER ORA-01722 In a SQL statement, the conversion of a character string
into a number fails because the string does not
represent a valid number. (In procedural statements,
VALUE_ERROR is raised.) This exception is also raised
when the LIMIT-clause expression in a bulk FETCH
statement does not evaluate to a positive number.
ACCESS_INTO_NULL ORA-06530 A program attempts to assign values to the attributes of
an uninitialized object.
CASE_NOT_FOUND ORA-06592 None of the choices in the WHEN clauses of a CASE
statement is selected, and there is no ELSE clause.
COLLECTION_IS_NULL ORA-06531 A program attempts to apply collection methods other
than EXISTS to an uninitialized nested table or varray,
or the program attempts to assign values to the
elements of an uninitialized nested table or varray.
INVALID_CURSOR ORA-01001 A program attempts a cursor operation that is not
allowed, such as closing an unopened cursor.
LOGIN_DENIED ORA-01017 A program attempts to log on to Oracle with an invalid
username or password.
NOT_LOGGED_ON ORA-01012 A program issues a database call without being
connected to Oracle.
PROGRAM_ERROR ORA-06501 PL/SQL has an internal problem
SUBSCRIPT_OUTSIDE_LIMIT ORA-06532 A program references a nested table or varray element
using an index number (-1 for example) that is outside
the legal range.
SYS_INVALID_ROWID ORA-01410 The conversion of a character string into a universal
rowid fails because the character string does not
represent a valid rowid.
TIMEOUT_ON_RESOURCE ORA-00051 A time-out occurs while Oracle is waiting for a resource
Pre-Defined Exceptions
Exception Oracle Error SQLCODE Value
SUBSCRIPT_BEYOND_COUNT ORA-06533 A program references a nested table or varray element
using an index number larger than the number of
elements in the collection.
ROWTYPE_MISMATCH ORA-06504 The host cursor variable and PL/SQL cursor variable
involved in an assignment have incompatible return
types. For example, when an open host cursor variable
Oracle Complete PLSQL Reference 100
is passed to a stored subprogram, the return types of
the actual and formal parameters must be compatible.
SELF_IS_NULL ORA-30625 A program attempts to call a MEMBER method, but the
Instance of the object type has not been initialized. The
built-in parameter SELF points to the object, and is
Always the first parameter passed to a MEMBER
method.
STORAGE_ERROR ORA-06500 PL/SQL runs out of memory or memory has been
Corrupted.
CURSOR_ALREADY_OPEN ORA-06511 A program attempts to open an already open cursor. A
Cursor must be closed before it can be reopened. A
cursor FOR loop automatically opens the cursor to
which it refers, so your program cannot open that
cursor inside the loop.
OTHERS 1. Any other error occurred.
2. You can use the OTHERS exception to handle all
exceptions
3. Because OTHERS handles all exceptions, you must
list it after any specific exceptions in your EXCEPTION
block.
Create the following Employee and Department tables to be used in the following exercises
User Exception
System Error
User Exception
when NO_DATA_FOUND & TOO_MANY_ROWS then
System Error
User Exception
System Error
System Error
User Exception
User Exception
when INVALID_NUMBER then
Raised when an attempt is made to convert an invalid character string into a number.
System Error
User Exception
when OTHERS then
You can use the OTHERS exception to handle all exceptions
System Error
User Exception
User Exception
OUT Parameter
2. can be bused when pass parameter values from one procedure to another procedure
2.1 OUT parameter returns a value to the caller of a subprogram.
OUT Parameter
Table Type
DataBase Trigger
Functions
Q: What is Fincation?
A function is similar to a procedure except that a function must return a value.
Function can accept parameters or not
CREATE [OR REPLACE] FUNCTION function_name [(parameter_name [IN | OUT | IN OUT] type [, ...])]
RETURN type
{IS | AS}
BEGIN
function_body
END function_name;
Oracle Complete PLSQL Reference 117
Function with no parameters
Trigger Syntax
SQL>CreateorreplacetriggerTri1
Afterupdateofsal,commonemp
Foreachrow
Begin
Updateemp
Settotal=sal+comm
Wheresal=:new.salorcomm=:new.comm;
End;
SQL>insertintoevalues(1,'ali',100,200,null);
SQL>insertintoevalues(2,'mona',200,300,null);
SQL>commit;
SQL>updateesetsal=300whereid=1;
ERRORatline1:
ORA04091:tableSCOTT.Eismutating,trigger/functionmaynotseeit
ORA06512:at"SCOTT.TRI1",line2
ORA04088:errorduringexecutionoftrigger'SCOTT.TRI1'
ErrorCalrification
INOracleyoucanntinsrtintotableXandruntriggertoupdatethesametable
Butyoucanrunthetriggertoupdateanothertablebbecauseitisrelatedtointernal
constraintthatviolatethisissue
Insert into v
Values(1,ahmed,100,1,1,sales,cairo);
You must insert data into view in the same sequence for that view columns
Example No:11
Conn sys/password@<service_name> as sysdba;
Create table ddl_log
(server_event char(40),
owner char(20),
objectname char(20),
text varchar(200),
username char(20),
transaction_date date);
create table w
logon_date date);
(username char(20),
CREATE OR REPLACE TRIGGER ip_trace
AFTER LOGON ON DATABASE
object_name varchar2(255));
BEGIN
IF (ora_sysevent=LOGON) THEN
CREATE
INSERT INTO IP OR REPLACE TRIGGER sysevent_trig
VALUES(ora_client_ip_address,user,ora_login_user,Ora_database_name,ora_instance_num,sysdate);
AFTER
END IF; ALTER ON SCHEMA
END;
BEGIN
INSERT INTO w VALUES(user,ora_dict_obj_name);
END ;
Trigger Privelages
create trigger
create any trigger
administer database trigger -- required
System Privileges
for ON DATABASE
alter any trigger
drop any trigger
You Can Enable And Disable Any Trigger According To the following Codes
2.
create or replace function emp_count (p_deptno in number)
return number
is
cnt number(2) := 0;
begin
select count(*) into cnt
from emp
where deptno = p_deptno ;
return (cnt);
end;
/
3.
4.
select ename , sal , sal*0.10 as raise
from emp;
5.
select ename , sal , comm, nvl(sal,0)+nvl(comm,0) as total
from emp;
6.
select ename , hiredate , TO_CHAR(hiredate,'W')
from emp;
7.
select ename, hiredate , TO_CHAR(hiredate, 'fmMonth') as Month_name
from emp;
8.
select ename , hiredate , TO_CHAR( hiredate, 'Q' )
from emp
where deptno = 10 ;
12.
Create Or Replace Function username
RETURN VARCHAR2
IS
BEGIN
Oracle Complete PLSQL Reference 152
RETURN user;
END;
17.
CREATE OR REPLACE FUNCTION add_three_numbers( a NUMBER := 0, b NUMBER := 0, c NUMBER := 0
)
RETURN NUMBER
IS
BEGIN
RETURN a + b + c;
END;
/
BEGIN
dbms_output.put_line(add_three_numbers(3,4,5));
END;
/
18.
CREATE OR REPLACE FUNCTION add_three_numbers( a NUMBER := 0, b NUMBER := 0, c NUMBER := 0
)
RETURN NUMBER
IS
BEGIN
RETURN a + b + c;
END;
/
BEGIN
dbms_output.put_line(add_three_numbers(a => 4,b => 5,c => 3));
END;
19.
CREATE OR REPLACE FUNCTION add_three_numbers( a NUMBER := 0, b NUMBER := 0, c NUMBER := 0
)
RETURN NUMBER
IS
BEGIN
RETURN a + b + c;
END;
/
BEGIN
dbms_output.put_line(add_three_numbers(a => 4,b => 5,c => 3));
END;
createsequencesqdept
startwith1
incrementby1;
CREATEorreplacepackageover_pack
IS/AS
Procedureadd_dept(dnonumber,dnamevarchar2,dlocvarchar2);
Procedureadd_dept(dnamevarchar2,dlocvarchar2);
End;
/
CREATEorreplacepackageBODYover_pack
Is
Procedureadd_dept(dnonumber,dnamevarchar2,dlocvarchar2)
Is
Begin
Insertintoddvalues(dno,dname,dloc);
End;
Procedureadd_dept(dnamevarchar2,dlocvarchar2)
Is
Begin
Insertintoddvalues(sqdept.nextval,dname,dloc);
End;
End;
/
execover_pack.add_dept(design,cairo);
execover_pack.add_dept(1,sales,alex);
CREATEorreplacepackagebodyover_pack
Is
functiontotal(v_salnumber,v_commnumber)
returnnumber
is
Begin
return(nvl(v_sal,0)+nvl(v_comm,0));
End;
Functionmax_sal_emp
RETURNnumber
IS
v_max_salnumber(5);
BEGIN
Selectmax(sal)
Intov_max_sal
Fromemp;
RETURN(v_max_sal);
END;
End;
/
selectsal,comm,over_pack.total(sal,comm)
fromemp;
selectover_pack.max_sal_emp
fromdual;
http://www.java2s.com/Tutorial/Oracle/0500__Cursor/UsingSELECTinaCursor.htm
http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Cursorforobjecttable.htm
http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Cursorwithorderby.htm
http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Cursorforaggregatefunction.htm
http://www.java2s.com/Tutorial/Oracle/0500__Cursor/FetchingAcrossCommitsExample2.htm
http://www.java2s.com/Tutorial/Oracle/0500__Cursor/CursorFORLoop.htm
http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Closecursorinexcpetionhandler.htm
SQL>Createorreplaceprocedurea
Is
CursorEmp_Rec_Curisselectename,deptnofromemp;
Begin
foriinemp_rec_curloopimplicitopenandimplicitFetch
ifi.deptno=20then
dbms_output.put_line(i.ename||''||i.deptno);
endif;
endloop;implicitcloseandimplicitloopExit
end;
theprviousexampleisequaltonextexample
SQL>Createorreplaceprocedurea
Is
Begin
foriin(selectename,deptnofromemp)loopimplicitopenandimplicitFetch
ifi.deptno=20then
dbms_output.put_line(i.ename||''||i.deptno);
endif;
endloop;
implicitcloseandimplicitloopExit
end;
Nested Cursor
http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Nestedcursor.htm
VARRAY of Cursor
http://www.java2s.com/Tutorial/Oracle/0500__Cursor/VARRAYofCursor.htm
Execute procedure
1. exec rep1;
2. exec rep1()p1,p2,p3,;
3. call rep1();
4. call rep1(p1,p2,p3,.);
Triggers
http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Createandusereferencecursor.htm
http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Referencevalueinacursorbycursorvariable.htm
Function
http://www.java2s.com/Tutorial/Oracle/0480__PL-SQL-
Programming/CodewithConditionalControltoAvoidanException.htm
http://www.java2s.com/Tutorial/Oracle/0480__PL-SQL-
Programming/CodewithExplicitHandlerforPredefinedException.htm
http://www.java2s.com/Tutorial/Oracle/0480__PL-SQL-
Programming/Handlingexceptionswithouthaltingtheprogram.htm
IN OUT PARAMETER
http://www.java2s.com/Tutorial/Oracle/0500__Cursor/TheuseofREFCURSOR.htm
http://www.java2s.com/Tutorial/Oracle/0500__Cursor/OpenSYSREFCURSORforselectfrom.htm
http://www.java2s.com/Tutorial/Oracle/0500__Cursor/SYSREFCURSORtypeparameter.htm
http://www.java2s.com/Tutorial/Oracle/0440__PL-SQL-Statements/ReversedFORLOOP.htm
http://www.adp-gmbh.ch/ora/plsql/loops.html
https://support.us.oracle.com/oip/faces/secure/srm/sr/SRQueue.jspx?mc=true
https://login.oracle.com/mysso/signon.jsp?
site2pstoretoken=v1.2~97B77393~56D799A0127BA50DC728218D093398C3E7DC7FBF437396E2
DF8C88659E2568533223ED388A5A74C7CE50A6B563DA6224E2FE03819119B6DD1568AE6C9280
AB2EDCDECBBDD876929B5A9F5D0C72951FDCE134763C3783B3DFACB6CED8B35EA6CC1CF29A9
2BAA0E40C94B0B59C78A8AA97086082846113AC3E082477225EF2359275DE1F014672AC086F85
A66620BFBDAB778B2E5A6D04E0641CF70781A264F3C9EE35CFEC74333D63B3570160E466D4390
A005E5988628900&p_error_code=&p_submit_url=https%3A%2F%2Flogin.oracle.com%2Fsso
%2Fauth&p_cancel_url=http%3A%2F%2Fgcca.oraclecorp.com
=%2Fcca&ssousername=&subscribername
https://login.oracle.com/mysso/signon.jsp?
site2pstoretoken=v1.2~B483CC4E~8A17DE85F48237269E6D418A2D3B532BF6B825EBC625C51F
D063482AE69E7EB1B7E38AEF36FA299222FB6EB1EE7E34B0DC424060688F88C2241F59A23D04F
3E37FE9AD514E1C692B8BD63EA50EB5A6510493DD38C1E272779A451A13D05CB235AD10FE3A1
1658C15E94EE612F4B74D190699D28ACAE02CA2213BB826001290456A80A25F7EE2D6C99261B0
5A83CD01EAB5FEE046D837278283E8C3F7E28198BAA653F3C73A6FFC6B39B19ACD78D5EDAC9C
E0C22B7B5F17349A1312F92CB33D4C25CE5C83F0768185C830F3F292E87C413AC60A0775EF16C
324913DCBF1A7F1A9D25E779E5B91F1350602B1F083E5812CDA7B4A2BD87D6317&p_error_code
=&p_submit_url=https%3A%2F%2Flogin.oracle.com%2Fsso%2Fauth&p_cancel_url=https%3A%2F
=%2Fsupport.us.oracle.com%2Foip&ssousername=&subscribername
https://login.oracle.com/mysso/signon.jsp?
site2pstoretoken=v1.2~B483CC4E~23E6FB45EB4FE6929831F3A33F813893C1D08307A3F8A92A
A3484C34FF3229B41916D02D6C8610D11A20FCE7DF40F64B70506A05058A71C3E56EE66E25DBC
CD6B8834A62BB8CD4371A40D66106E03A166297BAD9E86E8A419F45FCD1CDB2278BB4E534703
9AED42D290AD988AC97C5977896884568F4C86E545344B0079CAB3DA03435F70B45D1D2DD73C
B25930116BFC56B8EDDC9863698C3465FE67D524D229537AAFBF483E0CC33D838D654E6D4748
356753D3EF371FECA7F8B482995D61F8430328F872CE9E6DAC0580B0A73C727699C7F402C9526
09B21A3263A306C1E4DE7CE0A56893155771D173674350EE77&p_error_code=&p_submit_url=htt
ps%3A%2F%2Flogin.oracle.com%2Fsso%2Fauth&p_cancel_url=https%3A%2F
=%2Fsupport.us.oracle.com%2Foip&ssousername=&subscribername
http://www.ss64.com/orap/
Packagesmarked*arenewin9.2
PackageDescription
DBMS_ALERTNotifyadatabaseevent(asynchronous)
DBMS_APPLICATION_INFO
Registeranapplicationnamewiththedatabase
forauditingorperformancetracking.
Applicationinfocanbepushedinto
V$SESSION/V$SESSION_LONGOPS
DBMS_AQAddamessage(ofapredefinedobjecttype)ontoaqueue
ordequeueamessage.
DBMS_AQADMAdministeraqueueorqueuetable
formessagesofapredefinedobjecttype.
DBMS_AQELMConfigureAdvancedQueuing
asynchronousnotificationbyemailandHTTP.*
DBMS_BACKUP_RESTORE
NormalizefilenamesonWindowsNTplatforms.
DBMS_DDLAccessSQLDDLstatementsfromastoredprocedure,
providesspecialadministrationoperations
notavailableasDDLs.
DBMS_DEBUGImplementserversidedebuggersandprovideawayto
debugserversidePL/SQLprogramunits.
DBMS_DEFERUserinterfacetoareplicatedtransactionaldeferred
RPCfacility.RequirestheDistributedOption.
DMBS_DEFER_SYS
Thesystemadministratorinterfacetoareplicated
transactionaldeferredRPCfacility.
RequirestheDistributedOption.
DBMS_DESCRIBE
Describetheargumentsofastoredprocedure
withfullnametranslationandsecuritychecking.
DBMS_DISTRIBUTED_TRUST_ADMIN
MaintaintheTrustedDatabaseList,whichisusedto
determineifaprivilegeddatabaselinkfromaparticular
servercanbeaccepted.
DBMS_ENCODEEncode???
DBMS_FGAFinegrainedsecurityfunctions.*
DMBS_FLASHBACK
Flashbacktoaversionofthedatabaseataspecified
wallclocktimeoraspecifiedsystemchange
number(SCN).*
DBMS_HS_PASSTHROUGH
SendpassthroughSQLstatementstononOraclesystems.
(viaHeterogeneousServices)
DBMS_IOTCreateatableintowhichreferencestothechainedrows
foranIndexOrganizedTablecanbeplacedusingthe
ANALYZEcommand.
DBMS_JOBSchedulePL/SQLproceduresthatyouwantperformedat
periodicintervals;alsothejobqueueinterface.
DBMS_LDAPFunctionsandprocedurestoaccessdatafrom
LDAPservers.*
DBMS_LIBCACHE
PreparesthelibrarycacheonanOracleinstanceby
extractingSQLandPL/SQLfromaremoteinstanceand
compilingthisSQLlocallywithoutexecution.*
DBMS_LOBGeneralpurposeroutinesforoperationsonOracleLarge
Object(LOBs)datatypesBLOB,CLOB(readwrite),
DBMS_LOCKRequest,convertandreleaselocksthroughOracleLock
Managementservices.
DBMS_LOGMNRFunctionstoinitializeandrunthelogreader.
DBMS_LOGMNR_CDC_PUBLISH
Identifynewdatathathasbeenaddedto,modified,or
removedfrom,relationaltablesandpublishthechanged
datainaformthatisusablebyanapplication.*
DBMS_LOGMNR_CDC_SUBSCRIBE
Viewandquerythechangedatathatwascaptured
andpublishedwiththeDBMS_LOGMNR_CDC_PUBLISHpackage.*
DBMS_LOGMNR_D
Querythedictionarytablesofthecurrentdatabase,and
createatextbasedfilecontainingtheircontents.
DBMS_METADATA
Retrievecompletedatabaseobjectdefinitions(metadata)
fromthedictionary.*
DBMS_MVIEWRefreshsnapshotsthatarenotpartofthesame
refreshgroupandpurgelogs.DBMS_SNAPSHOTisasynonym.
DBMS_OBFUSCATION_TOOLKIT
ProceduresforDataEncryptionStandards.
DBMS_ODCIGettheCPUcostofauserfunctionbasedonthe
elapsedtimeofthefunction.*
DBMS_OFFLINE_OG
PublicAPIsforofflineinstantiationofmastergroups.
DBMS_OFFLINE_SNAPSHOT
PublicAPIsforofflineinstantiationofsnapshots.
DBMS_OLAPProceduresforsummaries,dimensions,andqueryrewrites.
DBMS_ORACLE_TRACE_AGENT
ClientcallableinterfacestotheOracleTRACE
instrumentationwithintheOracle7Server.
DBMS_ORACLE_TRACE_USER
PublicaccesstotheOraclerelease7Server
OracleTRACEinstrumentationforthecallinguser.
DBMS_OUTLN_EDIT
Editaninvoker'srightspackage.*
DBMS_OUTPUTAccumulateinformationinabuffersothatitcanbe
retrievedoutlater.
DBMS_PCLXUTILIntrapartitionparallelismforcreatingpartitionwise
localindexes.
DBMS_PIPEADBMSpipeservicewhichenablesmessagestobesent
betweensessions.
DBMS_PROFILERAProbeProfilerAPItoprofilePL/SQLapplications
andidentifyperformancebottlenecks.
Toinstallthisrunprofload.sql(asSYS)andproftab.sql(as
user)
DBMS_RANDOMAbuiltinrandomnumbergenerator.
Optionstogeneraterandomnumberswithinarangeor
distribution.
DBMS_RECTIFIER_DIFF
APIsusedtodetectandresolvedatainconsistencies
betweentworeplicatedsites.
DBMS_REDEFINITION
Reorganiseatable(changeit'sstructure)whileit's
stillonlineandinuse.*
DBMS_REFRESHCreategroupsofsnapshotsthatcanberefreshedtogether
toatransactionallyconsistentpointintime.
RequirestheDistributedOption.
DBMS_REPAIRRepairdatacorruption.
DBMS_REPCATAdministerandupdatethereplicationcatalogandenvironment.
RequirestheReplicationOption.
DBMS_REPCAT_ADMIN
Createuserswiththeprivilegesneededbythesymmetric
replicationfacility.RequirestheReplicationOption.
DBMS_REPCAT_INSTATIATE
Instantiatesdeploymenttemplates.
RequirestheReplicationOption.
DBMS_REPUTIL
Generateshadowtables,triggers,andpackages
fortablereplication.
DBMS_RESOURCE_MANAGER
Maintainplans,consumergroups,andplandirectives;
alsoprovidessemanticssothatyoumaygrouptogether
changestotheplanschema.
DBMS_RESOURCE_MANAGER_PRIVS
Maintainprivilegesassociatedwithresourceconsumergroups.
DBMS_RESUMABLE
Suspendlargeoperationsthatrunoutofspaceorreachspace
limitsafterexecutingforalongtime,fixtheproblem,and
makethestatementresumeexecution.
DBMS_RLSRowlevelsecurityadministrativeinterface.
DBMS_ROWIDProcedurestocreaterowidsandtointerprettheircontents.
DBMS_SESSIONAccesstoSQLALTERSESSIONstatements,andothersession
information,fromstoredprocedures.
DBMS_SHARED_POOL
Keepobjectsinsharedmemory,sothattheywillnotbeaged
outwiththenormalLRUmechanism.
DBMS_SNAPSHOT
SynonymforDBMS_MVIEW
DBMS_SPACESegmentspaceinformationnotavailablethroughstandardSQL.
Howmuchspaceisleftbeforeanewextentgetsallocated?
HowmanyblocksareabovethesegmentsHighWaterMark?
Howmanyblocksareinthefreelist(s)
DBMS_SPACE_ADMIN
Tablespaceandsegmentspaceadministrationnotavailable
throughthestandardSQL.
DBMS_SQLUsedynamicSQLtoaccessthedatabase.
DBMS_STANDARD
Languagefacilitiesthathelpyourapplicationinteract
withOracle.
DBMS_TRACERoutinestostartandstopPL/SQLtracing.
DBMS_TRANSACTION
AccesstoSQLtransactionstatementsfromstored
proceduresandmonitorstransactionactivities.
DBMS_TRANSFORM
Aninterfacetothemessageformattransformationfeatures
ofOracleAdvancedQueuing.*
DBMS_TTSCheckifatransportablesetisselfcontained.
DBMS_TYPESConstants,whichrepresentthebuiltinanduserdefined
types.
DBMS_URLOracleSpatialconnection_type??
DBMS_UTILITYUtilityroutines,Analyze,Time,Conversionetc.
DBMS_WMDatabaseWorkspaceManager(longtransactions)*
DBMS_XMLGENConverttheresultsofaSQLquerytoacanonicalXMLformat.
*
DMBS_XMLQUERY
DatabasetoXMLTypefunctionality.*
DBMS_XMLSAVE
XMLtodatabasetypefunctionality.*
DEBUG_EXTPROC
Debugexternalproceduresonplatformswithdebuggers
thatcanattachtoarunningprocess.
OUTLN_PKGSynonymofDBMS_OUTLN.
PLITBLMHandleindextableoperations.(Don'tcalldirectly)
SDO_CS,SDO_GEOM,SDO_LRS,SDO_MIGRATE,SDO_TUNE
seeOracleSpatialUser'sGuideandReference
SpatialpackagesareinstalledinuserMDSYSwithpublic
synonyms.
STANDARDTypes,exceptions,andsubprogramswhichare
UTL_COLLCollectionlocatorsqueryandupdatefromaPL/SQLprogram.
UTL_ENCODEEncodeRAWdataintoastandardencodedformat
sothatthedatacanbetransportedbetweenhosts.*
UTL_FILEReadandwriteOStextfilesviaPL/SQL.
ArestrictedversionofstandardOSstreamfileI/O.
UTL_HTTPEnableHTTPcalloutsfromPL/SQLandSQLtoaccessdata
ontheInternetortocallOracleWebServerCartridges.
UTL_INADDRAproceduretosupportinternetaddressing.
UTL_PGConvertCOBOLnumericdataintoOraclenumbers
andconvertOraclenumbersintoCOBOLnumericdata.
UTL_RAWSQLfunctionsforRAWdatatypesthatconcat,
substr,etc.toandfromRAWS.
UTL_REFEnableaPL/SQLprogramtoaccessanobjectbyprovidinga
referencetotheobject.
UTL_SMTPSendSMTPemail.Themailerprogramneedstorunonthe
server,
butcanbeinvokedfromaclient.
UTL_TCPSimpleTCP/IPbasedcommunicationbetweenserversandthe
outsideworld.
UTL_URLEscapeandunescapemechanismforURLcharacters.
ANYDATATYPEAselfdescribingdatainstanceTYPE.
ANYDATASETTYPE
DescribeagivenTYPEplusasetofdatainstancesofthat
type.
ANYTYPETYPEContainsatypedescriptionofanypersistentSQLtype,
namedorunnamed,includingobjecttypesandcollectiontypes.
Seealso
EXECExecuteaPL/SQLpackage
DESCDescribeapackage
RelatedViews
ALL_ARGUMENTSUSER_ARGUMENTS
Primary
KeyConstraint 11gR1 25Nov2007
Procedures 11gR1 17Dec2007
ProductUserProfiles 11gR1 17Oct2007
Profiles 11gR1 20Dec2007
Protocol.ora 11gR1 27Sep2008 DeprecatedSee:SQLNET.ORA
PseudoColumns 11gR1 25Aug2007
PublicSynonyms 11gR1 21Jul2007
PurgeRecyclebin 11gR1 14Aug2007
PurgeTable 11gR1 14Sep2007
QuoteDelimiters 11gR1 14Sep2007
RAC 11gR1 15Oct2008
RAID 11gR1 09Feb2008
System
11gR1 20Sep2008
SystemEvents
11gR1 18Mar2008
SystemEventTriggers 11gR1 06Jan2008
SystemPrivileges
11gR1 08Jan2008
SystemStatistics
11gR1 08Apr2008
TableCollectionExpression 11gR1 30Nov2008
Tables 11gR1 26Nov2008
TableTriggers 11gR1 13Feb2008
Tablespaces 11gR1 23Oct2008
TablespaceGroups 11gR1 22Nov2007
Timestamp 11gR1 20Dec2007
TimeZones 11gR1 20Dec2007
TKPROF 11gR1 04Sep2008
TotalRecall 11gR1 09Aug2007
TraceFileIdentifier 11gR1 19Feb2008
Tracing 11gR1 04Sep2008
TransactionBackout 11gR1 16Oct2007
Transactions 11gR1 15Dec2007
TranslateBuiltinFunction 11gR1 07Aug2007
TransparentDataEncryption 11gR1 29Oct2007
TransportableTablespaces 11gR1 21Jun2008
Truncate(Tables&Partitions) 11gR1 30Jul2007
Tuning 11gR1 15Aug2008
Types 11gR1 02Dec2008
UndoTablespace 11gR1 20Nov2008
UndocumentedOracle 11gR1 17Aug2008
UNIX/vi 09Apr2008
UniqueConstraint 11gR1 25Nov2007
Unpivot 11gR1 02Oct2007
UpdateStatement 11gR1 02Nov2007
USERENV 11gR1 25Aug2007 SeeSYS_CONTEXT
Users 11gR1 22Apr2008
USER_LOCK 11gR1 27Jul2007
OracleBuiltinPackages
Version11.1
SQL>
SQL>
SQL> set serveroutput on;
SQL>
SQL>
SQL>
SQL> create or replace procedure rep1
2
3 is
4 v1 number(5);
5 v2 varchar2(20);
6 v3 varchar2(20);
7
8 begin
9 select deptno , dnaem , loc
10 into v1 , v2 , v3
11 from dept;
12
13 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3)
14
15 end
16 ;
17 /
LINE/COL ERROR
-------- -----------------------------------------------------------------
15/1 PLS-00103: Encountered the symbol "END" when expecting one of the
following:
:= . ( % ;
The symbol ";" was substituted for "END" to continue.
LINE/COL ERROR
-------- -----------------------------------------------------------------
7/1 PL/SQL: SQL Statement ignored
7/17 PL/SQL: ORA-00904: "DNAEM": invalid identifier
SQL> ed;
Wrote file afiedt.buf
Procedure created.
*
ERROR at line 1:
Oracle Complete PLSQL Reference 193
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SCOTT.REP1", line 7
ORA-06512: at line 1
SQL>
SQL>
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at "SCOTT.REP1", line 11
Oracle Complete PLSQL Reference 195
ORA-06512: at line 1
SQL> ed;
Wrote file afiedt.buf
Procedure created.
1 row created.
SQL> ed;
Oracle Complete PLSQL Reference 196
Wrote file afiedt.buf
1 row created.
SQL> ed;
Wrote file afiedt.buf
1 row created.
SQL> commit;
Commit complete.
SQL> ed;
Wrote file afiedt.buf
1 row updated.
SQL> commit;
Commit complete.
Procedure created.
7 rows selected.
Procedure created.
2 rows deleted.
SQL> commit;
Commit complete.
COUNT(*)
----------
14
COUNT(*)
----------
5
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
LINE/COL ERROR
-------- -----------------------------------------------------------------
9/1 PL/SQL: SQL Statement ignored
10/7 PL/SQL: ORA-00933: SQL command not properly ended
17/5 PLS-00113: END identifier 'LOOP' must match 'REP1' at line 1,
column 11
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
1 row created.
SQL> commit;
Commit complete.
14 rows selected.
Procedure created.
*
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SCOTT.REP1", line 11
ORA-06512: at line 1
14 rows selected.
LINE/COL ERROR
-------- -----------------------------------------------------------------
13/1 PL/SQL: Statement ignored
13/24 PLS-00302: component 'V1' must be declared
SQL> ED;
Wrote file afiedt.buf
LINE/COL ERROR
-------- -----------------------------------------------------------------
11/1 PL/SQL: Statement ignored
11/24 PLS-00302: component 'V1' must be declared
SQL> ed;
Wrote file afiedt.buf
LINE/COL ERROR
-------- -----------------------------------------------------------------
8/1 PL/SQL: SQL Statement ignored
9/8 PLS-00302: component 'V1' must be declared
9/25 PL/SQL: ORA-00904: : invalid identifier
11/1 PL/SQL: Statement ignored
11/24 PLS-00302: component 'V1' must be declared
SQL> ed;
Wrote file afiedt.buf
LINE/COL ERROR
-------- -----------------------------------------------------------------
11/1 PL/SQL: Statement ignored
11/24 PLS-00302: component 'V1' must be declared
SQL>
SQL>
SQL> ed;
Wrote file afiedt.buf
LINE/COL ERROR
-------- -----------------------------------------------------------------
8/1 PL/SQL: Statement ignored
8/24 PLS-00302: component 'V1' must be declared
SQL>
SQL> ed;
Wrote file afiedt.buf
Oracle Complete PLSQL Reference 208
1 create or replace procedure rep1
2 is
3 begin
4 for i in (select empno , ename , job from emp) loop
5 dbms_output.put_line(i.empno || ' ' || i.ename || ' ' || i.job);
6 end loop;
7 end
8* ;
SQL> /
Procedure created.
SQL>
SQL>
SQL> create or replace procedure rep1
2 is
3 v1 number(5);
4 v2 varchar2(20);
5 v3 varchar2(20);
6 begin
7 for i in (select empno , ename , job from emp) loop
8 dbms_output.put_line(i.v1 || ' ' || i.v2 || ' ' || i.v3)
9 end loop;
10 end
11 ;
12 /
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL>
SQL>
SQL> spool off;
SQL>
SQL>
SQL>
SQL> select * FROM DEPT;
6 rows selected.
SQL>
SQL>
SQL> create or replace procedure rep1
2 is
3
4 cursor zozo is select deptno , dname , loc from dept;
5
6 v1 number(5);
7 v2 varchar2(20);
8 v3 varchar2(20);
9
10
11 begin
12 open zozo;
13
14 fetch zozo into v1,v2,v3;
15 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 );
16
17 close zozo;
18
19 end ;
20 /
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
Oracle Complete PLSQL Reference 212
SQL> exec rep1;
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
50 a
60 b b
2 rows deleted.
SQL> commit;
Commit complete.
14 rows selected.
LINE/COL ERROR
-------- -----------------------------------------------------------------
4/16 PL/SQL: SQL Statement ignored
4/39 PL/SQL: ORA-00904: "JOB": invalid identifier
SQL> ed;
Wrote file afiedt.buf
Procedure created.
Procedure created.
SQL> ed;
Wrote file afiedt.buf
LINE/COL ERROR
-------- -----------------------------------------------------------------
12/52 PLS-00103: Encountered the symbol "" when expecting one of the
following:
. ( ) , * @ % & | = - + < / > at in is mod remainder not rem
=> .. <an exponent (**)> <> or != or ~= >= <= <> and or like
LIKE2_ LIKE4_ LIKEC_ as between from using || member
SUBMULTISET_
The symbol "(" was substituted for "" to continue.
12/62 PLS-00103: Encountered the symbol ";" when expecting one of the
following:
. ( ) , * % & | = - + < / > at in is mod remainder not rem =>
.. <an exponent (**)> <> or != or ~= >= <= <> and or like
LIKE2_ LIKE4_ LIKEC_ as between from using || member
SUBMULTISET_
The symbol ")" was substituted for ";" to continue.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
1 row updated.
SQL> commit;
Commit complete.
Oracle Complete PLSQL Reference 221
SQL> exec rep1;
7782 CLARK MANAGER 2450
7839 KING PRESIDENT 5000
7902 FORD ANALYST 3000
7934 MILLER CLERK 1300
SQL> ed;
Wrote file afiedt.buf
1* commit
SQL> /
Commit complete.
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL>
SQL>
SQL>
SQL>
SQL>
SQL> --%ISOPEN
SQL>
SQL> --%FOUND
SQL>
SQL> --%NOT FOUND
SQL>
SQL> --%rowcount
SQL>
SQL>
SQL>
SQL> ed;
Oracle Complete PLSQL Reference 223
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Oracle Complete PLSQL Reference 226
Wrote file afiedt.buf
Procedure created.
14 rows selected.
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.
SQL> ed;
Wrote file afiedt.buf
Procedure created.