Вы находитесь на странице: 1из 104

A P P E N D I X

Command Reference
%FOUND
%FOUND
Difficulty
Intermediate

A
3 3

Recommended tool

Other tools

Chapter

Section

See Also %ISOPEN, %NOTFOUND, CURSOR, %ROWCOUNT

Syntax
c1%FOUND

OR
SQL%FOUND

Variables in the syntax


c1:

a valid PL/SQL cursor

Description
This is an attribute of a PL/SQL cursor. This attribute evaluates to TRUE, FALSE, or NULL depending on the cursor activity of an explicit cursor.

666

Appendix A 3 Command Reference

This attribute evaluates to FALSE when the last FETCH fails because no more rows were available, or to TRUE if the last FETCH returned a row. It returns an error if used before opening a cursor. It returns NULL if the cursor is opened, but the FETCH statement has not been executed. If this attribute is used as SQL%FOUND, PL/SQL assumes it to be an implicit cursor; a SQL statement like INSERT, UDPATE, DELETE, or SELECT.
SQL%FOUND evaluates to TRUE if an INSERT, UPDATE, or DELETE statement affected no rows, or a single-row SELECT returned no rows.

Examples
PL/SQL
LOOP FETCH loan_cursor INTO customer_name, loan_amount; IF loan_cursor%FOUND THEN approved_loan := loan_amount * 0.80; ELSE EXIT; END IF; END LOOP; INSERT INTO approved_loan VALUES (customer_name, loan_amount); IF SQL%FOUND THEN COMMIT; ELSE ROLLBACK; END IF;

Appendix A 3 %ISOPEN

667

%ISOPEN
%ISOPEN
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also %FOUND, %NOTFOUND, CURSOR, %ROWCOUNT

Syntax
c1%ISOPEN

OR
SQL%ISOPEN

Variables in the syntax


c1:

a valid PL/SQL cursor

Description
This is an attribute of a PL/SQL cursor. This attribute evaluates to TRUE when the cursor is open, and evaluates to FALSE if the cursor is not open. If this attribute is used as SQL%ISOPEN, PL/SQL assumes it to be an implicit cursor ie. a SQL statement like INSERT, UDPATE, DELETE, or SELECT. Oracle automatically closes an implicit cursor after executing its associated SQL statement. Because SQL% cursor is an implicit cursor, SQL%ISOPEN always evaluates to FALSE.

668

Appendix A 3 Command Reference

Examples
PL/SQL
IF loan_cursor%ISOPEN THEN FETCH loan_cursor INTO customer_name, loan_amount; ELSE OPEN loan_cursor; END IF;

Appendix A 3 %NOTFOUND

669

%NOTFOUND
%NOTFOUND
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also %ISOPEN, %FOUND, CURSOR, %ROWCOUNT

Syntax
c1%NOTFOUND

OR
SQL%NOTFOUND

Variables in the syntax


c1:

a valid PL/SQL cursor

Description
This is an attribute of a PL/SQL cursor. This attribute evaluates to TRUE, FALSE, or NULL depending on the cursor activity. This attribute evaluates to TRUE when the last FETCH fails because no more rows were available, or to FALSE if the last FETCH returned a row. It returns an error if used before opening a cursor. It returns NULL if the cursor is opened, but the FETCH statement has not been executed. If this attribute is used as SQL%NOTFOUND, PL/SQL assumes it to be an implicit cursor (a SQL statement like INSERT, UDPATE, DELETE, or SELECT.)
SQL%NOTFOUND evaluates to FALSE if an INSERT, UDPATE, or DELETE. statement affected no rows, or a single-row SELECT returned no rows.

670

Appendix A 3 Command Reference

Examples
PL/SQL
LOOP FETCH loan_cursor INTO customer_name, loan_amount; EXIT WHEN loan_cursor%NOTFOUND END LOOP; INSERT INTO approved_loan VALUES (customer_name, loan_amount); IF SQL%NOTFOUND THEN ROLLBACK; ELSE COMMIT; END IF;

Appendix A 3 %ROWCOUNT

671

%ROWCOUNT
%ROWCOUNT
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also %ISOPEN, %FOUND, %NOTFOUND, CURSOR

Syntax
c1%ROWCOUNT

OR
SQL%ROWCOUNT

Variables in the syntax


c1:

a valid PL/SQL cursor

Description
This is an attribute of a PL/SQL cursor. This attribute returns the number of rows fetched from the active set so far. If this attribute is used as SQL%ROWCOUNT, PL/SQL assumes it to be an implicit cursor ie. (a SQL statement like INSERT, UDPATE, DELETE, or SELECT.)
SQL%ROWCOUNT returns the number of rows affected by an INSERT, UDPATE, DELETE, or returned by a single-row SELECT.

Examples
PL/SQL
DECLARE CURSOR c1 IS SELECT customer_name, loan_amount FROM loan

672

Appendix A 3 Command Reference

ORDER BY loan_amount DESC; cust_name VARCHAR2(50); loan_amt NUMBER(5,2); BEGIN OPEN c1; LOOP FETCH c1 INTO cust_name, loan_amt; EXIT WHEN (c1%ROWCOUNT > 5) OR (c1%NOTFOUND); INSERT INTO loan_approved VALUES (cust_name, loan_amt); COMMIT; END LOOP; CLOSE c1; END; UPDATE approved_loan SET approved_flag = Y WHERE loan_amount < 5000; IF SQL%ROWCOUNT > 10 THEN INSERT INTO approvals VALUES (STOP MORE APPROVAL); END IF;

Appendix A 3 %ROWTYPE

673

%ROWTYPE
%ROWTYPE
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also %TYPE, FETCH

Syntax
( [user.]table | cursor )%ROWTYPE

Variables in the syntax


user:

the user where the table, or view was created the table, or view that you want to access

table or view: cursor:

any valid PL/SQL cursor

Description
The %ROWTYPE attribute is useful if a record variable has to be declared that has the same structure as a row within a table, or a view, or a row fetched from a cursor. The row is represented as a record whose fields have the same names, and datatypes as the columns within the table or view.

Examples
PL/SQL
A %ROWTYPE declaration cannot include an initialization clause. To declare a record that can store an entire row from the loan table, the above attribute can be used as follows:

674

Appendix A 3 Command Reference

loan_rec

loan%ROWTYPE

The column values are stored within individual fields of records. A specific field can be referenced as follows:
loan_rec.customer_name

A value can be assigned to a field as follows:


loan_rec.loan_amount := 1000;

You can also use the %ROWTYPE declaration with a cursor. If a cursor is used as a prefix for %ROWTYPE, it contains columns equal to the columns within the SELECT statement of the cursor. You can declare, and use the record of the type of the cursor select as follows:
DECLARE CURSOR loan_cursor IS SELECT customer_name, loan_amount FROM loan; loan_record loan_cursor%ROWTYPE BEGIN OPEN loan_cursor; LOOP FETCH loan_cursor INTO loan_record; EXIT WHEN loan_cursor%NOTFOUND; IF loan_record.loan_amount < 5000 THEN UPDATE loan SET loan_approval = Y WHERE customer_name = loan_record.customer_name; IF SQL%FOUND THEN COMMIT; END IF; END IF; END LOOP; CLOSE loan_cursor; END;

Appendix A 3 %TYPE

675

%TYPE
%TYPE
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also %ROWTYPE, FETCH

Syntax
( [user.]table.column | variable )%TYPE

Variables in the syntax


user:

the user where the table or view was created the table or view that you want to access

table or view: column:

the column of the table, or view any valid PL/SQL variable

variable:

Description
The %TYPE attribute provides the datatype of a variable, constant, or a column. This is particularly useful when declaring a variable that refers to a column in the database, a table, and a column that can be referenced. This type of declaration has two advantages: first, the exact datatype of the column need not be known, and secondly, if at a later stage, the definition or datatype of the column within the table is changed, the datatype of the variable defined using %TYPE would change automatically at runtime. Variable and constant declarations using the %TYPE attribute are treated like declarations that explicitly state the datatype They can also be initialized. However, if the column has a NOT NULL constraint, such a constraint does not apply to the variables declared using %TYPE.

676

Appendix A 3 Command Reference

Examples
PL/SQL
new_balance customer_name old_balance%TYPE; loan.customer_name%TYPE;

Appendix A 3 (+)

677

(+)
(+)
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter 9

Section Joining Tables

See Also PRIOR, CONNECT BY

Syntax
WHERE table1.column1 = table2.column1 (+)

Description
The (+) denotes an Outer Join. When you join a table using the outer join, your SQL query returns you all rows from table1 where column1 of table1 is equal to the column1 of table2, as well as all other rows from table1 that have no corresponding rows in table2.

Examples
SQL
SELECT SALES_AGENT, MANAGER FROM SALESMEN, MANAGER WHERE SALESMEN.MANGER = MANGER.MANGER(+); SALES_AGENT ---------JAMES BOND SADDAM HUSSAIN MICHAEL JORDAN MANAGER -------M PHIL JACKSON

678

Appendix A 3 Command Reference

@ (at sign)
@
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also @@, CREATE DATABASE LINK

Syntax
@ filename[.ext] [arg_1,...,arg_N]

Variables in the syntax


filename: ext:

the command file you would like to execute

