Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
335 views

Oracle PLSQL Quick Reference Card

This document provides a quick reference to common Oracle PL/SQL statements and concepts such as the SELECT statement, data manipulation statements like INSERT and UPDATE, data definition statements for creating tables and views, data dictionary tables, and constraints. It covers topics such as joins, aggregation, subqueries, transactions, and altering database objects.

Uploaded by

gongorac
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
335 views

Oracle PLSQL Quick Reference Card

This document provides a quick reference to common Oracle PL/SQL statements and concepts such as the SELECT statement, data manipulation statements like INSERT and UPDATE, data definition statements for creating tables and views, data dictionary tables, and constraints. It covers topics such as joins, aggregation, subqueries, transactions, and altering database objects.

Uploaded by

gongorac
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Oracle PL/SQL Quick Reference WHERE condition) ; IS ‘text’ ;

Manipulating Data Dropping a comment from a table


SELECT Statement
INSERT Statement(one row) COMMENT ON TABLE table | COLUMN table.column IS ‘’ ;
SELECT [DISNCT] {*, column [alias],...}
INSERT INTO table [ (column [,column...])] Data Dictionary
FROM table
VALUES (value [,value...]) ; ALL_OBJECTS USER_OBJECTS
[WHERE condition(s)]
INSERT Statement with Subquery ALL_TABLES USER_TABLES
[ORDER BY {column, exp, alias} [ASC|DESC]]
INSERT INTO table [ column(, column) ] ALL_CATALOG USER_CATALOG or CAT
Cartesian Product
subquery ; ALL_COL_COMMENTS USER_COL_COMMENTS
SELECT table1.*, table2.*,[...]
UPDATE Statement ALL_TAB_COMMENTS USER_TAB_COMMENTS
FROM table1,table2[,...]
UPDATE table Defineing Constraints
Equijoin(Simple joins or inner join)
SET column = value [, column = value,...] CREATE TABLE [schema.]table
SELECT table1.*,table2.*
[WHERE condition] ; (column datatype [DEFAULT expr][NOT NULL]
FROM table1,table2
Updating with Multiple-column Subquery [column_constraint],...
WHERE table1.column = table2.column
UPDATE table [table_constraint][,...]) ;
Non-Equijoins
SET (column, column,...) = Column constraint level
SELECT table1.*, table2.*
(SELECT column, column,... column [CONSTRAINT constraint_name] constraint_type,
FROM table1, table2
FROM table Constraint_type
WHERE table1.column
WHERE condition) PRIMARY KEY REFERENCES table(column) UNIQUE
BETWEEN table2.column1 AND table2.column2
WHERE condition ; CHECK (codition)
Outer joins
Deleting Rows with DELETE Statement Table constraint level(except NOT NULL)
SELECT table1.*,table2.*
DELETE [FROM] table column,...,[CONSTRAINT constraint_name]
FROM table1,table2
[WHERE conditon] ; constraint_type (column,...),
WHERE table1.column(+) = table2.column
Deleting Rows Based on Another Table NOT NULL Constraint (Only Column Level)
SELECT table1.*,table2.*
DELETE FROM table CONSTRAINT table[_column...]_nn NOT NULL ...
FROM table1,table2
WHERE column = (SELECT column UNIQUE Key Constraint
WHERE table1.column = table2.column(+)
FROM table CONSTRAINT table[_column..]_uk UNIQUE (column[,...])
Self joins
WHERE condtion) ; PRIMARY Key Constraint
SELECT alias1.*,alias2.*
Transaction Control Statements CONSTRAINT table[_column..]_pk PRIMARY (column[,...])
FROM table1 alias1,table1 alias2
COMMIT ; FOREIGN Key Constraint
WHERE alias1.column = alias2.column
SAVEPOINT name ; CONSTRAINT table[_column..]_fk
Aggregation Selecting
ROLLBACK [TO SAVEPOINT name] ; FOREIGN KEY (column[,...])
SELECT [column,] group_function(column)
CREATE TABLE Statement REFERENCES table (column[,...])[ON DELETE CASCADE]
FROM table
CREATE TABLE [schema.]table CHECK constraint
[WHERE condition]
(column datatype [DEFAULT expr] [,...]) ; CONSTRAINT table[_column..]_ck CHECK (condition)
[GROUP BY group_by_expression]
CREATE TABLE Statement with Subquery Adding a Constraint(except NOT NULL)
[HAVING group_condition]
CREATE TABLE [schema.]table ALTER TABLE table
[ORDER BY column] ;
[(column, column...)] ADD [CONSTRAINT constraint_name ] type (column) ;
Group function
AS subquery Adding a NOT NULL constraint
AVG([DISTINCT|ALL]n)
Datatype ALTER TABLE table
COUNT(*|[DISTINCT|ALL]expr)
VARCHAR2(size) CHAR(size) NUMBER(p,s) DATE MODIFY (column datatype [DEFAULT expr]
MAX([DISTINCT|ALL]expr)
LONG CLOB RAW LONG RAW [CONSTRAINT constraint_name_nn] NOT NULL) ;
MIN([DISTINCT|ALL]expr)
BLOB BFILE Dropping a Constraint
STDDEV([DISTINCT|ALL]n)
ALTER TABLE Statement (Add columns) ALTER TABLE table
SUM([DISTINCT|ALL]n)
ALTER TABLE table DROP CONSTRAINT constraint_name ;
VARIANCE([DISTINCT|ALL]n)
ADD (column datatype [DEFAULT expr] ALTER TABLE table
Subquery
[, column datatype]...) ; DROP PRIMARY KEY | UNIQUE (column) |
SELECT select_list
Changing a column’s type, size and default of a Table CONSTRAINT constraint_name [CASCADE] ;
FROM table
ALTER TABLE table Disabling Constraints
WHERE expr operator(SELECT select_list FROM table);
MODIFY (column datatype [DEFAULT expr] ALTER TABLE table
single-row comparison operators
[, column datatype]...) ; DISABLE CONSTRAINT constraint_name [CASCADE] ;
= > >= < <= <>
Dropping a Table Enabing Constraints
multiple-row comparison operators
DROP TABLE table ; ALTER TABLE table
IN ANY ALL
Changing the Name of an Object ENABLE CONSTRAINT constraint_name ;
Multiple-column Subqueries
RENAME old_name TO new_name ; Data Dictionary
SELECT column, column, ...
Trancating a Table ALL_CONSTRAINTS USER_CONSTRAINTS
FROM table
TRUNCATE TABLE table ; ALL_CONS_COLUMNS USER_CONS_COLUMNS
WHERE (column, column, ...) IN
Adding Comments to a Table Creating a View
(SELECT column, column, ...
COMMENT ON TABLE table | COLUMN table.column CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view
FROM table Rev. January 18,2001
[(alias[, alias]...)] Dropping Roles TABLE RECORD NESTED TABLE VARRAY
AS subquery DROP ROLE role ; LOB Datatypes
[WITH CHECK OPTION [CONSTRAINT constraint_name]] Object Privileges CLOB BLOB BFILE NCLOB
[WITH READ ONLY] ; Object Table View Sequence Procedure Creating Bind Variables
Removing a View ALTER X X VARIABLE variable_name dataype
DROP VIEW view ; DELETE X X Displaying Bind Variables
CREATE SEQUENCE Statement EXECUTE X PRINT [variable_name]
CREATE SEQUENCE sequence INDEX X Commenting Code
[INCREMENT BY n] INSERT X X --prefix single-line comments with two dashes
[START WITH n] REFERENCES X /* Place muti-line comment between the symbols */
[{MAXVALUE n| NOMAXVALUE}] SELECT X X X SELECT Statements in PL/SQL
[{MINVALUE n| NOMINVALUE}] UPDATE X X SELECT {column_list|*}
[{CYCLE | NOCYCLE}] Object Privileges INTO {variable_name[,variable_name]...
[{CACHE [n|20]| NOCACHE}] ; GRAND object_priv [(column)] |record_name}
Pseudocolumns ON object FROM table
sequence.NEXTVAL sequence.CURRVAL TO {user|role|PUBLIC} WHERE condition
Modifying a Sequence (No START WITH option) [WITH GRANT OPTION] ; Implicit Cursor Attributes for DML statements
ALTER SEQUENCE sequence Revoking Object Privileges SQL%ROWCOUNT
[INCREMENT BY n] REVOKE {privilege [,privilege...] | ALL} SQL%FOUND
[{MAXVALUE n| NOMAXVALUE}] ON object SQL%NOTFOUND
[{MINVALUE n| NOMINVALUE}] FROM {user[,user...]|role|PUBLIC} SQL%ISOPEN
[{CYCLE | NOCYCLE}] [CASCADE CONSTRAINTS] ; Constrol Structures
[{CACHE [n|20]| NOCACHE}] ; Data Dictionary IF Statement Basic Loop
Removing a Sequence ROLE_SYS_PRIVS IF condition THEN LOOP
DROP SEQUENCE sequence ; ROLE_TAB_PRIVS USER_ROLE_PRIVS statements ; statements;
Creating an Index USER_TAB_PRIVS_MADE USER_TAB_PRIVS_RECD [ELSIF condition THEN ...
CREATE INDEX index USER_COL_PRIVS_MADE USER_COL_PRIVS_RECD statements ;] EXIT [WHEN condition];
ON TABLE (column[,column]...) ; PL/SQL Block Structure [ELSE END LOOP
Removing an Index DECLARE --Optional statements;]
DROP INDEX index ; --Variables, Cursors, User-defined exceptions END IF ;
Synoyms BEGIN --Mandatory FOR Loop WHILE Loop
CREATE [PUBLIC] SYNONYM synonym FOR object ; --SQL statements FOR conter in [REVERSE] WHILE condition LOOP
Removing Synonyms --PL/SQL statements lower..upper LOOP statement1;
DROP SYNONYM synonym ; EXCEPTION --Optional statement1; statement2;
Data Dictionary --Actions to perform when errors occur statement2; ...
ALL_VIEWS USER_VIEWS END ; --Mandatory ... END LOOP ;
ALL_SEQUENCES USER_SEQUENCES PL/SQL Block Type END LOOP;
ALL_INDEXES USER_INDEXES Anonymous Procedure Function Creating a PL/SQL Record
ALL_IND_COLUMNS USER_IND_COLUMNS [DECLARE] PROCEDURE name FUNCTION name TYPE record_name_type IS RECORD
System Privileges(DBA) User System Privileges IS RETURN datatype IS (field_declaration[,field_declaration]...) ;
CREATE USER CREATE SESION [DECLARE] [DECLARE] record_name record_name_type ;
DROP USER CREATE TABLE BEGIN BEGIN BEGIN Where field_declaration is
DROP ANY TABLE CREATE SEQUENCE --statements --statements --statements field_name {field_type|variable%TYPE|
BACKUP ANY TABLE CREATE VIEW [EXCEPTION] [EXCEPTION] [EXCEPTION] table.column%TYPE|table%ROWTYPE}
CREATE PROCEDURE END ; END ; END ; [[NOT NULL] {:=|DEFAULT} expr]
Creating Users Declaring PL/SQL Variables Referencing Fields in the Record
CREATE USER user identifier [CONSTANT] datatype [NOT NULL] record_name.field_name
IDENTIFIED BY password ; [:=|DEFAULT expr] ; Declaring Records with the %ROWTYPE Attribute
Creating Roles Assigning Values to Variables DECLARE
CREATE ROLE role ; identifier := expr ; record_name reference%ROWTYPE
Granting System Privileges Base Scalar Datatypes Creating a PL/SQL Table
GRANT privelges[,...] TO user[,...] ; VARCHAR2(n) NUMBER(p,s) DATE CHAR(n) TYPE type_name IS TABLE OF
GRANT privelges TO role ; LONG LONG RAW BOOLEAN {column_scalr_type|variable%TYPE|table.column%TYPE
GRANT role TO user[,...] ; BINARY_INTEGER PLS_INTEGER |variable%ROWTYPE} [NOT NULL]
Changing Password The %TYPE Attribute [INDEX BY BINARY_INTEGER];
ALTER USER user IDENTIFIED BY password ; table_name.column_name%TYPE ; identifier type_name ;
Dropping Users variable_name%TYPE ; Referencing a PL/SQL table
DROP USER user [CASCADE] ; Composite Datatypes pl_sql_table_name(primary_key_value)
Using PL/SQL Table Method INVALID_CURSOR INITCAP(column|expression)
table_name.method_name[(parameters)] ZERO_DIVIDE INSTR(column|expression,m)
PL/SQL Table Methods DUP_VAL_ON_INDEX CONCAT(column1|expression1,column2|expression2}
EXITS(n) COUNT FIRST LAST PRIOR(n) Trapping Exceptions SUBSTR(column|expression,m,[n])
NEXT(n) EXTEND(n,i) TRIM DELETE EXCEPTION LENGTH(column|expression)
PL/SQL Table of Records WHEN exception1 [OR exception2 ...] THEN LPAD(column|expression,n,’string’)
TYPE table_name_type IS TABLE OF table_name%ROWTYPE statement1 ; Number Functions
INDEX BY BINARY_INTEGER ; statement2 ; MOD(m,n)
table_name table_name_type ; ... ROUND(column|expression,n)
Referencing a Table of Records [WHEN exception3 [OR exception4 ...] THEN TRUNC(column|expression,n)
table_name(index).field statement1 ; Date Functions
Declaring the Cursor in Declaration Section statement2 ; MONTHS_BETWEEN(date1,date2)
CURSOR cursor_name IS select_statement ; ...] ADD_MONTHS(date,n)
record_name cursor_name%ROWTYPE ; [WHEN OTHERS THEN NEXT_DAY(date,’char’)
Opening and Closing the Cursor statement1 ; LAST_DAY(date)
OPEN cursor_name ; statement2 ; ROUND(date[,’fmt’])
CLOSE cursor_name ; ...] TRUNC(date[,’fmt’])
Fetching Data from the Cursor Declaring Non-Predefined Oracle Sever Exception Conversion Functions
FETCH cursor_name DECLARE TO_CHAR(number|date[,’fmt’])
INTO [variable1(,variable2,...) exception EXCEPTION ; TO_NUMBER(char[,’fmt’])
|record_name] ; PRAGMA EXCEPTION_INIT(exception, error_number) ; TO_DATE(char[,’fmt’])
Explicit Cusor Attributes Referencing the declared Non-predefined execption NVL(expr1,expr2)
cursor_name%ISOPEN BEGIN DECODE(col/expr,search1,result1
cursor_name%NOTFOUND ... [,search2,result2,...,]
cursor_name%FOUND EXCEPTION [,default])
cursor_name%ROWCOUNT WHEN exception THEN Operators
Cursor FOR Loops statement1 ; Comparison = > >= < <= <>
FOR record_name IN cursor_name LOOP ... BETWEEN..AND, IN, LIKE, IS NULL
statement1; END ; Logical AND OR NOT
statement2; Trapping User-Defined Exceptions Order of Operations
... DECLARE Operator Operation
END LOOP; exception EXCEPTION ; **,NOT Exponentiation, logical negation
Cursor FOR Loops Using Subqueries BEGIN +,- Identity, negation
FOR record_name IN (subqueries) LOOP ... *,/ Muliplication, division
statement1 IF SQL%NOTFOUND THEN +,-,|| Addition, subtraction, concatenation
... RAISE exception ; =,!=,<,>,<= Comparison
END LOOP ; END IF ; >=,IS NULL,LIKE
Cursors with Parameters ... BETEEN,IN
CURSOR cursor_name [(cursor_parameter_name datatype EXCEPTION AND Conjunction
[,...])] WHEN exception THEN OR Inclusion
IS select_statement statement1 ;
[FOR UPDATE [OF column_reference][NOWAIT]]; ...
Parameter Name END ;
cursor_parameter_name [IN] datatype [{:=|DEFAULT}expr] Functions for Trapping Exceptions
Openning with Parameters SQLCODE return error code
OPEN cursor_name(cursor_parameter_name[,...]); SQLERRM return error message
Cursor FOR Loops with parameters RAISE_APPLICATION_ERROR procedure(Executable/Exception
FOR record_name IN cursor_name(cursor_parameter_name Section)
[,...]) LOOP RAISE_APPLICATION_ERROR ( error_number,
statement1; message [, {TRUE|FALSE}]) ;
statement2; error_number between -20000 to -20999
... message string up to 2,048 bytes long
END LOOP; TRUE placed on the stack of previous errors.
WHERE CURRENT OF clause FALSE replaces all previous errors
UPDATE|DELETE ... WHERE CURRENT OF cursor_name ; Single-Row Functions
Predefined Exceptions Character Functions
NO_DATA_FOUND LOWER(column|expression)
TOO_MANY_ROWS UPPER(column|expression)

You might also like