Академический Документы
Профессиональный Документы
Культура Документы
Command Reference
%FOUND
%FOUND
Difficulty
Intermediate
A
3 3
Recommended tool
Other tools
Chapter
Section
Syntax
c1%FOUND
OR
SQL%FOUND
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
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
Syntax
c1%ISOPEN
OR
SQL%ISOPEN
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
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
Syntax
c1%NOTFOUND
OR
SQL%NOTFOUND
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
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
Syntax
c1%ROWCOUNT
OR
SQL%ROWCOUNT
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
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
Syntax
( [user.]table | cursor )%ROWTYPE
the user where the table, or view was created the table, or view that you want to access
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
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
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
Syntax
( [user.]table.column | variable )%TYPE
the user where the table or view was created the table or view that you want to access
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
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
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
@ (at sign)
@
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter
Section
Syntax
@ filename[.ext] [arg_1,...,arg_N]
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]
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
ABS
ABS
Difficulty
Beginner
Recommended Tool
Other Tools
Chapter
Section
Syntax
ABS (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
Syntax
ACCEPT variable [format] [default] [PROMPT]
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
ACOS
ACOS
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter
Section
Syntax
ACOS (n)
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
Syntax
ADD_MONTHS (d, n)
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
ALTER CLUSTER
ALTER CLUSTER
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter
Section
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]
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.
685
Examples
SQL
ALTER CLUSTER customer PCTFREE 12
686
ALTER DATABASE
ALTER DATABASE
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter 5
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 ]
687
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
ALTER FUNCTION
ALTER FUNCTION
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter 19
Section Functions
Syntax
ALTER FUNCTION [user.]function COMPILE
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;
689
ALTER INDEX
ALTER INDEX
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter 12
Section Indexes
Syntax
ALTER [UNIQUE] INDEX [user.]index [INITRANS n] [MAXTRANS n] [STORAGE n]
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
ALTER PACKAGE
ALTER PACKAGE
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter 19
Section Packages
Syntax
ALTER PACKAGE [user.]package COMPILE [PACKAGE | BODY]
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;
691
ALTER PROCEDURE
ALTER PROCEDURE
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter 19
Section Procedures
Syntax
ALTER PROCEDURE [user.]procedure COMPILE
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
ALTER PROFILE
ALTER PROFILE
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter 11
Section Profiles
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 } ]
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:
693
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
Recommended Tool
Other Tools
Chapter
Section
Syntax
ALTER RESOURCE COST [ CPU_PER_SESSION n | CONNECT_TIME n | LOGICAL_READS_PER_SESSION n | PRIVATE_SGA n]
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:
695
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
ALTER ROLE
ALTER ROLE
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter 11
Section Roles
Syntax
ALTER ROLE role [ NOT IDENTIFIED | IDENTIFIED [ BY PASSWORD | EXTERNALLY ] ]
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;
697
Recommended Tool
Other Tools
Chapter
Section
Syntax
ALTER [PUBLIC] ROLLBACK SEGMENT rollback_segment [STORAGE storage]
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
ALTER SEQUENCE
ALTER SEQUENCE
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter 13
Section Sequences
Syntax
ALTER SEQUENCE [user.]sequence [ INCREMENT BY n] [ MAXVALUE n | NOMAXVALUE] [ MINVALUE n | NOMINVALUE] [ CYCLE | NO CYCLE] [CACHE n | NO CACHE] [ORDER | NO ORDER]
the user where the sequence was created the sequence that you want to alter from the database
sequence: n:
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:
699
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
ALTER SESSION
ALTER SESSION
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter
Section
Syntax
ALTER SESSION [ SET parameter CLOSE DATABASE LINK link | ADVICE [ COMMIT | ROLLBACK | NOTHING ] | [ ENABLE | DISABLE | COMMIT IN PROCEDURE ]
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 ] |
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
ALTER SNAPSHOT
ALTER SNAPSHOT
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter
Section
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]
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
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.
703
Examples
SQL
ALTER SNAPSHOT customer.inactive_cust_snapshot [ PCTUSED 12]
704
Recommended Tool
Other Tools
Chapter
Section
Syntax
ALTER SNAPSHOT LOG ON [user.] table [PCTFREE n | PCTUSED n | INITRANS n | MAXTRANS n | STORAGE n]
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
705
Recommended Tool
Other Tools
Chapter
Section
Syntax
ALTER SNAPSHOT LOG ON [user.] table [PCTFREE n | PCTUSED n | INITRANS n | MAXTRANS n | STORAGE n]
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
ALTER SYSTEM
ALTER SYSTEM
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter
Section
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 ]
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.
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
ALTER TABLE
ALTER TABLE
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter 12
Section Tables
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]
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:
file:
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
ALTER TABLESPACE
ALTER TABLESPACE
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter 12
Section Tablespaces
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 ]
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);
711
ALTER TRIGGER
ALTER TRIGGER
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter 19
Section Triggers
Syntax
ALTER TRIGGER [user.]trigger [ENABLE | DISABLE | COMPILE]
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
ALTER TYPE
ALTER TYPE
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter 24
Section Types
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}
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:
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.
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
ALTER USER
ALTER USER
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter 11
Section Users
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]
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:
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.
715
Examples
SQL
ALTER USER customer DEFAULT tablespace cust_tablespace TEMPORARY tablespace temp;
716
ALTER VIEW
ALTER VIEW
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter 13
Section Views
Syntax
ALTER VIEW [user.]view COMPILE
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
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] }
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
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
Syntax
A[PPEND] 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
ASCII
ASCII
Difficulty
Beginner
Recommended Tool
Other Tools
Chapter
Section
Syntax
ASCII (x)
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
Syntax
ASIN (n)
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
ATAN
ATAN
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter
Section
Syntax
ATAN (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
Syntax
ATAN2 (x, y)
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
AUDIT
AUDIT
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter 20
Section
Syntax
AUDIT command | ALL ON [user.]object | DEFAULT [ BY SESSION | ACCESS ] [ WHENEVER [NOT] SUCCESSFUL ]
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.
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
Syntax
AVG ( [DISTINCT | ALL] n)
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
BFILENAME
BFILENAME
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter 23
Section LOBs
Syntax
BFILENAME (directory, file)
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
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];
object_declaration_1,...,object_declaration_n:
728
subprogram_declaration_1,...,subprogram_declaration_n:
a subprogram
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
Syntax
BTI[TLE] [ printspec [ text | variable] ] | [ OFF | ON]
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
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
Syntax
CEIL (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
CHANGE
CHANGE
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter 14
Syntax
C[HANGE] separating_character old [separating_character [new [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
Syntax
CHARTOROWID (x)
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
CHR
CHR
Difficulty
Beginner
Recommended Tool
Other Tools
Chapter
Section
Syntax
CHR (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
Syntax
CLEAR option
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
CLOSE
INSERT
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter
Section
Syntax
CLOSE {cursor_name | cursor_variable_name :host_cursor_variable_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
See Also
Syntax
COL[UMN] [{column|expr} [option_1 ... option_n]]
738
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
Syntax
COMMENT ON [ TABLE table | COLUMN table.column ] IS comment
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:
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
COMMIT
COMMIT
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter 4
Syntax
COMMIT [WORK ] [COMMENT comment_text]
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
Syntax
COMP[UTE] [function [LABEL] text OF expression|column|alias expression | column | alias | REPORT | ROW] ON
the text you will specify for the computed value the expression you would like to use to compute the value
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
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
Syntax
CONCAT (x, y)
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:
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
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
Syntax
||
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.
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
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
the owner of the table the table for the SQL SELECT the WHERE condition of the SQL SELECT
where_condition: expn:
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
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
Syntax
CONVERT (x,desc_set [, source_set])
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:
750
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
Syntax
COPY FROM username[/password] @database_specification TO username[/password]@database_specification {APPEND|CREATE|INSERT|REPLACE} destination_table [(column_1,..., column_N)] USING query
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:
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
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
Syntax
COS (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
COSH
COSH
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter
Section
Syntax
COSH (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
Syntax
COUNT ( * | [DISTINCT | ALL] expn)
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
CREATE CLUSTER
CREATE CLUSTER
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter 22
Section
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]
the user where the cluster was created the name of the cluster that you want to create
cluster: n:
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.
757
Examples
SQL
CREATE CLUSTER customer PCTFREE 12
758
CREATE CONTROLFILE
CREATE CONTROLFILE
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter
Section
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 ]
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
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
CREATE DATABASE
CREATE DATABASE
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter
Section
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)
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
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
Recommended Tool
Other Tools
Chapter 21
Syntax
CREATE [PUBLIC] DATABASE LINK link CONNECT TO user IDENTIFIED BY password USING connect_string
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.
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
CREATE PROFILE
CREATE PROFILE
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter 6
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 } ]
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:
765
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
CREATE DIRECTORY
CREATE DIRECTORY
Difficulty
Advanced
Recommended Tool
Other Tools
Chapter 23
Section LOBs
Syntax
CREATE [OR REPLACE] DIRECTORY directory AS pathname;
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;
767
CREATE FUNCTION
CREATE FUNCTION
Difficulty
Intermediate
Recommended Tool
Other Tools
Chapter 19
Section Functions
Syntax
CREATE [OR REPLACE] FUNCTION [user.]function [ (parameter [IN] datatype [,parameter [IN] datatype] ... ) ] RETURN datatype (IS | AS) block
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
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
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 ;