Cover | Table of Contents
Constant width is used for code examples and
output.
[] enclose optional items in syntax descriptions.{ } enclose a list of items in syntax
descriptions; you must choose one item from the list.
| separates bracketed list items in syntax
descriptions.
Constant width is used for code examples and
output.
[] enclose optional items in syntax descriptions.{ } enclose a list of items in syntax
descriptions; you must choose one item from the list.
| separates bracketed list items in syntax
descriptions.
|
Type
|
Characters
|
|---|---|
|
Letters
|
A-Z, a-z |
|
Digits
|
0-9 |
|
Symbols
|
~!@#$%^&*( )_-+=|[ ]{ }:;"'< >,.?/ ^
|
|
Whitespace
|
space, tab, newline, carriage return |
|
Type
|
Description
|
|---|---|
|
Scalar
|
Variables made up of a single value, such as a number, date, or
Boolean
|
|
Composite
|
Variables made up of multiple values, such as a record or a collection
|
|
Reference
|
Pointers to values
|
|
LOB
|
Variables containing large object (LOB) locators
|
IF condition THEN executable statement(s) END IF;
IF caller_type = 'VIP' THEN
generate_response('GOLD');
END IF;
IF condition THEN TRUE sequence_of_executable_statement(s) ELSE FALSE/NULL sequence_of_executable_statement(s) END IF;
IF caller_type = 'VIP' THEN
generate_response('GOLD');
ELSE
generate_response('BRONZE');
END IF;
IF condition-1 THEN statements-1 ELSIF condition-N THEN statements-N [ELSE ELSE statements] END IF;
IF caller_type = 'VIP' THEN
generate_response('GOLD');
ELSIF priority_client THEN
generate_response('SILVER');
ELSE
generate_response('BRONZE');
END IF;
CASE region_id
WHEN 'NE' THEN
mgr_name := 'MINER';
WHEN 'SE' THEN
mgr_name := 'KOOI';
ELSE mgr_name := 'LANE';
END CASE;
LOOP
executable_statement(s)
END LOOP;
LOOP
FETCH company_cur INTO company_rec;
EXIT WHEN company_cur%ROWCOUNT > 5 OR
company_cur%NOTFOUND;
process_company(company_cur);
END LOOP;
FOR loop_index IN [REVERSE] lowest_number..highest_number LOOP executable_statement(s) END LOOP;
BEGIN
FOR counter IN 1 .. 4
LOOP
DBMS_OUTPUT.PUT(counter);
END LOOP;
DBMS_OUTPUT.NEW_LINE;
FOR counter IN REVERSE 1 .. 4
LOOP
DBMS_OUTPUT.PUT(counter);
END LOOP;
DBMS_OUTPUT.NEW_LINE;END;
1234 4321
FOR record_index IN [cursor_name | (SELECT statement)] LOOP executable_statement(s) END LOOP;
COMMIT [WORK] [COMMENT text];
ROLLBACK [WORK] [TO [SAVEPOINT] savepoint_name];
CURSOR company_cur IS SELECT company_id FROM company;
CURSOR company_cur (id_in IN NUMBER) IS SELECT name FROM company WHERE company_id = id_in;
CURSOR company_cur (id_in IN NUMBER) RETURN company%ROWTYPE;
DECLARE
exception_name EXCEPTION;
|
Error
|
Named exception
|
|---|---|
|
ORA-00001
|
DUP_VAL_ON_INDEX
|
|
ORA-00051
|
TIMEOUT_ON_RESOURCE
|
|
ORA-00061
|
TRANSACTION_BACKED_OUT
|
|
ORA-01001
|
INVALID_CURSOR
|
|
ORA-01012
|
NOT_LOGGED_ON
|
|
ORA-01017
|
LOGIN_DENIED
|
|
ORA-01403
|
NO_DATA_FOUND
|
|
ORA-01410
|
SYS_INVALID_ROWID
|
DECLARE
-- Declare table-based record for company table.
comp_rec company%ROWTYPE
CURSOR comp_summary_cur IS
SELECT C.company_id,SUM(S.gross_sales) gross
FROM company C ,sales S
WHERE C.company_id = S.company_id;
-- Declare a cursor-based record.
comp_summary_rec comp_summary_cur%ROWTYPE;
DECLARE
TYPE name_rectype IS RECORD(
prefix VARCHAR2(15)
,first_name VARCHAR2(30)
,middle_name VARCHAR2(30)
,sur_name VARCHAR2(30)
,suffix VARCHAR2(10) );
TYPE employee_rectype IS RECORD (
emp_id NUMBER(10) NOT NULL
,mgr_id NUMBER(10)
,dept_no dept.deptno%TYPE
,title VARCHAR2(20)
,name empname_rectype
,hire_date DATE := SYSDATE
,fresh_out BOOLEAN );
-- Declare a variable of this type.
new_emp_rec employee_rectype;
BEGIN
record_name.field_name
CREATE [OR REPLACE] PROCEDURE name [ (parameter [,parameter]) ] [AUTHID { CURRENT_USER | DEFINER } ] [DETERMINISTIC] { IS | AS } declaration_section BEGIN executable_section [EXCEPTION exception_section] END [name];
apply_discount(new_company_id, 0.15);
CREATE [OR REPLACE] FUNCTION name [ (parameter [,parameter]) ] RETURN return_datatype [AUTHID { CURRENT_USER | DEFINER } ] [DETERMINISTIC] [PARALLEL_ENABLE] [PIPELINED] [AGGREGATE USING] { IS | AS } [declaration_section] BEGIN
CREATE [OR REPLACE] TRIGGER trigger_name { BEFORE | AFTER | INSTEAD OF } trigger_event ON {table_or_view_reference | NESTED TABLE nested_table_column OF view} [REFERENCING [OLD AS old] [NEW AS new] [PARENT AS parent]] [FOR EACH ROW ][WHEN trigger_condition] trigger_body;
CREATE [OR REPLACE] TRIGGER trigger_name { BEFORE | AFTER } trigger_event ON [ DATABASE | schema ] [WHEN trigger_condition] trigger_body;
|
Trigger event
|
Description
|
|---|---|
|
INSERT
|
Fires whenever a row is added to the
table_or_view_reference.
|
|
UPDATE
|
Fires whenever an UPDATE changes the
table_or_view_reference |
CREATE [OR REPLACE] PACKAGE package_name [ AUTHID { CURRENT_USER | DEFINER } ] { IS | AS } [definitions of public TYPEs ,declarations of public variables, types, and objects ,declarations of exceptions ,pragmas ,declarations of cursors, procedures, and functions ,headers of procedures and functions] END [package_name];
CREATE [OR REPLACE] PACKAGE BODY package_name { IS | AS } [definitions of private TYPEs ,declarations of private variables, types, and objects ,full definitions of cursors ,full definitions of procedures and functions
[schema_name.][pkg_name.]func_name[@db_link] [parm_list]
-- Capture system events. INSERT INTO v_sys_event (timestamp ,event ,qty_waits) SELECT time_pkg.GetTimestamp ,event ,total_waits FROM v$system_event -- Capture system statistics. INSERT INTO v_sys_stat (timestamp,stat#,value) SELECT time_pkg.GetTimestamp ,statistic# ,value FROM v$sysstat;
CREATE TABLE table_name OF object_type;
CREATE [OR REPLACE] TYPE obj_type_name [AUTHID { CURRENT_USER | DEFINER } ] { { IS | AS } OBJECT | UNDER parent_type_name } ( attribute_name datatype,..., [ [ [NOT] OVERRIDING ] [ {NOT] FINAL ] [ {NOT} INSTANTIABLE ] method_spec,...,] [PRAGMA RESTRICT_REFERENCES(program_name, purities)] ) [ [NOT] FINAL ] [ [NOT] INSTANTIABLE ];
MEMBER { PROCEDURE | FUNCTION } program_spec
STATIC { PROCEDURE | FUNCTION } program_spec
{ ORDER | MAP } MEMBER FUNCTION comparison_function_spec
CONSTRUCTOR FUNCTION constructor_function_spec
|
Collection type
| |||
|---|---|---|---|
|
Characteristic
|
Associative array
|
Nested table
|
VARRAY
|
|
Dimensionality
|
Single
|
Single
|
Single
|
|
Usable in SQL?
|
No
|
LISTENER = (ADDRESS = (PROTOCOL=TCP)(HOST=hostname)(PORT=1521)) EXTPROC_LISTENER = (ADDRESS = (PROTOCOL = IPC)(KEY = extprocKey)) SID_LIST_LISTENER = (SID_DESC = (GLOBAL_DBNAME = global_name) (ORACLE_HOME = oracle_home_directory) (SID_NAME = SID) ) SID_LIST_EXTPROC_LISTENER = (SID_DESC = (SID_NAME = extprocSID) (ORACLE_HOME = oracle_home_directory) (ENVS = "EXTPROC_DLLS= qualifier:shared_object_file_list") (PROGRAM = extproc) )
ACCESS |
ADD |
ALL |
ALTER |
AND |
ANY |
AS |
ASC |
AT |
AUDIT |
BEGIN |
BETWEEN |
BY |
CASE |
CHAR |
CHECK |
CLOSE |
CLUSTER |
COLUMN |
COLUMNS |
COMMENT |
COMMIT |
COMPRESS |
CONNECT |
CREATE |
CURRENT |
CURSOR |
Return to Oracle PL/SQL Language Pocket Reference