Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference...

44
Oracle PL/SQL Quick Reference 40021GC10 Production 1.0 April 1999 M08685

Transcript of Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference...

Page 1: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

Oracle PL/SQL Quick Reference

40021GC10Production 1.0April 1999M08685

Page 2: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 2 Oracle PL/SQL Quick Reference

Oracle PL/SQL Quick Reference

Edition 1.0

Published by Oracle Corporation

Copyright Oracle Corporation, 1999. All rights reserved.

Author: Kuljit Jassar

This documentation contains proprietary information of Oracle Corporation. It is provided under a license agreement containingrestrictions on use and disclosure and is also protected by copyright law. Reverse engineering of the software is prohibited. If thisdocumentation is delivered to a U.S. Government Agency of the Department of Defense, then it is delivered with Restricted Rightsand the following legend is applicable:Restricted Rights LegendUse, duplication or disclosure by the Government is subject to restrictions for commercial computer software and shall be deemed tobe Restricted Rights software under Federal law, as set forth in subparagraph (c)(1)(ii) of DFARS 252.227-7013, Rights inTechnical Data and Computer Software (October 1988).This material or any portion of it may not be copied in any form or by any means without the express prior written permission ofOracle Corporation. Any other copying is a violation of copyright law and may result in civil and/or criminal penalties.If this documentation is delivered to a U.S. Government Agency not within the Department of Defense, then it is delivered with“Restricted Rights,” as defined in FAR 52.227-14, Rights in Data-General, including Alternate III (June 1987).The information in this document is subject to change without notice. If you find any problems in the documentation, please reportthem in writing to Education Products, Oracle Corporation, 500 Oracle Parkway, Box SB-6, Redwood Shores, CA 94065. OracleCorporation does not warrant that this document is error-free.Oracle is a registered trademark and all references to Oracle products are trademarks or registered trademarks of OracleCorporation.All other products or company names are used for identification purposes only, and may be trademarks of their respective owners.

Page 3: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________________________________Oracle SQL Language Quick Reference Page 3

Table of Contents

Conventions Used in This Reference 5Syntax Diagrams and Notation 5Reading Syntax Diagrams 5

Required Keywords and Parameters 5Optional Keywords and Parameters 6Syntax Loops 6Multipart Diagrams 6Database Objects 6

Datatypes 7Object Naming Rules 8Oracle Reserved Words 8

PL/SQL Reserved Words 8SQL Reserved Words 10SQL Keywords 11

SYSTEM PRIVILEGES 12OBJECT PRIVILEGES 13

Built-in Functions 14SQL Commands Syntax 16

ALTER FUNCTION 16ALTER PACKAGE 16ALTER PROCEDURE 16ALTER TRIGGER 16DROP FUNCTION 16DROP PACKAGE 16DROP PROCEDURE 16DROP TRIGGER 17

PL/SQL Language Elements 18Assignment Statement 18Block 18CALL 20CLOSE Statement 20Collection Method 21Collection 21Comments 22COMMIT Statement 22Constant and Variable 23Cursor Attribute 24Cursor Variable 24Cursor 25DELETE Statement 26EXCEPTION_INIT PRAGMA 26Exception 27EXECUTE IMMEDIATE Statement 27EXIT Statement 27Expression 28FETCH Statement 31FORALL Statement 32

Page 4: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 4 Oracle PL/SQL Quick Reference

Functions 32GOTO Statement 33IF Statement 33INSERT Statement 33Literal 34LOCK TABLE Statement 34LOOP Statement 35NULL Statement 35Object Type 36OPEN Statement 36OPEN-FOR Statement 36OPEN-FOR-USING Statement 37Package 37Procedure 38RAISE Statement 39Records 39RETURN Statement 39ROLLBACK Statement 39%ROWTYPE Attribute 40SAVEPOINT Statement 40SELECT INTO Statement 40SET TRANSACTION Statement 41SQL Cursor 41SQLCODE Function 42SQLERRM Function 42%TYPE Attribute 42Trigger 43UPDATE Statement 44