the extension to the command file, if applicable. The default extension is SQL. the arguments to the command file, if applicable

arg1,...,argN:

Description
By using the @ command, you can run the given file. SQL *Plus will search for the given file within the current directory. If the given file does not exist within the current directory, SQL *Plus will search the system dependent path for the file.

Examples
SQL
@PRINT_LOAN_RPT @PRINT_RESULTS.QRY

Appendix A 3 @@

679

@@
@@
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also @

Syntax
@@ filename [.ext]

Variables in the syntax


filename: ext:

the command file you would like to execute

the extension to the command file, if applicable. The default extension is SQL.

Description
To direct SQL *Plus to run the given command file from the same path as the command file from which it was called, use the @@ command. In effect, SQL *Plus will execute a nested command file by using the @@ command.

Examples
SQL
@@PRINT_LOAN_STATUS.QRY @@PRINT_RESULTS.QRY

680

Appendix A 3 Command Reference

ABS
ABS
Difficulty
Beginner

Recommended Tool

Other Tools

Chapter

Section

See Also SIGN

Syntax
ABS (n)

Variables in the syntax


n:

a numeric variable

Description
The ABS function will return the absolute value of a number. The absolute value refers to the positive value of the number.

Examples
PL/SQL
Var1:= ABS (-1);

SQL
SELECT ABS (-1) Absolute Value FROM DUAL; Absolute Value ------1

Appendix A 3 ACCEPT

681

ACCEPT
ACCEPT
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also INPUT

Syntax
ACCEPT variable [format] [default] [PROMPT]

Variables in the syntax


variable:

The variable into which SQL *Plus will store the value format: the input format for the reply. The format must be a valid text constant e.g.: A5, A10, 99.99, 9999.99, and so on.

default: The default value SQL *Plus will use to store within the variable, if there is no reply from the user. PROMPT text: SQL *Plus will display the text on the screen before accepting the value for the variable from the user

Description
The ACCEPT command will read a line of input, and store the input within a variable. If the variable does not exist, SQL *Plus will create the variable. To store the input as a number, use the NUMBER option. To store the input as a character, use the CHAR option. To store the input as a date, use the DATE option. To not display the input as the user types it, use the HIDE option.

Examples
SQL
ACCEPT loan NUMBER FORMAT 99999.99 DEFAULT 0.00 PROMPT Enter weekly salary: ACCEPT last_name CHAR FORMAT 35 PROMPT Enter customers last name:

682

Appendix A 3 Command Reference

ACOS
ACOS
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also ASIN, ATAN, and ATAN2

Syntax
ACOS (n)

Variables in the syntax


n:

numeric variable between -1 and 1

Description
The ACOS function will return the arc cosine value for a number. The arc cosine is a geometric term expressed in radians and is between 0 to pi. The resultant value is accurate up to 30 digits.

Examples
PL/SQL
Var1:= ACOS (-1);

SQL
SELECT ACOS (-1) Arc Cosine FROM DUAL; Arc Cosine ---------3.1415927

Appendix A 3 ADD_MONTHS

683

ADD_MONTHS
ADD_MONTHS
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also MONTHS_BETWEEN

Syntax
ADD_MONTHS (d, n)

Variables in the syntax


d: n:

a valid date variable an integer variable

Description
The ADD_MONTHS function adds n number of months to the d date you specified and returns the new date. If d is the last day of the month and the month in the returning date has less days, the function returns the last day for that month.

Examples
PL/SQL
Date1:= ADD_MONTHS (26-JAN-47, 10);

SQL
SELECT ADD_MONTHS (26-JAN-47, 10) Add Months FROM DUAL; Add Month --------26-NOV-47

684

Appendix A 3 Command Reference

ALTER CLUSTER
ALTER CLUSTER
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also CREATE CLUSTER, DROP CLUSTER

Syntax
ALTER CLUSTER [user.]cluster [INITRANS n] [MAXTRANS n] [PCTFREE n] [PCTUSED n] [SIZE n [K | M] ] [STORAGE n] [ALLOCATE EXTENT [SIZE n [K | M] ] ] [DATAFILE filename] [INSTANCE n]

Variables in the syntax


user: n:

the user where the cluster was created

any positive integer value the name of a file

filename:

Description
To alter the cluster, use the ALTER CLUSTER statement. You can use the ALTER CLUSTER statement to change the various CLUSTER settings including PCTFREE, PCTUSED, INITRANS, MAXTRANS, TABLESPACE, and STORAGE for future cluster blocks. Those blocks that currently exist cannot be changed. You can use the ALTER CLUSTER statement only if you have the ALTER CLUSTER system privilege.

Appendix A 3 ALTER CLUSTER

685

Examples
SQL
ALTER CLUSTER customer PCTFREE 12

686

Appendix A 3 Command Reference

ALTER DATABASE
ALTER DATABASE
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 5

Section Instance Manager, Database Assistant

See Also CREATE DATABASE, DROP DATABASE