Page 5: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________________________________Oracle SQL Language Quick Reference Page 5

Conventions Used in This Reference

Text

The text in this reference adheres to the following conventions:UPPERCASE Uppercase text calls attention to SQL keywords, filenames, and initialization

parameters.italics Italicized text calls attention to parameters of SQL statements.boldface Boldface text calls attention to definitions of terms.

Syntax Diagrams and Notation

This reference uses syntax diagrams to show PL/SQL statement and other elements of the PL/SQLlanguage. These syntax diagrams use lines and arrows to show syntactic structure.If you are not familiar with syntax diagrams, refer to Oracle8 SQL Reference.Keywords appear in UPPERCASE. You must use keywords in your SQL statement exactly as theyappear in the syntax diagram, although keywords are not case-sensitive.

Parameters appear in lowercase and act as placeholders. Parameters are usually names of databaseobjects, Oracle datatype names, or expressions.

Reading Syntax Diagrams

Syntax diagrams are drawings that illustrate valid SQL syntax. To read a diagram, trace it from left toright, in the direction shown by the arrows.Commands and other keywords appear in UPPERCASE inside rectangles. Type them exactly asshown in the rectangles. Parameters appear in lowercase inside ovals. Variables are used for theparameters. Punctuation, operators, delimiters, and terminators appear inside circles.If the syntax diagram has more than one path, you can choose any path to travel.If you have the choice of more than one keyword, operator, or parameter, your options appear in avertical list.

Required Keywords and Parameters

Required keywords and parameters can appear singly or in a vertical list of alternatives. Singlerequired keywords and parameters appear on the main path, that is, on the horizontal line you arecurrently traveling. In the following example, library_name is a required parameter:

If there is a library named HQ_LIB, then, according to the diagram, the following statement is valid:SAVEPOINT s1;

If multiple keywords or parameters appear in a vertical list that intersects the main path, one of themis required. That is, you must choose one of the keywords or parameters, but not necessarily the onethat appears on the main path. In the following example, you must choose one of the four settings:

Page 6: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 6 Oracle PL/SQL Quick Reference

Optional Keywords and Parameters

If keywords and parameters appear in a vertical list above the main path, they are optional. In thefollowing example, instead of traveling down a vertical line, you can continue along the main path:

According to the diagram, all of the following statements are valid:EXIT;EXIT this_loop;EXIT this_loop WHEN x >= 1000;

Syntax Loops

Loops let you repeat the syntax within them as many times as you like. In the following example, afterchoosing one expression, you can go back repeatedly to choose another, separated by commas.

Multipart Diagrams

Read a multipart diagram as if all the main paths were joined end to end. The following example is atwo-part diagram:

According to the diagram, the following statement is valid:CREATE SYNONYM emp FOR scott.employees;