Syntax
ALTER DATABASE [database] [ADD LOGFILE [THREAD n] [GROUP n] file_definition [.file_definition] ... | ADD LOGFILE MEMBER File [REUSE] [, file [REUSE] ...] TO [GROUP n | (file [, file] ...) | file file [REUSE] [, file [REUSE] ...] TO [GROUP n | (file [, file] ...) | file) ] .. | DROP LOGFILE { GROUP n | (file [,file] ... ) | file} [GROUP n | (file [,file] ... ) | file] ... | DROP LOGFILE MEMBER file [, file] | RENAME FILE file to file | NOARCHIVELOG | ARCHIVELOG | MOUNT [EXCLUSIVE | PARALLE] | OPEN [RESETLOGS | NORESETLOGS] | ENABLE [PUBLIC] THREAD n | DISABLE THREAD n | BACKUP CONTROLFILE TO file [REUSE] DATAFILE file [ONLINE | OFFLINE [DROP]] | CREATE DATAFILE file[,file] AS file_definition [.file_definition] ... | RENAME GLOBAL_NAME TO database [.domain] | RECOVER recover_clause | SET [DBMAC [ON | OFF] | DBHIGH = string | DBLOW = string ]

Appendix A 3 ALTER DATABASE

687

Variables in the syntax


database: n:

the database whose settings are to be changed

any positive integer value the name of a file

file:

Description
To change the various settings of the database, use the ALTER DATABASE command. You can use the ALTER DATABASE command to : Open/mount the database. Add/Drop/Clean redo log file as well as its group members. Choose archivelog/noarchivelog mode. Perform media recovery. Rename a data file/redo log file member. Backup the current Control file. Create a new data file. Resize one or more datafiles. Create a new datafile in place of an old one for recovery purposes. Enable/disable autoextending the size of datafiles. You can use the ALTER DATABASE statement only if you are a DBA.

Examples
SQL
ALTER DATABASE NO MOUNT ; ALTER DATABASE ADD LOGFILE GROUP 2 customer.002 size 2m;

688

Appendix A 3 Command Reference

ALTER FUNCTION
ALTER FUNCTION
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 19

Section Functions

See Also CREATE FUNCTION, DROP FUNCTION

Syntax
ALTER FUNCTION [user.]function COMPILE

Variables in the syntax


user:

the user where the function was created the stored function that you want to alter from the database

function:

Description
To alter the stored function, use the ALTER FUNCTION statement. You can use the ALTER FUNCTION statement only if you have the ALTER ANY FUNCTION system privilege. The ALTER FUNCTION also re-compiles the function, thereby helping you avoid runtime overhead and error messages.

Examples
SQL
ALTER FUNCTION loan_calculation COMPILE; ALTER FUNCTION credit_points COMPILE;

Appendix A 3 ALTER INDEX

689

ALTER INDEX
ALTER INDEX
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 12

Section Indexes

See Also CREATE INDEX, DROP INDEX

Syntax
ALTER [UNIQUE] INDEX [user.]index [INITRANS n] [MAXTRANS n] [STORAGE n]

Variables in the syntax


user: index:

the user where the index was created the index that you want to alter from the database

Description
To alter the index, use the ALTER INDEX statement. You can use the ALTER INDEX statement only if you have the ALTER ANY INDEX system privilege. You can further specify the values for INITRANS, MAXTRANS, and STORAGE parameters.

Examples
SQL
ALTER INDEX loan_application;

690

Appendix A 3 Command Reference

ALTER PACKAGE
ALTER PACKAGE
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 19

Section Packages

See Also CREATE PACKAGE, DROP PACKAGE

Syntax
ALTER PACKAGE [user.]package COMPILE [PACKAGE | BODY]

Variables in the syntax


user:

the user where the package was created the package that you want to alter from the database

package:

Description
To alter the package, use the ALTER PACKAGE statement. You can use the ALTER PACKAGE statement only if you have the ALTER ANY PACKAGE system privilege.
ALTER PACKAGE command has the option to re-compile the package specification with the PACKAGE option or the package body with the BODY. If you use the PACKAGE

option, Oracle will re-compile both the package specification as well as the package body.

Examples
SQL
ALTER PACKAGE loan_processing;

Appendix A 3 ALTER PROCEDURE

691

ALTER PROCEDURE
ALTER PROCEDURE
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 19

Section Procedures

See Also CREATE PROCEDURE, DROP PROCEDURE

Syntax
ALTER PROCEDURE [user.]procedure COMPILE

Variables in the syntax


user:

the user where the package was created the procedure that you want to alter from the database

procedure:

Description
To alter the procedure, use the ALTER PROCEDURE statement. You can use the ALTER PROCEDURE statement only if you have the ALTER ANY PROCEDURE system privilege. The ALTER PROCEDURE also re-compiles the function, thereby helping you avoid runtime overhead and error messages.

Examples
SQL
ALTER PROCEDURE loan_calculation COMPILE; ALTER PROCEDURE credit_points COMPILE;

692

Appendix A 3 Command Reference

ALTER PROFILE
ALTER PROFILE
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 11

Section Profiles

See Also CREATE PROFILE, DROP PROFILE

Syntax
ALTER PROFILE profile LIMIT [ { SESSIONS_PER_USER | CPU_PER_SESSION | CPU_PER_CALL | CONNECT_TIME | IDLE_TIME | LOGICAL_READS_PER_SESSION | LOGICAL_READS_PER_CALL | COMPOSITE_LIMIT } { n | UNLIMITED | DEFAULT } | PRIVATE_SGA { n {K | M} | UNLIMITED | DEFAULT } ]

Variables in the syntax


profile: n:

the database profile that you want to alter

any integer value

Description
To alter the database profile, use the ALTER PROFILE statement. You can use the ALTER PROFILE statement only if you have the DBA system privilege. The ALTER PROFILE allows you to change the profile settings for the following:

Appendix A 3 ALTER PROFILE

693

Table A-1 Profile Settings in ALTER PROFILE


Setting
SESSIONS_PER_USER CPU_PER_SESSION CPU_PER_CALL CONNECT_TIME IDLE_TIME LOGICAL_READS_PER_SESSION LOGICAL_READS_PER_CALL COMPOSITE_LIMIT

Description The number of concurrent sessions a user can log in The amount of CPU time used in a session in hundredths of a second The amount of CPU time used by a particular phrase, execute, or fetch call in hundredths of a second The elapsed time of the session in minutes The number of minutes after which the user should be disconnected The number of data blocks read from both memory and disk during a session The number of data blocks read for a particular phrase, execute, or fetch call The total resource cost for a session in service units based on a weighted sum of CPU, connect time, logical reads, and private SGA The number of bytes in a private System Global Area (SGA)

PRIVATE_SGA

Examples
SQL
ALTER PROFILE customer LIMIT SESSION_PER_USER 12 ; ALTER PROFILE customer LIMIT CONNECT_TIME 600 ;

694

Appendix A 3 Command Reference

ALTER RESOURCE COST


ALTER RESOURCE COST
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also CREATE PROFILE

Syntax
ALTER RESOURCE COST [ CPU_PER_SESSION n | CONNECT_TIME n | LOGICAL_READS_PER_SESSION n | PRIVATE_SGA n]

Variables in the syntax


n:

any integer value

Description
With the ALTER RESOURCE COST command, you can alter the various parameters that are used by Oracle for calculating the resource cost in a session, You can use the ALTER RESOURCE COST statement only if you have the DBA system privilege. The ALTER RESOURCE allows you to change the profile settings for the following:

Appendix A 3 ALTER RESOURCE COST

695

Table A-2 Profile Setting Changes for ALTER RESOURCE


Profile Setting
CPU_PER_SESSION CONNECT_TIME LOGICAL_READS_PER_SESSION PRIVATE_SGA

Description The amount of CPU used in a session in hundredths of a second The elapsed time of the session in minutes The number of data blocks read from both memory and disk during a session The number of bytes in a private System Global Area (SGA)

Examples
SQL
ALTER PROCEDURE loan_calculation COMPILE; ALTER PROCEDURE credit_points COMPILE;

696

Appendix A 3 Command Reference

ALTER ROLE
ALTER ROLE
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 11

Section Roles

See Also CREATE ROLE, DROP ROLE

Syntax
ALTER ROLE role [ NOT IDENTIFIED | IDENTIFIED [ BY PASSWORD | EXTERNALLY ] ]

Variables in the syntax


role:

the role that you want to alter from the database

Description
To alter the role, use the ALTER ROLE statement. You can use the ALTER ROLE statement only if you have the ALTER ANY ROLE system privilege.

Examples
SQL
ALTER ROLE custom_user;

Appendix A 3 ALTER ROLLBACK SEGMENT

697

ALTER ROLLBACK SEGMENT


ALTER ROLLBACK SEGMENT
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also CREATE ROLLBACK SEGMENT, DROP ROLLBACK SEGMENT

Syntax
ALTER [PUBLIC] ROLLBACK SEGMENT rollback_segment [STORAGE storage]

Variables in the syntax


rollback_segment:

the rollback segment you would like to alter from the

database

Description
To change a rollback segment from the database, use the ALTER ROLLBACK SEGMENT statement. You cannot use the ALTER ROLLBACK SEGMENT to change a PUBLIC rollback segment to a private rollback segment and vice versa.

Examples
SQL
ALTER PUBLIC ROLLBACK SEGMENT humanresources; ALTER ROLLBACK SEGMENT insurance;

698

Appendix A 3 Command Reference

ALTER SEQUENCE
ALTER SEQUENCE
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 13

Section Sequences

See Also CREATE SEQUENCE, DROP SEQUENCE

Syntax
ALTER SEQUENCE [user.]sequence [ INCREMENT BY n] [ MAXVALUE n | NOMAXVALUE] [ MINVALUE n | NOMINVALUE] [ CYCLE | NO CYCLE] [CACHE n | NO CACHE] [ORDER | NO ORDER]

Variables in the syntax


user:

the user where the sequence was created the sequence that you want to alter from the database

sequence: n:

any positive integer value

Description
To change a sequence from the database, use the ALTER SEQUENCE statement. The ALTER SEQUENCE allows you to change all the options for the sequence including the following:

Appendix A 3 ALTER SEQUENCE

699

Table A-3 Options for the ALTER SEQUENCE statement


options
MINVALUE MAXVALUE CYCLE CACHE ORDER INCREMENT

description The lowest value the sequence can generate. The highest value the sequence can generate. This will restart the sequence number after reaching the MAXVALUE specified. This allows a preallocated set of sequence numbers to be kept in the memory. The default value is 20. This causes the sequence number to be assigned to instances requesting them in a serial order. This value specifies the number by which the sequence is incremented every time a new value is requested.

Examples
SQL
ALTER SEQUENCE customer_code_seq INCREMENT BY 1; ALTER SEQUENCE loan_application_seq NOMAXVALUE ;

700

Appendix A 3 Command Reference

ALTER SESSION
ALTER SESSION
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also SET ROLE, ALTER SYSTEM

Syntax
ALTER SESSION [ SET parameter CLOSE DATABASE LINK link | ADVICE [ COMMIT | ROLLBACK | NOTHING ] | [ ENABLE | DISABLE | COMMIT IN PROCEDURE ]

Variables in the syntax


parameter:

parameter whose value you will specify by using the SET command as

follows
[ [ [ [ SQL_TRACE [TRUE | FALSE] NLS_LANGUAGE = language ] NLS_TERRITORY = territory ] NLS_DATE_FORMAT = format ]

[ NLS_DATE_FORMAT = language ] [ NLS_NUMERIC_CHARACTERS = string] [ NLS_ISO_CURRENCY = territory] [ NLS_CURRENCY = string] [ NLS_SORT = sort] [ LABEL = [string | DBHIGH | DBLOW | OSLABEL] ] [ MLS_LABEL = format ] |

Appendix A 3 ALTER SESSION

701

Description
To change your current sessions configuration, use the ALTER SESSION statement. To close a database link, use the ALTER SESSION CLOSE DATABASE LINK statement. Provide the database links name. To advise the database on a commit or rollback operation for statement(s) that did not execute completely, use the ALTER SESSION ADVISE statement. To let functions and stored procedures issue COMMIT or ROLLBACK within your current session, use the ALTER SESSION ENABLE COMMIT IN PROCEDURE statement. To disallow COMMIT or ROLLBACK within your current sessions functions and stored procedures, use the ALTER SESSION DISABLE COMMIT IN PROCEDURE statement.

Examples
SQL
ALTER SESSION ENABLE COMMIT IN PROCEDURE ALTER SESSION DISABLE COMMIT IN PROCEDURE

702

Appendix A 3 Command Reference

ALTER SNAPSHOT
ALTER SNAPSHOT
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also CREATE SNAPSHOT, DROP SNAPSHOT

Syntax
ALTER SNAPSHOT [user.] snapshot [PCTFREE n | PCTUSED n | INITRANS n | MAXTRANS n | STORAGE n] [ REFRESH { FAST | COMPLETE | FORCE} [START WITH start_date] [NEXT next_date]

Variables in the syntax


user: n:

the user where you created the snapshot

any positive integer value the date to start the snapshot process the date when to refresh the snapshot the snapshot you would like to alter from the database

start_date: next_date: snapshot:

Description
To change a snapshot from the database, use the ALTER SNAPSHOT statement. You can use the ALTER SNAPSHOT statement only if you have the ALTER ANY SNAPSHOT system privilege.

Appendix A 3 ALTER SNAPSHOT

703

Examples
SQL
ALTER SNAPSHOT customer.inactive_cust_snapshot [ PCTUSED 12]

704

Appendix A 3 Command Reference

ALTER SNAPSHOT LOG


ALTER SNAPSHOT LOG
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also CREATE SNAPSHOT LOG, DROP SNAPSHOT LOG

Syntax
ALTER SNAPSHOT LOG ON [user.] table [PCTFREE n | PCTUSED n | INITRANS n | MAXTRANS n | STORAGE n]

Variables in the syntax


n:

any positive integer value

table: the master table associated with snapshot log you would like to change from the database

Description
To change a snapshot log from the database, use the ALTER SNAPSHOT LOG statement. You can use the ALTER SNAPSHOT LOG statement only if you have the ALTER TABLE, and ALTER TRIGGER system privileges on the master table associated with the snapshot log.

Examples
SQL
ALTER SNAPSHOT LOG ON inventory PCTUSED 12

Appendix A 3 ALTER SNAPSHOT LOG

705

ALTER SNAPSHOT LOG


ALTER SNAPSHOT LOG
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also CREATE SNAPSHOT LOG, DROP SNAPSHOT LOG

Syntax
ALTER SNAPSHOT LOG ON [user.] table [PCTFREE n | PCTUSED n | INITRANS n | MAXTRANS n | STORAGE n]

Variables in the syntax


n:

any positive integer value

table:

the master table associated with snapshot log you would like to change from the database

Description
To change a snapshot log from the database, use the ALTER SNAPSHOT LOG statement. You can use the ALTER SNAPSHOT LOG statement only if you have the ALTER TABLE, and ALTER TRIGGER system privileges on the master table associated with the snapshot log.

Examples
SQL
ALTER SNAPSHOT LOG ON inventory PCTUSED 12

706

Appendix A 3 Command Reference

ALTER SYSTEM
ALTER SYSTEM
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also COMMIT, ROLLBACK, SAVEPOINT, SET TRANSACTION

Syntax
ALTER SYSTEM [ SET { RESOURCE_LIMIT = { TRUE | FALSE } | MTS_SERVERS = n MTS_DSIPATCHERS = protocol.n SWITCH LOGFILE | { CHECKPOINT | CHECK DATAFILES } { GLOBAL | LOCAL } | { ENABLE | DISABLE } { DISTRIBUTED RECOVERY | RESTRICTED SESSION } | ARCHIVE LOG archive_log_clause FLUSH SHARE_POOL KILL SESSION sid, serial number ]

Variables in the syntax


archive_log_clause: sid:

archive log clause

the session id (sid) of the session you would like to KILL the serial number of the session you would like to KILL

serial number:

Description
To change your Oracle 8s instance dynamically, use the ALTER SYSTEM statement. To let users with RESTRICTED SESSION privilege log on to Oracle 8, use the ALTER SYSTEM ENABLE RESTRICTED SESSION statement. To let users with CREATE SESSION privilege log on to Oracle 8, use the ALTER SYSTEM DISABLE RESTRICTED SESSION statement.

Appendix A 3 ALTER SYSTEM

707

To force Oracle 8 to perform a checkpoint, use the ALTER SYSTEM CHECKPOINT statement. To instruct Oracle 8 to verify all online data files, use the ALTER SYSTEM CHECK
DATAFILES statement.

To clear all data from the System Global Areas shared pool, use the ALTER SYSTEM
FLUSH SHARED_POOL statement.

To enable distributed recovery within a single process mode, use the ALTER SYSTEM ENABLE DISTRIBUTED RECOVERY statement. To disable distributed recovery within single or multi- process mode, use the ALTER SYSTEM DISABLE DISTRIBUTED RECOVERY statement. To force Oracle 8 to write to a different log file, use the ALTER SYSTEM SWITCH
LOGFILE statement.

To enable or disable automatic archiving, use the ALTER SYSTEM ARCHIVE LOG statement. To kill an Oracle 8 session specified by the SID and serial number, use the ALTER
SYSTEM KILL SESSION statement.

Examples
SQL
ALTER SYSTEM SET RESOURCE_LIMIT = TRUE

708

Appendix A 3 Command Reference

ALTER TABLE
ALTER TABLE
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter 12

Section Tables

See Also CREATE TABLE, DROP TABLE

Syntax
ALTER TABLE [user.] table { [ ADD ( { column1 | table_constraint } [, column2 | table_constraint} ] ... ) ] [ MODIFY ( column1, column2) ] [ DROP drop_constraint] [PCTFREE n] [PCTUSED n] [INITRANS n] [MAXTRANS n] [STORAGE n] ALLOCATE EXTENT [ SIZE n [K | M]] [DATAFILE file] [INSTANCE n] [ ENABLE | DISABLE]

Variables in the syntax


user:

the user where the table was created

table:the table you would like to alter from the database column:

columns name table constraint like NULL, NOT NULL and more

table_constraint: n:

any positive integer value the physical datafiles name

file:

Appendix A 3 ALTER TABLE

709

Description
To change the structure of a table from the database, use the ALTER TABLE statement. You can use the ALTER TABLE statement only if you have the ALTER ANY TABLE system privilege. The ADD option allows you to add columns to the end of an existing table. Also, you can add table constraints to a table with the ALTER TABLE command. You can MODIFY the existing columns. However, the following restrictions apply: To change or decrease the size of a column, you must first set the values for all rows for that column to NULL. To add a NOT NULL column to a table, make sure that the table has no rows. To change an existing column to NOT NULL constraint, make sure that all rows for that column have a value. Increasing the length of a NOT NULL column without specifying NULL will leave it
NOT NULL.

Views with the Select * clause will not work after a new column has been added to the table.

Examples
SQL
ALTER TABLE customer ( ADD ( address VARCHAR2(50)); ALTER TABLE customer ( MODIFY ( name VARCHAR2(50) NOT NULL);

710

Appendix A 3 Command Reference

ALTER TABLESPACE
ALTER TABLESPACE
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter 12

Section Tablespaces

See Also CREATE TABLESPACE

Syntax
ALTER TABLESPACE tablespace [ ADD DATAFILE file_definition [,file_definition] | RENAME DATAFILE file [,file] ... TO file [, file] | DEFAULT STORAGE storage | ONLINE | OFFLINE [NORMAL | IMMEDIATE] | [ BEGIN | END] BACKUP ]

Variables in the syntax


tablespace:

the tablespace you would like to alter from the database the name of the file with size in K or M

file_definition:

Description
To change the tablespace specification, use the ALTER TABLESPACE statement. You can use the ALTER TABLESPACE statement only if you have the DBA system privilege.

Examples
SQL
ALTER TABLESPACE customer ( ADD DATAFILE customer02.dat);

Appendix A 3 ALTER TRIGGER

711

ALTER TRIGGER
ALTER TRIGGER
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 19

Section Triggers

See Also CREATE TRIGGER, DROP TRIGGER

Syntax
ALTER TRIGGER [user.]trigger [ENABLE | DISABLE | COMPILE]

Variables in the syntax


user:

the user where the trigger was created the stored trigger that you want to alter from the database

trigger:

Description
To alter the trigger, use the ALTER TRIGGER statement. You can use the ALTER TRIGGER statement only if you have the ALTER ANY TRIGGER system privilege. You can disable and enable triggers through this command. If a trigger is disabled, ORACLE does not fire the trigger when a potentially triggering operation occurs. The ALTER TRIGGER also re-compiles the function, thereby helping you avoid runtime overhead and error messages.

Examples
SQL
ALTER TRIGGER loan_calculation COMPILE; ALTER TRIGGER credit_points COMPILE;

712

Appendix A 3 Command Reference

ALTER TYPE
ALTER TYPE
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter 24

Section Types

See Also CREATE TYPE, CREATE TYPE BODY, DROP TYPE

Syntax:
ALTER TYPE schema.type_name { COMPILE { SPECIFICATION | BODY } | REPLACE AS | AS TABLE | AS OBJECT } { VARRAY (size) | VARYING ARRAY (size) } { OF datatype} { REF object_type_name} { MAP | ORDER MEMBER function_specification } { PRAGMA RESTRICT_REFERENCES function_specification restriction}

Variables in the syntax


schema:

the database schema where created the object type the object type that you want to alter

type_name: size:

the upper limit of the VARRAY size any datatype such as CHAR, DATE, NUMBER, and more name of the object type referred to name of the member function

datatype:

object_type_name:

function_specification: restriction:

type of restrictions such as WNDS, WNPS, RNDS, RNPS

Description
With Oracle8, you can now create objects as per your custom needs. To use objects with Oracle8, you need to install the Oracle Objects option. To create the objects, use the CREATE TYPE statement.

Appendix A 3 ALTER TYPE

713

Use ALTER TYPE to recompile or change the specification or body of an object type. You can only add a new method with the ALTER TYPE command. You cannot modify or delete existing methods or attributes.

Examples
SQL
ALTER TYPE loan_obj AS OBJECT (customer_name CHAR(20), loan_amount NUMBER(5), MEMBER FUNCTION get_amount RETURN NUMBER, MEMBER FUNCTION get_loan_approved RETURN NUMBER, pragma RESTRICT_REFERENCES (get_amount, WNDS));

714

Appendix A 3 Command Reference

ALTER USER
ALTER USER
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter 11

Section Users

See Also CREATE USER, DROP USER

Syntax
ALTER USER user [IDENTIFIED [BY password | EXTERNALLY]] [ DEFAULT TABLESPACE tablespace] [TEMPORARY TABLESPACE tablespace] [QUOTA {n [K | M] | UNLIMITED} ON tablespace] [,QUOTA {n [K | M] | UNLIMITED} ON tablespace] [PROFILE profile] [DEFAULT ROLE (role1, role2, ...) | ALL EXCEPT (role1, role2, ...) | NONE]

Variables in the syntax


user: tablespace:

the user that you would like to change from the database

the tablespace on which you would like to create the user. A user can span across multiple tablespaces. any positive integer value the profile to which the user is attached

n:

profile: role:

the various roles that the user is assigned or is not assigned

Description
To change a user from the database, use the ALTER USER statement. You can use the ALTER USER statement only if you have the DBA system privileges.

Appendix A 3 ALTER USER

715

Examples
SQL
ALTER USER customer DEFAULT tablespace cust_tablespace TEMPORARY tablespace temp;

716

Appendix A 3 Command Reference

ALTER VIEW
ALTER VIEW
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 13

Section Views

See Also CREATE VIEW, DROP VIEW

Syntax
ALTER VIEW [user.]view COMPILE

Variables in the syntax


user: view:

the user where the view was created the view that you want to alter from the database

Description
To alter the view, use the ALTER VIEW statement. You can use the ALTER VIEW statement only if you have the ALTER ANY VIEW system privilege. The ALTER VIEW also re-compiles the view thereby helping you avoid runtime overhead and error messages.

Examples
SQL
ALTER VIEW loan_calculation COMPILE; ALTER VIEW credit_points COMPILE;

Appendix A 3 ANALYZE

717

ANALYZE
ANALYZE
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter 15

Section Tuning

See Also EXPLAIN PLAN, AUDIT

Syntax
ANALYZE { INDEX [user.]index { { COMPUTE | ESTIMATE | DELETE } STATISTICS [ SAMPLE ( n PERCENT | n ROWS } ] | VALIDATE STRUCTURE } | { TABLE [user.]table | CLUSTER [user.]cluster} { { COMPUTE | ESTIMATE | DELETE } STATISTICS [ SAMPLE ( n PERCENT | n ROWS } ] | VALIDATE STRUCTURE } [CASCASE] | LIST CHAINED ROWS [INTO [user.]table] }

Variables in the syntax


index: n:

the index that you want to analyze

any positive integer value the table you want to analyze the cluster you want to analyze

table:

cluster:

Description
To collect statistical data to fine-tune your database, use the ANALYZE command. You can collect data on a table, a cluster, or an index. Also, the ANALYZE command provides you with an option to delete these statistical data, which, in turn, allows to create a new query plan. The VALIDATE STRUCTURE clause checks for any possible data corruption.

718

Appendix A 3 Command Reference

The ANALYZE command also allows the option to identify the chained rows of a table.

Examples
SQL
ANALYZE INDEX cust_index ESTIMATE STATISTICS;

Appendix A 3 APPEND

719

APPEND
APPEND
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also DEL, EDIT

Syntax
A[PPEND] text

Variables in the syntax


text:

the text you would like to append to the current line within the SQL buffer

Description
To append text to the current line within the SQL buffer, use the APPEND command.

Examples
SQL
A FROM TELECOM APPEND WHERE SQLCODE = 2

720

Appendix A 3 Command Reference

ASCII
ASCII
Difficulty
Beginner

Recommended Tool

Other Tools

Chapter

Section

See Also CHR

Syntax
ASCII (x)

Variables in the syntax


x: a required character variable that should be specified within single quotes

Description
The ASCII function will return the characters ASCII (American Standard Code for Information Interchange) value.

Examples
PL/SQL
Var1:= ASCII (A);

SQL
SELECT ASCII (Z) FROM DUAL; ASCII(Z) ---------90

Appendix A 3 ASIN

721

ASIN
ASIN
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also ACOS, ATAN, ATAN2

Syntax
ASIN (n)

Variables in the syntax


n:

a numeric variable between -1 and 1

Description
The ASIN function will return the arc sine value for a number. The arc sine is a geometric term expressed in radians and is between -pi/2 to pi/2. The resultant value is accurate up to 30 digits.

Examples
PL/SQL
Var1:= ASIN (-1);

SQL
SELECT ASIN (-1) Arc Sine FROM DUAL; Arc Sine ---------1.570796

722

Appendix A 3 Command Reference

ATAN
ATAN
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also ACOS, ASIN, ATAN2

Syntax
ATAN (n)

Variables in the syntax


n:

a numeric variable

Description
The ATAN function will return the arc tangent value for a number. The arc tangent is a geometric term expressed in radians and is between -pi/2 to pi/2. The resultant value is accurate up to 30 digits.

Examples
PL/SQL
Var1:= ATAN (-1);

SQL
SELECT ATAN (-1) Arc Tangent FROM DUAL; Arc Tangent -----------.7853982

Appendix A 3 ATAN2

723

ATAN2
ATAN2
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also ACOS, ASIN, ATAN

Syntax
ATAN2 (x, y)

Variables in the syntax


n:

a numeric variable

Description
The ATAN2 function will return the arc tangent value of x and y numbers. The arc tangent is a geometric term expressed in radians and is between -pi/2 to pi/2 depending on the signs of x and y. The resultant value is accurate up to 30 digits.

Examples
PL/SQL
Var1:= ATAN2 (-1, 1);

SQL
SELECT ATAN2 (-1, 1) Arc Tangent2 FROM DUAL; Arc Tangent2 ------------.7853982

724

Appendix A 3 Command Reference

AUDIT
AUDIT
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter 20

Section

See Also NO AUDIT, ANALYZE

Syntax
AUDIT command | ALL ON [user.]object | DEFAULT [ BY SESSION | ACCESS ] [ WHENEVER [NOT] SUCCESSFUL ]

Variables in the syntax


command: You can audit ALTER, AUDIT, COMMENT, DELETE, EXECUTE, GRANT, INDEX, INSERT, LOCK, RENAME, SELECT and UPDATE commands. user:

the user where the object was created

object:

Object can be a table, a view, a synonym, a sequence, a procedure, a function, a package, or a snapshot.

Description
AUDIT is a powerful feature of ORACLE to automate the task of auditing commands. AUDIT will store the audit data in audit tables.

Use the ALL option to audit all the commands on an object.


WHENEVER SUCCESSFUL audits commands only when successfully executed.

Examples
SQL
AUDIT INSERT ON customer WHENEVER NOT SUCCESSFUL;

Appendix A 3 AVG

725

AVG
AVG
Difficulty
Beginner

Recommended Tool

Other Tools

Chapter 14

Section Group by

See Also SUM

Syntax
AVG ( [DISTINCT | ALL] n)

Variables in the syntax


DISTINCT:

This option causes the function to consider only distinct values of the argument. This is optional.

ALL:

This option causes the function to consider all values of the argument including duplicate values. This is optional. a numeric variable

n:

Description
The AVG function will return the average value of n for a group of rows. The AVG function will add all the values of n and divide it by the number of rows to arrive at the average value.

Examples
PL/SQL
Var1:= AVG (1, 2, 3);

SQL
SELECT AVG (DAILY_SALES) Average Daily Sales FROM SALES; Average Daily Sales -------------655.12

726

Appendix A 3 Command Reference

BFILENAME
BFILENAME
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter 23

Section LOBs

See Also CREATE DIRECTORY

Syntax
BFILENAME (directory, file)

Variables in the syntax


directory:

the physical directory on the server. The maximum length for this variable is 30 characters. the physical name of file on the server

file:

Description
The BFILENAME is new with Oracle8. It returns a BFILE locator where all the external binary files (BFiles) are stored.

Examples
SQL
INSERT INTO lob_table VALUES (BFILENAME (lob_directory, file1.bmp));

Appendix A 3 BLOCK

727

BLOCK
BLOCK
Difficulty
Beginner

Recommended Tool

Other Tools

Chapter

Section

See Also LABEL

Syntax
[<<label>>] DECLARE object_declaration_1,...,object_declaration_n [subprogram_declaration_1 [,subprogram_declaration_2,...,subprogram_declaration_n]] BEGIN statement_1,...,statement_n [EXCEPTION exception_handler_1 [, exception_handler_2,..., exception_handler_3]] END [label];

Variables in the syntax


label:

an optional, undeclared identifier for the PL/SQL block an object declaration

object_declaration_1,...,object_declaration_n:

may include one of the following :


constant_declaration variable_declaration cursor_declaration cursor_variable_declaration record_declaration exception_declaration plsql_table_declaration

728

Appendix A 3 Command Reference

subprogram_declaration_1,...,subprogram_declaration_n:

a subprogram

declaration may include one of the following :


procedure_declaration function_declaration statement_1,...,statement_n:

a sequence of statements exception handlers for the

exception_handler_1,...,exception_handler_n:

sequence of statements

Description
A block constitutes PL/SQLs basic program unit.

Examples
PL/SQL
DECLARE checking_acct_balance NUMBER; BEGIN IF checking_acct_balance = 0 THEN INSERT INTO checking_acct VALUES (500); DELETE FROM savings_acct VALUES (500); END IF; COMMIT; END; DECLARE total_sales NUMBER; bonus NUMBER; salary NUMBER; emp_id NUMBER; BEGIN IF total_sales < 1000 THEN bonus := salary / total_sales; ELSE bonus := total_sales ; END IF; INSERT INTO employee VALUES (bonus); COMMIT; EXCEPTION WHEN ZERO_DIVIDE THEN INSERT INTO employee VALUES (0); COMMIT; WHEN OTHERS THEN ROLLBACK; END;

Appendix A 3 BTITLE

729

BTITLE
BTITLE
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 14

Section Titles and Headings

See Also TTITLE, REPHEADER, REPFOOTER

Syntax
BTI[TLE] [ printspec [ text | variable] ] | [ OFF | ON]

Variables in the syntax


printspec: printspec will include one of the following clauses that SQL *Plus will use to place and format the title : COL n S[KIP] [n] TAB n LE[FT] CE[NTER] R[IGHT] BOLD FORMAT text text: the titles text variable:

the variable that will contain one of the following system maintained

values :
SQL.LNO (current line number) SQL.PNO (current page number) SQL.RELEASE (current Oracle release number)

730

Appendix A 3 Command Reference

SQL.SQLCODE (current error code) SQL.USER (current username)

Description
To place the given title at the bottom of the reports every page, use the BTITLE command. To turn the BTITLE definition off, use the OFF option. To turn the BTITLE definition on, use the ON option.

Examples
SQL
BTITLE RIGHT MARKETING REPORT BTITLE OFF BTITLE ON

Appendix A 3 CEIL

731

CEIL
INSERT
Difficulty
Beginner

Recommended Tool

Other Tools

Chapter

Section

See Also FLOOR

Syntax
CEIL (n)

Variables in the syntax


n:

a numeric variable

Description
The CEIL function will return the smallest integer greater than or equal to the number.

Examples
PL/SQL
Var1:= CEIL (147.2754);

SQL
SELECT CEIL (147.2754) Ceiling FROM DUAL; Ceiling --------148

732

Appendix A 3 Command Reference

CHANGE
CHANGE
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 14

Section Editing Commands

See Also EDIT

Syntax
C[HANGE] separating_character old [separating_character [new [separating_character]]]

Variables in the syntax


separating_character:

a non-alphanumeric character that does not appear within the old, or new text such as !, /, and so on the old text within the SQL buffer you would like to replace the new text that will replace the first occurrence of the old text

old: new:

Description
To change the given texts first occurrence within the SQL buffer with the given new text, use the CHANGE command.

Examples
SQL
C !MAJID!IMRAN C /MARKETING/SALES

Appendix A 3 CHARTOROWID

733

CHARTOROWID
CHARTOROWID
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also ROWIDTOCHAR

Syntax
CHARTOROWID (x)

Variables in the syntax


x:

a character (CHAR or VARCHAR2 datatype) variable specified in quotes

Description
The CHARTOROWID function converts the character datatype to ROWID datatype.

Examples
PL/SQL
Var1 := CHARTOROWID (ORACLE)

SQL
SELECT CHARTOROWID (0000000D.1111.0022) ROWID_TYPE FROM DUAL; ROWID_TYPE -----------------0000000D.1111.0022

734

Appendix A 3 Command Reference

CHR
CHR
Difficulty
Beginner

Recommended Tool

Other Tools

Chapter

Section

See Also ASCII

Syntax
CHR (n)

Variables in the syntax


n:

a numeric variable

Description
The CHR function will return ns character value within the character set of the database.

Examples
PL/SQL
Var1 := CHR (120);

SQL
SELECT CHR (74) || CHR (65) || CHR (86) || CHR (65) Hot FROM DUAL; Hot ---JAVA

Appendix A 3 CLEAR

735

CLEAR
INSERT
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 14

Section Group By

See Also BREAK, COLUMN, COMPUTE

Syntax
CLEAR option

Variables in the syntax


option:

option will be one of the following clauses -

BRE[AKS] BUF[FER] COL[UMNS] COMP[UTES] SCR[EEN] SQL TIM[ING]

Description
To clear the given options current value or setting, use the CLEAR command.

Examples
SQL
CLEAR CLEAR CLEAR CLEAR BREAKS BUFFER SCREEN SQL

736

Appendix A 3 Command Reference

CLOSE
INSERT
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also OPEN, OPEN-FOR, FETCH

Syntax
CLOSE {cursor_name | cursor_variable_name :host_cursor_variable_name}; |

Variables in the syntax


cursor_name:

name of cursor you would like to close, and release resources associated with the cursor

cursor_variable_name:

name of cursor variable you would like to close, and release resources associated with the cursor variable name of cursor variable declared within a PL/SQL

host_cursor_variable_name:

host environment

Description
Use the CLOSE statement to close a cursor (or cursor variable). By closing a cursor (or cursor variable), all resources associated with the cursor (or cursor variable) will be released.

Examples
PL/SQL
LOOP FETCH loan_cur INTO loan_rec; EXIT WHEN loan_cur%NOTFOUND; END LOOP; CLOSE loan_cur;

Appendix A 3 COLUMN

737

COLUMN
COLUMN
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 14

Section Titles and Headings

See Also

Syntax
COL[UMN] [{column|expr} [option_1 ... option_n]]

Variables in the syntax


column: the name of the column whose display attributes you would like to set expr: a valid SQL expression option_1 ... option_N: ALI[AS] alias CLE[AR] FOLD_A[FTER] FOLD_B[EFORE] FOR[MAT] format HEA[DING] text JUS[TIFY] {L[EFT]|C[ENTER]|C[ENTRE]|R[IGHT]} LIKE {expr|alias} NEWL[INE] NEW_V[ALUE] variable NOPRI[NT]|PRI[NT] NUL[L] text OLD_V[ALUE] variable ON|OFF WRA[PPED]|WOR[D_WRAPPED]|TRU[NCATED]

option will represent one of the following clauses:

738

Appendix A 3 Command Reference

Description
To specify a Columns display attributes, use the COLUMN command. To display a Columns current display attributes, specify the Columns name with the COLUMN command. To list all the current Column display attributes, specify the COLUMN command only.

Examples
SQL
COLUMN SALARY FORMAT $9,999,999.99 COLUMN LAST_NAME FORMAT A35

Appendix A 3 COMMENT

739

COMMENT
COMMENT
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also REMARK

Syntax
COMMENT ON [ TABLE table | COLUMN table.column ] IS comment

Variables in the syntax


table:

the name of the table where you want to include the comment

column: the name of the column in the table where you want to include the comments comment:

the comment you would like to include

Description
To include a comment within a table or a column of a table, use the COMMENT command.

Examples
SQL
COMMENT ON TABLE customer COLUMN cust_name IS this column is the name of the customer;

740

Appendix A 3 Command Reference

COMMIT
COMMIT
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 4

Section SQL *Plus

See Also ROLLBACK, SAVEPOINT, SET TRANSACTION, LOCK TABLE

Syntax
COMMIT [WORK ] [COMMENT comment_text]

Variables in the syntax


WORK:

optional keyword. No net effect if you use it. Simply makes the sentence sound more complete.

COMMENT: optional text you can associate with the transaction. Cannot exceed 50 characters. Must be quoted literal.

Description
Use the COMMIT statement to make changes made within the current transaction permanent. By issuing a COMMIT statement, you direct the application to write the changes within the current transaction to the database.

Examples
SQL
COMMIT; COMMIT WORK; COMMIT WORK Saving loan transaction

Appendix A 3 COMPUTE

741

COMPUTE
COMPUTE
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 14

Section Group By

See Also BREAK

Syntax
COMP[UTE] [function [LABEL] text OF expression|column|alias expression | column | alias | REPORT | ROW] ON

Variables in the syntax


function:

one of the following valid functions :

AVG, COU[NT], MAX[IMUM], MIN[IMUM], NUM[BER], STD, SUM, VAR[IANCE] text:

the text you will specify for the computed value the expression you would like to use to compute the value

expression: column: alias:

the column(s) you would like to use to compute the value the alias for the column(s) you would like to use to compute the value

Description
To compute a value by using one of the valid functions on specified column(s) or expression(s), use the COMPUTE command. The COMPUTE commands ON clause will specify the event when SQL *Plus will include a break. For example, if you specify ROW within the ON clause, SQL *Plus will include a break when a new row is fetched. If you specify REPORT within the ON clause, SQL *Plus will include a break when the end of report is reached.

742

Appendix A 3 Command Reference

Examples
SQL
COMPUTE MAX LABEL MAXIMUM SALES OF SALES ON PRODUCTS COMPUTE MIN LABEL MINIMUM SALES OF SALES ON PRODUCTS COMPUTER SUM LABEL TOTAL OF SALES ON PRODUCTS

Appendix A 3 CONCAT

743

CONCAT
CONCAT
Difficulty
Beginner

Recommended Tool

Other Tools

Chapter

Section

See Also CONCATENATE

Syntax
CONCAT (x, y)

Variables in the syntax


x: y:

string variable string variable

Description
The CONCAT function joins two strings to form a third string value. The following table shows the resultant variable when you join two variables:

Table A-4 Results When Concatenating Variables


String X Char Varchar2 NULL String Y Char Varchar2 NULL Result Char Varchar2 NULL Maximum Length 255 Characters 2000 Characters

The CONCAT function is identical to the CONCATENATE (||) function. The reason to have two identical functions is because although Oracle supports the pipe sign (||) on most of the platforms, it still does not support it on all platforms and so users on such other platforms can use the CONCAT function to achieve the same functionality.

744

Appendix A 3 Command Reference

Examples
PL/SQL
Var1 := CONCAT (Oracle 8 , is now released) ;

SQL
SELECT CONCAT (Oracle 8 , is now released) Press Release FROM DUAL; Press Release -----------------------Oracle 8 is now released

Appendix A 3 CONCATENATE

745

CONCATENATE
CONCATENATE
Difficulty
Beginner

Recommended Tool

Other Tools

Chapter

Section

See Also CONCAT

Syntax
||

Variables in the syntax


Not applicable

Description
The CONCATENATE function joins two strings to form a third string value. The following table shows the resulting variable when you concatenate two variables.

Table A-5 Results When Concatenating Variables


String X Char Varchar2 NULL String Y Char Varchar2 NULL Result Char Varchar2 NULL Maximum Length 255 Characters 2000 Characters

The CONCAT function is identical to the CONCATENATE function. The reason to have two identical functions is because although Oracle supports the pipe sign on most of the platforms, it still does not support it on all platforms and so users on such other platforms can use the CONCAT function to achieve the same functionality.

746

Appendix A 3 Command Reference

Examples
PL/SQL
Var1 := Oracle 8 || is now released;

SQL
SELECT Oracle 8 || is now released Press Release FROM DUAL; Press Release -----------------------Oracle 8 is now released

Appendix A 3 CONNECT BY

747

CONNECT BY
CONNECT BY
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also

Syntax
SELECT sql_expn FROM [user.]table WHERE where_condition CONNECT BY [PRIOR] expn = [PRIOR] expn START WITH expn = expn ORDER BY expn

Variables in the syntax


sql_expn: user: table:

a valid sql expression

the owner of the table the table for the SQL SELECT the WHERE condition of the SQL SELECT

where_condition: expn:

any valid expression

Description
The CONNECT BY operator can be used within a SQL SELECT statement to draw a hierarchical structure. It is used most when the data can be represented in a treelike structure. The position of PRIOR helps ORACLE to determine the hierarchy. You can make use of the WHERE clause to eliminate individual items in the hierarchy, but it would not be possible to eliminate both the individual and its descendent items unless you use a not equal sign with the CONNECT BY clause. You cannot use the CONNECT BY clause with a table join.

748

Appendix A 3 Command Reference

Examples
SQL
SELECT employee_name, department_name FROM employee CONNECT BY emp_no = PRIOR department_no ORDER BY department_no;

Appendix A 3 CONVERT

749

CONVERT
CONVERT
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also DECODE

Syntax
CONVERT (x,desc_set [, source_set])

Variables in the syntax


x:

a character variable that should be specified within single quotes which denotes the actual value to be converted

desc_set:

the name of the character set specified within single quotes to which the conversion is to be made

source_set:

the name of the character set specified within single quotes from which the conversion is to be made. This argument is optional. By default, it will take the database character set The following table shows the common character sets:

Table A-6 Common character sets


Character Set Code US7ASCII WE8DEC WE8HP F7DEC WE8EBCDIC500 WE8PC850 WE8ISO8859P1 Character Set US 7-bit ASCII character set DEC West European 8-bit character set HP West European Laserjet 8-bit character set DEC French 7-bit character set IBM West European EBCDIC Code Page 500 IBM PC Code Page 850 ISO 8859-1 West European 8-bit character set

750

Appendix A 3 Command Reference

Description
The function CONVERT can be used to convert a string from one character set to the other.

Examples
SQL
SELECT CONVERT (strutz, WE8HP, F7DEC ) Conversion FROM DUAL; Conversion -----Strutz

Appendix A 3 COPY

751

COPY
COPY
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 21

Section Distributed Database Application

See Also CREATE DATBASE LINK

Syntax
COPY FROM username[/password] @database_specification TO username[/password]@database_specification {APPEND|CREATE|INSERT|REPLACE} destination_table [(column_1,..., column_N)] USING query

Variables in the syntax


username: the username within the FROM clause indicates the user id for connecting to the source database; the username within the TO clause indicates the user id for connecting to the destination database password: the password within the FROM clause indicates the password for connecting to the source database; the password within the TO clause indicates the password for connecting to the destination database database specification:

the database specification within the FROM clause indicates the source database; the database specification within the TO clause indicates the destination database
destination_table: the destination_table indicates the Table you would like to create within the destination database, or to which you would like to add the data column_1,...,column_N:

the Column(s) within the destination Table

query: the query that will determine the rows, and Columns the COPY command will copy

Description
To direct SQL *Plus to copy the data from a query to a table within the database, use the COPY command.

752

Appendix A 3 Command Reference

To append the data being copied to the existing data within the destination table, use the APPEND option. To insert the data being copied to the existing data within the destination table, use the INSERT option. To replace the data within the destination table with the data being copied, use the
REPLACE option.

To create the destination table before the data is copied, use the CREATE option.

Examples
SQL
COPY FROM brokerage/sql TO sales/sql APPEND customers (id, name, address) USING select id, name, address from brokerage.customers;

Appendix A 3 COS

753

COS
COS
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also COSH, SIN, SINH, TAN, TANH

Syntax
COS (n)

Variables in the syntax


n:

a numeric variable

Description
The COS function will return the cosine value for a number. The cosine is a geometric term for an angle expressed in radians. The resultant value is accurate up to 36 digits.

Examples
PL/SQL
Var1:= COS (90);

SQL
SELECT COS (90) Cosine of 90 degrees FROM DUAL; Cosine of 90 degrees --------------------.4480736

754

Appendix A 3 Command Reference

COSH
COSH
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter

Section

See Also COS, SIN, SINH, TAN, TANH

Syntax
COSH (n)

Variables in the syntax


n:

a numeric variable

Description
The COSH function will return the hyperbolic cosine value for a number. The hyperbolic cosine is a geometric term. The resultant value is accurate up to 36 digits.

Examples
PL/SQL
Var1:= COSH (20);

SQL
SELECT COSH (20) Hyperbolic Cosine of 20 deg FROM DUAL; Hyperbolic Cosine of 20 deg --------------------------242582598

Appendix A 3 COUNT

755

COUNT
COUNT
Difficulty
Beginner

Recommended Tool

Other Tools

Chapter 14

Section Group by

See Also SUM

Syntax
COUNT ( * | [DISTINCT | ALL] expn)

Variables in the syntax


*:

This option causes the function to count all the rows including duplicates.

DISTINCT:

This option causes the function to consider only distinct values of the argument. This is optional.

ALL:

This option causes the function to consider all values of the argument including duplicate values. This is optional. This option causes the function returns to return rows only where expr is not null.

expn:

Description
The COUNT function will return the number of rows returned by the query.

Examples
SQL
SELECT COUNT (*) Total # of Sales FROM SALES; Total # of Sales -------------12

756

Appendix A 3 Command Reference

CREATE CLUSTER
CREATE CLUSTER
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter 22

Section

See Also ALTER CLUSTER, DROP CLUSTER

Syntax
CREATE CLUSTER [user.]cluster ( column1 datatype [, column2 datatype, ....] ) [INITRANS n] [MAXTRANS n] [PCTFREE n] [PCTUSED n] [SIZE n [K | M] ] [STORAGE n] [TABLESPACE tablespace] [INDEX | [HASH IS column] HASHKEYS n]

Variables in the syntax


user:

the user where the cluster was created the name of the cluster that you want to create

cluster: n:

any positive integer value

Description
To create a cluster, use the CREATE CLUSTER statement. You can use the CREATE CLUSTER statement with the various CLUSTER settings including PCTFREE, PCTUSED, INITRANS, MAXTRANS, TABLESPACE and STORAGE for creating the cluster blocks. You can use the CREATE CLUSTER statement only if you have the CREATE CLUSTER system privilege. By default, the cluster is Indexed.

Appendix A 3 CREATE CLUSTER

757

Examples
SQL
CREATE CLUSTER customer PCTFREE 12

758

Appendix A 3 Command Reference

CREATE CONTROLFILE
CREATE CONTROLFILE
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also CREATE DATABASE

Syntax
CREATE CONTROLFILE [REUSE] [SET] DATABASE database LOGFILE [GROUP n] file [,[GROUP n] file] ( RESETLOG | NORESETLOG) DATAFILE file [,file] [ MAXLOGFILES n] [ MAXLOGMEMBERS n] [ MAXLOGHISTORY n] [ MAXDATAFILES n] [ MAXINSTANCE n] [ ARCHIVELOG | NOARCHIVELOG ]

Variables in the syntax


n:

any positive integer value the name of a physical file

file:

Description
You can use the CREATE CONTROLFILE command to re-create a control file. This may be necessary when the Control File is lost or damaged or if you want to change the settings for the Control File. The REUSE option allows you to use the existing Control Files. The SET option changes the name of the database. The LOGFILE clause specifies the redo log files. Apart from this, you can also specify the following options:

Appendix A 3 Heading 1

759

Table A-7 Options for the CREATE CONTROLFILE function


Command
MAXLOGFILES MAXLOGMEMBERS MAXLOGHISTORY MAXDATAFILES MAXINSTANCE ARCHIVELOG

Description The maximum number of redo log file groups. The maximum number of copies for a redo log group. The maximum number of archived redo log file groups for the Parallel Server. The maximum number of data files that can be created. The maximum number of Oracle instances that can be concurrently mounted on the database. The option to archive or not archive the redo log files.

Examples
SQL
CREATE CONTROLFILE REUSE SET DATABASE ORACLE LOGFILE D:\ORAWIN95\DATABASE\LOG1ORCL.ORA SIZE 200K, DATAFILE D:\ORAWIN95\DATABASE\SYS1ORCL.ORA SIZE 20M;

760

Appendix A 3 Command Reference

CREATE DATABASE
CREATE DATABASE
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter

Section

See Also ALTER DATABASE, CREATE CONTROLFILE

Syntax
CREATE DATABASE [database] [CONTROLFILE REUSE] LOGFILE [GROUP n] file [,[GROUP n] file] ( RESETLOG | NORESETLOG) DATAFILE file [,file] [ MAXLOGFILES n] [ MAXLOGMEMBERS n] [ MAXLOGHISTORY n] [DATAFILE file_definition [,file_definition]] [ MAXDATAFILES n] [ MAXINSTANCE n] [ ARCHIVELOG | NOARCHIVELOG ] [EXCLUSIVE] ( CHARACTER SET charset)

Variables in the syntax


n:

any positive integer value the name of a physical file the character set you would like to use to store data

file:

charset:

Description
You can use the CREATE DATABASE command to create a database. The REUSE option allows you to use the existing control files. The LOGFILE clause specifies the redo log files. Apart from this, you can also specify the following options:

Appendix A 3 Heading 1

761

Table A-8 Possible options for the CREATE DATABASE command


Command
MAXLOGFILES MAXLOGMEMBERS MAXLOGHISTORY DATAFILES MAXDATAFILES MAXINSTANCE ARCHIVELOG EXCLUSIVE CHARACTER SET

Description The maximum number of redo log file groups. The maximum number of copies for a redo log group. The maximum number of archived redo log file groups for the Parallel Server. The name of the physical database files. The maximum number of data files that can be created. The maximum number of Oracle instances that can be concurrently mounted on the database. The option to archive or not archive the redo log files. This option allows only one instance of the database to have exclusive access to the database. The character set in which you want to store data.

Examples
SQL
CREATE DATABASE ORACLE CONTROLFILE REUSE LOGFILE D:\ORAWIN95\DATABASE\LOG1ORCL.ORA SIZE 200K REUSE, D:\ORAWIN95\DATABASE\LOG2ORCL.ORA SIZE 200K REUSE DATAFILE D:\ORAWIN95\DATABASE\SYS1ORCL.ORA SIZE 20M REUSE AUTOEXTEND ON NEXT 10M MAXSIZE 200M CHARACTER SET WE8ISO8859P1;

762

Appendix A 3 Command Reference

CREATE DATABASE LINK


CREATE DATABASE LINK
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter 21

Section Distributed Database Applications

See Also CREATE SYNONYM

Syntax
CREATE [PUBLIC] DATABASE LINK link CONNECT TO user IDENTIFIED BY password USING connect_string

Variables in the syntax


link: user:

the name of the database link that you want to create the database user the corresponding password for the user the definition of the remote database that needs to be accessed

password:

connect_string:

Description
To create a link between your local database and a Username on the remote database, use the CREATE DATABASE LINK command. If you create a PUBLIC DATABASE LINK, these would be available to all the local users of your database. However, the PUBLIC DATABASE LINK can be created only by the DBA. After creating the link, use the @link in the from clause of the SELECT to access tables on the remote database.

Appendix A 3 CREATE DATABASE LINK

763

Examples
SQL
CREATE DATABASE LINK international_customers connect to INTL_DB identified by intl using D:INTERNATIONAL; SELECT CUSTOMER_NAME FROM CUSTOMER@INTL_DB;

764

Appendix A 3 Command Reference

CREATE PROFILE
CREATE PROFILE
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 6

Section User Profiles

See Also ALTER PROFILE, ALTER RESOURCE COST, DROP PROFILE

Syntax
CREATE PROFILE profile LIMIT [ { SESSIONS_PER_USER | CPU_PER_SESSION | CPU_PER_CALL | CONNECT_TIME | IDLE_TIME | LOGICAL_READS_PER_SESSION | LOGICAL_READS_PER_CALL | COMPOSITE_LIMIT } { n | UNLIMITED | DEFAULT } | PRIVATE_SGA { n {K | M} | UNLIMITED | DEFAULT } ]

Variables in the syntax


profile: n:

the database profile that you want to alter

any integer value

Description
To create a database profile, use the CREATE PROFILE statement. You can use the CREATE PROFILE statement only if you have the DBA system privilege. The CREATE PROFILE allows you to set the profile settings for the following:

Appendix A 3 CREATE PROFILE

765

Table A-9 Profile settings for the CREATE PROFILE statement


Profile Setting
SESSIONS_PER_USER CPU_PER_SESSION CPU_PER_CALL CONNECT_TIME IDLE_TIME LOGICAL_READS_PER_SESSION LOGICAL_READS_PER_CALL COMPOSITE_LIMIT

Description The number of concurrent sessions a User can log in. The amount of CPU time used in a session in hundredths of a second. The amount of CPU time used by a particular phrase, execute, or fetch call in hundredths of a second. The elapsed time of the session in minutes. The number of minutes after which the User should be disconnected. The number of data blocks read from both memory and disk during a session. The number of data blocks read for a particular phrase, execute, or fetch call. The total resource cost for a session in service units based on a weighted sum of CPU, connect time, logical reads, and private SGA. The number of bytes in a private System Global Area (SGA).

PRIVATE_SGA

Examples
SQL
CREATE PROFILE customer LIMIT SESSION_PER_USER 12 ; CREATE PROFILE customer LIMIT CONNECT_TIME 600 ;

766

Appendix A 3 Command Reference

CREATE DIRECTORY
CREATE DIRECTORY
Difficulty
Advanced

Recommended Tool

Other Tools

Chapter 23

Section LOBs

See Also DROP DIRECTORY, BFILENAME

Syntax
CREATE [OR REPLACE] DIRECTORY directory AS pathname;

Variables in the syntax


directory:

the directory Object that you want to create. The maximum length for this variable is 30 characters. the full pathname specified in quotes

pathname:

Description
To create a directory, use the CREATE DIRECTORY statement. The directory Object is new with Oracle8. It refers to the directory on the ORACLE servers physical system. This directory stores external binary files (bFiles). It is a good idea to use directory names when referring to the BFILEs rather than hard-coding the complete path. All directories created with this command are stored in a single namespace. By default, ORACLE grants READ object privilege. To grant READ privilege to other users or roles, you will need DBA system privilege. While granting privilege to the directory, ORACLE does not check if the ORACLE process can access the physical files. It assumes that the operating system does provide the access to the files to ORACLE processes.

Examples
SQL
CREATE OR REPLACE DIRECTORY bfile_directory AS /bfile;

Appendix A 3 CREATE FUNCTION

767

CREATE FUNCTION
CREATE FUNCTION
Difficulty
Intermediate

Recommended Tool

Other Tools

Chapter 19

Section Functions

See Also ALTER FUNCTION, DROP FUNCTION

Syntax
CREATE [OR REPLACE] FUNCTION [user.]function [ (parameter [IN] datatype [,parameter [IN] datatype] ... ) ] RETURN datatype (IS | AS) block

Variables in the syntax


user:

The user where you want to create the function the stored function that you want to create on the database any argument that you want to pass to the function the datatype of the argument respectively

function: parameter: datatype: block:

the block refers to the series of declarations, PL/SQL program statements, and exceptions that define the behavior of the function.

Description
To create the stored function, use the CREATE FUNCTION statement. A function is a subprogram that computes a value. Functions and procedures are structured alike, except that function have a RETURN value. These user created functions cannot be used as part of your SQL expressions. These functions are different than the SQL functions like TO_CHAR, TO_DATE, and more.

768

Appendix A 3 Command Reference

A function has two parts: the specification and the body. The function specification begins with the keyword FUNCTION and ends with the function name or parameter list. Parameter declarations are optional. Functions that take no parameters are written without parentheses. The function body begins with the keyword IS and ends with the keyword END, followed optionally by the function name. The function body has 3 parts: a declarative part, an executable part, and an optional exceptional-handling part. A good idea would be to use the CREATE OR REPLACE command so that if the function already exists, Oracle will replace it with the new function.

Examples
SQL
CREATE FUNCTION loan_calculation (loan_amount NUMBER, no_of_years NUMBER) RETURN NUMBER AS Total_loan NUMBER; BEGIN Total_loan := loan_amount * no_of_years; RETURN total_loan ; END loan_calculation ;

Вам также может понравиться