Database ObjectsThe names of Oracle identifiers, such as tables and columns, must not exceed 30 characters in length.The first character must be a letter, but the rest can be any combination of letters, numerals, dollarsigns ($), pound signs (#), and underscores (_).However, if an Oracle identifier is enclosed by double quotation marks ("), it can contain anycombination of legal characters, including spaces but excluding quotation marks.Oracle identifiers are not case-sensitive except when enclosed by double quotation marks.Note: In this quick reference guide, not all syntax statements have been included, and of thoseincluded, not all clauses have been included. For further information, see Oracle8 SQL Reference.

Page 7: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________________________________Oracle SQL Language Quick Reference Page 7

DatatypesScalar Types

BINARY_INTEGERDECDECIMALDOUBLE PRECISIONFLOATINTINTEGERNATURALNATURALNNUMBERNUMERICPLS_INTEGERPOSITIVEPOSITIVENREALSIGNTYPE

SMALLINTCHARCHARACTERLONGLONG RAWNCHARNVARCHAR2RAWROWIDSTRINGVARCHARVARCHAR2

BOOLEAN

DATE

Composite TypesRECORDTABLEVARRAY

Reference TypesREF CURSORREF object_type

LOB TypesBFILEBLOBCLOBNCLOB

Page 8: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 8 Oracle PL/SQL Quick Reference

Object Naming Rules

The following rules apply when naming objects:• Names must be from 1 to 30 characters long.• Names cannot contain quotation marks.• Names are not case-sensitive.• Unless surrounded by double quotation marks, a name must begin with an alphabetic character

from your database character set.• Names can contain only alphanumeric characters from your database character set and the

characters underscore(_), dollar sign ($), and pound sign (#). Oracle Corporation stronglydiscourages you from using $ and #. Names of database links can also contain periods (.) and at-signs (@).If your database character set contains multibyte characters, Oracle recommends that each namefor a user or a role contain at least one single-byte character.

• A name cannot be an Oracle8 reserved word.Depending on the Oracle product that you plan to use to access a database object, names might befurther restricted by other product-specific reserved words.

• Do not use the word DUAL as a name for an object. DUAL is the name of a dummy table.• The Oracle SQL language contains other words that have special meanings. These words include

datatypes, function names, and keywords. These words are not reserved. However, Oracle serveruses them internally, and this may make your statements difficult to read and may lead tounpredictable results

Oracle Reserved Words

Oracle reserved words have special meaning to the Oracle server. You cannot use these words asnames for database objects.Keywords also have special meaning to Oracle server, but are not reserved words. Because some maybecome reserved words, and for maximum portability to other implementations of SQL, do not usekeywords as object names.

PL/SQL Reserved Words

The words listed here are reserved by PL/SQL; that is, they have a special syntactic meaning toPL/SQL. Thus, you should not use them to name program objects such as constants, variables, andcursors. Also, some of these words (marked by an asterisk) are reserved by SQL. You should not usethem to name database objects such as columns, tables, and indexes.ALL*ALTER*AND*ANY*ARRAYAS*ASC*AUTHIDASSIGNAVGBEGINBETWEEN*

BINARY_INTEGERBODY*BOOLEANBULKBY*CHAR*CHAR_BASECHECK*CLOSECLUSTER*COLLECTCOMMENT*

COMMITCOMPRESS*CONNECT*CONSTANTCREATE*CURRENT*CURRVALCURSORDATE*DAYDECLAREDECIMAL*

DEFAULT*DELETE*DESC*DISTINCT*DODROP*ELSE*ELSIFENDEXCEPTIONEXCLUSIVE*EXECUTE

Page 9: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________________________________Oracle SQL Language Quick Reference Page 9

EXISTS*EXITEXTENDSFALSEFETCHFLOAT*FOR*FORALLFROM*FUNCTIONGOTOGROUP*HAVING*HEAPHOURIFIMMEDIATE*IN*INDEX*INDICATORINSERT*INTEGER*INTERFACEINTERSECT*INTERVALINTO*IS*ISOLATIONJAVALEVEL*LIKE*LIMITEDLOCK*LONG*LOOPMAXMINMINUS*

MINUTEMLSLABEL*MODMODE*MONTHNATURALNATURALNNEWNEXTVALNOCOPYNOT*NOWAIT*NULL*NUMBER*NUMBER_BASEOCIROWIDOF*ON*OPAQUEOPENOPERATOROPTION*OR*ORDER*ORGANIZATIONOTHERSOUTPACKAGEPARTITIONPCTFREE*PLS_INTEGERPOSITIVEPOSITIVENPRAGMAPRIOR*PRIVATEPROCEDUREPUBLIC*

RAISERANGERAW*REALRECORDREFRELEASERETURNREVERSEROLLBACKROW*ROWID*ROWLABEL*ROWNUM*ROWTYPESAVEPOINTSECONDSELECT*SEPARATESET*SHARE*SMALLINT*SPACESQLSQLCODESQLERRMSTART*STDDEVSUBTYPESUCCESSFUL*SUMSYNONYM*SYSDATE*TABLE*THEN*TIMETIMESTAMPTO*

TRIGGER*TRUETYPEUID*UNION*UNIQUE*UPDATE*USEUSER*VALIDATE*VALUES*VARCHAR*VARCHAR2*VARIANCEVIEW*WHENWHENEVER*WHERE*WHILEWITH*WORKWRITEYEARZONE

Page 10: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 10 Oracle PL/SQL Quick Reference

Words followed by an asterisk (*) are also ANSI reserved words.

SQL Reserved Words

ACCESSADDALL*ALTERAND*ANY*AS*ASC*AUDITBETWEEN*BY*CHAR*CHECK*CLUSTERCOLUMNCOMMENTCOMPRESSCONNECTCREATE*CURRENT*DECIMALDEFAULT*DELETE*DESC*DISTINCT*DROPELSE

EXCLUSIVEEXISTS*FILEFLOAT*FOR*FROM*GRANT*GROUP*HAVING*IDENTIFIEDIMMEDIATEIN*INCREMENTINDEXINITIALINSERT*INTEGER*INTERSECTINTO*IS*LEVELLIKE*LOCKLONGMAXEXTENTSMINUSMLSLABEL

MODEMODIFYNOAUDITNOCOMPRESSNOT*NOWAITNULL*NUMBEROF*OFFLINEON*ONLINEOPTION*OR*ORDER*PCTFREEPRIORPRIVILEGES*PUBLIC*RAWRENAMERESOURCEREVOKEROWROWIDROWNUMROWS

SELECT*SESSIONSET*SHARESIZESMALLINT*STARTSUCCESSFULSYNONYMSYSDATETABLE*THENTO*TRIGGERUIDUNION*UNIQUE*UPDATE*USER*VALIDATEVALUES*VARCHARVARCHAR2VIEW*WHENEVERWHERE*WITH*

Page 11: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 11

Words followed by an asterisk (*) are also ANSI reserved words.

SQL Keywords

ADMINAFTERALLOCATEANALYZEARCHIVEARCHIVELOGAUTHORIZATION*AVG*BACKUPBECOMEBEFOREBEGIN*BLOCKBODYCACHECANCELCASCADECHANGECHARACTER*CHECKPOINTCLOSE*COBOL*COMMIT*COMPILECONSTRAINTCONSTRAINTSCONTENTSCONTINUE*CONTROLFILECOUNT*CURSOR*CYCLEDATABASEDATAFILEDBADEC*DECLARE*DISABLEDISMOUNTDOUBLE*DUMPEACHENABLE

END*ESCAPE*EVENTSEXCEPTEXCEPTIONSEXEC*EXECUTEEXPLAINEXTENTEXTERNALLYFETCH*FLUSHFORCEFOREIGN*FORTRAN*FOUND*FREELISTFREELISTSFUNCTIONGO*GOTO*GROUPSINCLUDINGINDICATOR*INITRANSINSTANCEINT*KEY*LANGUAGE*LAYERLINKLISTSLOGFILEMANAGEMANUALMAX*MAXDATAFILESMAXINSTANCESMAXLOGFILESMAXLOGHISTORYMAXLOGMEMBERSMAXTRANSMAXVALUE

MIN*MINEXTENTSMINVALUEMODULE*MOUNTNEXTNEWNOARCHIVELOGNOCACHENOCYCLENOMAXVALUENOMINVALUENONENOORDERNORESETLOGSNORMALNOSORTNUMERIC*OFFOLDONLYOPEN*OPTIMALOWNPACKAGEPARALLELPASCAL*PCTINCREASEPCTUSEDPLANPLI*PRECISION*PRIMARY*PRIVATEPROCEDURE*PROFILEQUOTAREADREAL*RECOVERREFERENCES*REFERENCINGRESETLOGS

RESTRICTEDREUSE ROLEROLESROLLBACK*SAVEPOINTSCHEMA*SCNSECTION*SEGMENTSEQUENCESHAREDSNAPSHOTSOME*SORTSQLCODE*SQLERROR*STATEMENT_IDSTATISTICSSTOPSTORAGESUM*SWITCHSYSTEMTABLESTABLESPACETEMPORARYTHREADTIMETRACINGTRANSACTIONTRIGGERSTRUNCATEUNDERUNLIMITEDUNTILUSEUSINGWHENWRITEWORK*

Page 12: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 12 Oracle PL/SQL Quick Reference

SYSTEM PRIVILEGES

PROCEDURES

System Privilege Allows Grantee To ...

CREATE PROCEDURE Create stored procedures, functions, andpackages in grantee’s schema

CREATE ANY PROCEDURE Create stored procedures, functions, andpackages in any schema except SYS

ALTER ANY PROCEDURE Alter stored procedures, functions, orpackages in any schema except SYS

DROP ANY PROCEDURE Drop stored procedures, functions, orpackages in any schema except SYS

EXECUTE ANY PROCEDURE Execute procedures or functions (standaloneor packaged)Reference public package variables in anyschema except SYS

TRIGGER

System Privilege Allows Grantee To ...

CREATE TRIGGER Create a database trigger in grantee’s schemaCREATE ANY TRIGGER Create database triggers in any schema except

SYSALTER ANY TRIGGER Enable, disable, or compile database triggers

in any schema except SYSDROP ANY TRIGGER Drop any trigger in any schema except SYSADMINISTER DATABASETRIGGER

Create a trigger on DATABASE (You mustalso have the CREATE TRIGGER orCREATE ANY TRIGGER privilege.)

TYPES

System Privilege Allows Grantee To ...

CREATE TYPE Create object types and object type bodies ingrantee’s schema

CREATE TYPE Create object types and object type bodies inany schema except SYS

ALTER ANY TYPE Alter object types in any schema except SYSDROP ANY TYPE Drop object types and object type bodies in

any schema except SYSEXECUTE ANY TYPE Use and reference object types and collection

types in any schema except SYS, and invokemethods of an object type in any schema if youmake the grant to a specific user (If you grantEXECUTE ANY TYPE to a role, usersholding the enabled role will not be able toinvoke methods of any object type in anyschema.)

Page 13: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 13

OBJECT PRIVILEGES

These privileges apply to specific objects.

Object Privilege Allows Grantee To ...ALL [PRIVILEGES] All of the object privileges that can be applied

TABLE PRIVILEGESALTER Change the table definition with the ALTER TABLE

statementDELETE Remove rows from the table with the DELETE statement

Note: You must grant the SELECT privilege on the tablealong with the DELETE privilege

INDEX Create an index on the table with the CREATE INDEXstatement

INSERT Add new rows to the table with the INSERT statementREFERENCES Create a constraint that refers to the table. (You cannot

grant this privilege to a role.)SELECT Query the table with the SELECT statementUPDATE Change data in the table with the UPDATE statement

Note: You must grant the SELECT privilege on the tablealong with the UPDATE privilege.

VIEW PRIVILEGESDELETE Remove rows from the view with the DELETE statementINSERT Add new rows to the view with the INSERT statementSELECT Query the view with the SELECT statement.UPDATE Change data in the view with the UPDATE statement

SEQUENCE PRIVILEGESALTER Change the sequence definition with the ALTER

SEQUENCE statementSELECT Examine and increment values of the sequence with the

CURRVAL and NEXTVAL pseudocolumns

PROCEDURE, FUNCTION, and PACKAGE PRIVILEGEEXECUTE Compile the procedure or function or execute it directly, or

access any program object declared in the specification of apackage

SNAPSHOT PRIVILEGESELECT Query the snapshot with the SELECT statement

Page 14: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 14 Oracle PL/SQL Quick Reference

ObjectPrivilege Table View Sequence

Procedures,Functions,Packages

User-DefinedType

ALTER X XDELETE X XINDEX XINSERT X XREADREFERENCES XSELECT X X XUPDATE X XEXECUTE X X

Built-in FunctionsPL/SQL provides many powerful functions to help you manipulate data. These built-in functions fallinto the following categories:

• Error-reporting• Number• Character• Conversion• Date• Miscellaneous

You can use all the functions in SQL statements except the error-reporting functions SQLCODE andSQLERRM. Also, you can use all the functions in procedural statements except the miscellaneousfunctions DECODE, DUMP, and VSIZE.The SQL group functions AVG, MIN, MAX, COUNT, SUM, STDDEV, and VARIANCE are notbuilt into PL/SQL. Nevertheless, you can use them in SQL statements but not in proceduralstatements.

Page 15: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 15

Error Number Character ConversionSQLCODE ABS ASCII CHARTOROWIDSQLERRM ACOS CHR CONVERT

ASIN CONCAT HEXTORAWATAN INITCAP RAWTOHEXATAN2 INSTR ROWIDTOCHARCEIL INSTRB TO_CHARCOS LENGTH TO_DATECOSH LENGTHB TO_MULTI_BYTEEXP LOWER TO_NUMBERFLOOR LPAD TO_SINGLE_BYT

ELN LTRIMLOG NLS_INITCAPMOD NLS_LOWERPOWER NLS_UPPERROUND NLSSORTSIGN REPLACESIN RPADSINH RTRIMSQRT SOUNDEXTAN SUBSTRTANH SUBSTRBTRUNC TRANSLATE

TRIMUPPER

Date Object Reference MiscellaneousADD_MONTHS DEREF BFILENAMELAST_DAY REF DECODEMONTHS_BETWEEN

VALUE DUMP

NEW_TIME EMPTY_BLOBNEXT_DAY EMPTY_CLOBROUND GREATESTSYSDATE LEASTTRUNC NLS_CHARSET_DECL_LEN

NLS_CHARSET_IDNLS_CHARSET_NAMENVLSYS_CONTEXTSYS_GUIDUIDUSERUSERENVVSIZE

Page 16: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 16 Oracle PL/SQL Quick Reference

SQL Commands Syntax

ALTER FUNCTIONUse this command to recompile an invalid stand-alone stored function.

ALTER PACKAGEUse this command to explicitly recompile either a package specification, body, or both.

ALTER PROCEDUREUse this command to explicitly recompile a stand-alone stored procedure.

ALTER TRIGGERUse this command to enable, disable, or compile a database trigger.

DROP FUNCTIONUse this command to remove a stored function from the database.

DROP PACKAGEUse this command to remove a stored package from the database. This statement drops the body andspecification of a package.

DROP PROCEDUREUse this command to remove a stored procedure from the database.

Page 17: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 17

DROP TRIGGERUse this command to remove a database trigger from the database.

Page 18: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 18 Oracle PL/SQL Quick Reference

PL/SQL Language Elements

Assignment StatementAn assignment statement sets the current value of a variable, field, parameter, or element.

BlockThe basic program unit in PL/SQL is the block.

Page 19: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 19

Page 20: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 20 Oracle PL/SQL Quick Reference

CALLAllows you to execute a stand-alone procedure or function, or a procedure or function defined withina type or package.

CLOSE StatementThe CLOSE statement enables resources held by an open cursor or cursor variable to be reused. Nomore rows can be fetched from a closed cursor or cursor variable.

Page 21: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 21

Collection MethodA collection method is a built-in function or procedure that operates on collections and is called usingdot notation. The methods EXISTS, COUNT, LIMIT, FIRST, LAST, PRIOR, NEXT, EXTEND,TRIM, and DELETE help generalize code, make collections easier to use, and make your applicationseasier to maintain.

CollectionA collection is an ordered group of elements, all of the same type (for example, the grades for a classof students). Each element has a unique subscript that determines its position in the collection.PL/SQL offers three kinds of collections: index-by tables, nested tables, and varrays.

Page 22: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 22 Oracle PL/SQL Quick Reference

CommentsComments can appear within a statement at the end of a line. You cannot nest comments.

COMMIT StatementThe COMMIT statement explicitly makes permanent any changes made to the database during thecurrent transaction.

Page 23: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 23

Constant and VariableYou can declare constants and variables in the declarative part of any PL/SQL block, subprogram, orpackage. Declarations allocate storage space for a value, specify its datatype, and name the storagelocation so that you can reference it. Declarations can also assign an initial value and impose the NOTNULL constraint.

Page 24: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 24 Oracle PL/SQL Quick Reference

Cursor AttributeCursors and cursor variables have four attributes that give you useful information about the executionof a data manipulation statement.

Cursor VariableTo execute a multirow query, Oracle server opens an unnamed work area that stores processinginformation. To access the information, you can use an explicit cursor, which names the work area.Or you can use a cursor variable, which points to the work area.

Page 25: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 25

CursorTo execute a multirow query, the Oracle server opens an unnamed work area that stores processinginformation. A cursor enables you to name the work area, access the information, and process therows individually.

Page 26: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 26 Oracle PL/SQL Quick Reference

DELETE StatementThe DELETE statement removes entire rows of data from a specified table or view.

EXCEPTION_INIT PRAGMAThe PRAGMA EXCEPTION_INIT associates an exception name with an Oracle error number. Thisenables you to refer to any internal exception by name and to write a specific handler for it instead ofusing the OTHERS handler.

Page 27: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 27

ExceptionAn exception is a run-time error or warning condition, which can be predefined or user-defined.Predefined exceptions are raised implicitly (automatically) by the run-time system. User-definedexceptions must be raised explicitly by RAISE statements. To handle raised exceptions, you writeseparate routines called exception handlers.

EXECUTE IMMEDIATE StatementThe EXECUTE IMMEDIATE statement prepares (parses) and immediately executes a dynamic SQLstatement or an anonymous PL/SQL block.

EXIT StatementYou use the EXIT statement to exit a loop.

Page 28: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 28 Oracle PL/SQL Quick Reference

ExpressionAn expression is an arbitrarily complex combination of variables, constants, literals, operators, andfunction calls.

Page 29: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 29

Page 30: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 30 Oracle PL/SQL Quick Reference

Page 31: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 31

FETCH StatementThe FETCH statement retrieves rows of data one at a time from the result set of a multirow query.The data is stored in variables or fields that correspond to the columns selected by the query.

Page 32: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 32 Oracle PL/SQL Quick Reference

FORALL StatementThe FORALL statement instructs the PL/SQL engine to bulk-bind input collections before sendingthem to the SQL engine. Although the FORALL statement contains an iteration scheme, it is not aFOR loop.

FunctionsA function is a subprogram that can take parameters and be invoked. Generally, you use a function tocompute a value.

Page 33: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 33

GOTO StatementThe GOTO statement branches unconditionally to a statement label or block label.

IF StatementThe IF statement lets you execute a sequence of statements conditionally. Whether the sequence isexecuted or not depends on the value of a Boolean expression.

INSERT StatementThe INSERT statement adds new rows of data to a specified database table or view.

Page 34: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 34 Oracle PL/SQL Quick Reference

LiteralA literal is an explicit numeric, character, string, or Boolean value not represented by an identifier.The numeric literal 135 and the string literal ’hello world’ are examples.

LOCK TABLE StatementThe LOCK TABLE statement enables you to lock entire database tables in a specified lock mode. Inthis way you can share or deny access to the tables while maintaining their integrity.

Page 35: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 35

LOOP StatementThe LOOP statement executes a sequence of statements multiple times. The loop encloses thesequence of statements that is to be repeated. PL/SQL provides basic loops, WHILE loops, FORloops, and cursor FOR loops.

NULL StatementThe NULL statement explicitly specifies inaction; it does nothing other than pass control to the nextstatement. In a construct allowing alternative actions, the NULL statement serves as a placeholder.

Page 36: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 36 Oracle PL/SQL Quick Reference

Object TypeAn object type is a user-defined composite datatype that encapsulates a data structure along with thefunctions and procedures needed to manipulate the data. The variables that form the data structure arecalled attributes. The functions and procedures that characterize the behavior of the object type arecalled methods.

OPEN StatementThe OPEN statement executes the multirow query associated with an explicit cursor. It also allocatesresources that Oracle uses to process the query, and it identifies the result set, which consists of allrows that meet the query search criteria.

OPEN-FOR StatementThe OPEN-FOR statement executes the multirow query associated with a cursor variable. It alsoallocates resources that Oracle server uses to process the query, and it identifies the result set, whichconsists of all rows that meet the query search criteria.

Page 37: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 37

OPEN-FOR-USING StatementThe OPEN-FOR-USING statement associates a cursor variable with a multirow query, executes thequery, identifies the result set, positions the cursor on the first row in the result set, then zeroes therows-processed count kept by %ROWCOUNT.

PackageA package is a schema object that groups logically related PL/SQL types, items, and subprograms.Packages have two parts: a specification (spec for short) and a body.

Page 38: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 38 Oracle PL/SQL Quick Reference

ProcedureA procedure is a subprogram that can take parameters and be invoked. Generally, you use aprocedure to perform an action.

Page 39: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 39

RAISE StatementThe RAISE statement stops normal execution of a PL/SQL block or subprogram and transfers controlto the appropriate exception handler.

RecordsRecords are items of type RECORD. Records have uniquely named fields that can store data values ofdifferent types.

RETURN StatementThe RETURN statement immediately completes the execution of a subprogram and returns control tothe caller. Execution then resumes with the statement following the subprogram call. In a function, theRETURN statement also sets the function identifier to the result value.

ROLLBACK StatementThe ROLLBACK statement is the inverse of the COMMIT statement. It undoes some or all databasechanges made during the current transaction.

Page 40: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 40 Oracle PL/SQL Quick Reference

%ROWTYPE AttributeThe %ROWTYPE attribute provides a record type that represents a row in a database table. Therecord can store an entire row of data selected from the table or fetched from a cursor or cursorvariable. Fields in a record and corresponding columns in a row have the same names and datatypes.

SAVEPOINT StatementThe SAVEPOINT statement names and marks the current point in the processing of a transaction.With the ROLLBACK TO statement, savepoints enable you to undo parts of a transaction instead ofthe whole transaction.

SELECT INTO StatementThe SELECT INTO statement retrieves data from one or more database tables, then assigns theselected values to variables or fields.

Page 41: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 41

SET TRANSACTION StatementThe SET TRANSACTION statement begins a read-only or read-write transaction, establishes anisolation level, or assigns the current transaction to a specified rollback segment.

SQL CursorThe Oracle server implicitly opens a cursor to process each SQL statement that is not associated withan explicit cursor. PL/SQL lets you refer to the most recent implicit cursor as the SQL cursor, whichhas four attributes: %FOUND, %ISOPEN, %NOTFOUND, and %ROWCOUNT. These attributesgive you useful information about the execution of data manipulation statements.

Page 42: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 42 Oracle PL/SQL Quick Reference

SQLCODE FunctionThe function SQLCODE returns the number code associated with the most recently raised exception.SQLCODE is meaningful only in an exception handler. Outside a handler, SQLCODE always returns0.

SQLERRM FunctionThe function SQLERRM returns the error message associated with its error-number argument or, ifthe argument is omitted, with the current value of SQLCODE. SQLERRM with no argument ismeaningful only in an exception handler. Outside a handler, SQLERRM with no argument alwaysreturns the message of a normal, successful completion.

%TYPE AttributeThe %TYPE attribute provides the datatype of a field, record, nested table, database column, orvariable. You can use the %TYPE attribute as a datatype specifier when declaring constants,variables, fields, and parameters.

Page 43: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Oracle PL/SQL Quick Reference Page 43

TriggerA trigger is a stored PL/SQL block associated with a table, a schema, or the database.

dml_event_clause

referencing_clause

Page 44: Oracle PL/SQL Quick Reference - gopinadhs · PDF filePage 4 Oracle PL/SQL Quick Reference Functions 32 GOTO Statement 33 IF Statement 33 INSERT Statement 33 Literal 34 LOCK TABLE Statement

______________________________________________________________________________________________ Page 44 Oracle PL/SQL Quick Reference

UPDATE StatementThe UPDATE statement changes the values of specified columns in one or more rows in a table orview.