You are on page 1of 25

1

Quick Reference 1.Triggers There are two kinds of triggers basically. (1) Row Level Triggers (2) Statement Level Triggers It can be again broadly classified as follows BEFORE INSERT AFTER INSERT BEFORE UPDATE AFTER UPDATE BEFORE DELETE AFTER DELETE BEFORE INSERT AFTER INSERT BEFORE UPDATE AFTER UPDATE BEFORE DELETE AFTER DELETE

Row Level

Statement Level

2. Cursor Oracle server uses work areas called private SQL areas to execute SQL statements and to store processing information. PL/SQL cursors can be used to name a private SQL area and access its stored information. There are two kinds of cursors namely (1)Implicit Cursor Declared for all DML and PL/SQL Select statements. Opens a work area called as SQL. Therefore the cursor attributes for implicit cursors would prefix with SQL i.e., SQL%FOUND. Note: We replace SQL with the cursor name for Explicit Cursors. Usage 1. To find out the number of rows updated by an updated query. Sql%rowcount 2. Suppose we want to know whether the query returns any value. Eg: select * from emp where emp_id = 1234; Sql%found gives TRUE it retrieves. (2) Explicit Cursor When we declare a cursor, it is called explicit cursor Eg: Cursor c is select * from EMP;

2

ACTIVITIES ASSOCIATED WITH CURSORS 1. Declaration of a cursor 2. Open a cursor 3. Fetch rows 4. Close cursor Note: for Explicit cursor above 4 activities are done by programmer where as for Implicit Oracle does it. Cursor Attributes (cursor variables) 1. 2. 3. 4. %found %notfound %isopen %rowcount

4. SQL Commands 1. DQL – Data query Language (select) 2. DML – Data Manipulation Language (insert, update, delete) 3. DDL – Data Definition Language (create, alter, drop, truncate) 4. TCL – Transaction Control Language (commit, rollback, savepoint) 5. DCL – Data Control Language (grant, revoke) 5. Truncate V/S Delete TRUNCATE Truncate reuse storage will retain the space Truncate cannot be conditional. Truncate resets high-water mark if drop storage option is given. DELETE Rollback is possible for delete as it creates rollback segments Delete can be conditional. Delete don’t reset.

6. Joins Joins are used to combine rows from two or more Tables. There are different kinds of Joins 1. Self Join 2. Equi Join/Inner Join(Natural Join) 3. Outer Joins (Left/Right/Full) 4. Cross Join To explain two table are used. See the Structure and data for the tables • EMPB • DPTB

3 SQL>desc empb; Name Null? Type ------------------------------- -------- ---ID NUMBER NAME CHAR(10) DPT NUMBER MNG NUMBER SQL>desc dptb; Name Null? Type ------------------------------- -------- ---DPT NUMBER DPT_NAME CHAR(10) SQL>select * from empb; ID NAME DPT MNG ------------------------- ---------- ------------------------- ------------------------101 aaa 10 103 102 bbb 15 101 103 ccc 25 102 3 rows selected. SQL>select * from dptb; DPT ------------------------10 15 20 25 30 5 rows selected. DPT_NAME ---------uuu vvv www xxx yyy

1. Self Join Joining a table to itself. Self Join is used to combine rows of the same table in a different way by satisfying certain conditions. Take the case of table EMPB. Suppose we need to display the ID along MNG (Manager) Names. See the Query given below. SQL>select worker.id, manager.name from empb worker, empb manager where worker.MNG=manager.ID order by worker.id;
ID -------------------101 102 103 3 rows selected. NAME --------------ccc aaa bbb

4

2. Equi Join( Natural Join) Combines records that satisfy the Join Condition in both the table.
SQL>select

a.*, b.* from empb a, dptb b where a.dpt=b.dpt;

ID NAME DPT MNG DPT DPT_NAME ------------------------- ---------- ------------------------- ------------------------- ------------------------- ---------101 aaa 10 103 10 uuu 102 bbb 15 101 15 vvv 103 ccc 25 102 25 xxx 3 rows selected.

The following queries also give the same above result. select empb.*, dptb.* from empb, dptb where empb.dpt=dptb.dpt select empb.*, dptb.* from empb empb, dptb dptb where empb.dpt=dptb.dpt But if you give any of the above query without Join conditions as follows SQL>select a.*, b.* from empb a, dptb b;
ID NAME DPT MNG DPT DPT_NAME ------------------------- ---------- ------------------------- ------------------------- ------------------------- ---------101 aaa 10 103 10 uuu 102 bbb 15 101 10 uuu 103 ccc 25 102 10 uuu 101 aaa 10 103 15 vvv 102 bbb 15 101 15 vvv 103 ccc 25 102 15 vvv 101 aaa 10 103 20 www 102 bbb 15 101 20 www 103 ccc 25 102 20 www 101 aaa 10 103 25 xxx 102 bbb 15 101 25 xxx 103 ccc 25 102 25 xxx 101 aaa 10 103 30 yyy 102 bbb 15 101 30 yyy 103 ccc 25 102 30 yyy 15 rows selected.

3. Outer Joins When we are in need of retrieving all the rows from One Table and only those staisfy the join conditions from the second Table, we need to fill the Empty Part the second one with NULL. We use outer join (+) for this purpose.

5

See the following Query. It is a Left Outer Join as the ‘+’ symbol is on left hand side of the join. And when it is on the Right hand side it is called Right Outer Join.

SQL>select

a.id,a.name,b.dpt_name from empb a, dptb b where a.dpt(+)=b.dpt;

ID NAME DPT_NAME ------------------------- ---------- ---------101 aaa uuu 102 bbb vvv www 103 ccc xxx yyy 5 rows selected.

In the above query result it is clear that as the Department Numbers 20, 30 are not there with EMPB table got filled with null and the records from DPTB table is full. For full outer joine We use the key word ‘ FULL OUTER JOIN’ (Only in 9i) 4. Corss Join Cross Join gives a cartesian product. Only in 9i. SQL>select * from empb cross join dptb;
ID NAME DPT MNG DPT ---- ---------- ------------------------- ------------------------- -----------101 aaa 10 103 10 101 aaa 10 103 15 101 aaa 10 103 20 101 aaa 10 103 25 101 aaa 10 103 30 102 bbb 15 101 10 102 bbb 15 101 15 102 bbb 15 101 20 102 bbb 15 101 25 102 bbb 15 101 30 103 ccc 25 102 10 103 ccc 25 102 15 103 ccc 25 102 20 103 ccc 25 102 25 103 ccc 25 102 30 15 rows selected. DPT_NAME ---------------uuu vvv www xxx yyy uuu vvv www xxx yyy uuu vvv www xxx yyy

Hash Join : The Hash join will be used, if there are no adequate indexes on the joined
columns.

6

7. Global Temporary tables Can be created for temporary purpose, On commit preserve rows – Available for that transaction, till commit is fired On commit delete rows -- Available for entire session
CREATE GLOBAL TEMPORARY TABLE A (A NUMBER) ON COMMIT PRESERVE ROWS CREATE GLOBAL TEMPORARY TABLE A (A NUMBER) ON COMMIT DELETE ROWS

8. To Get Currently Connected Database Name sql>select * from global_name; GLOBAL_NAME -------------------------------COPDEV.WORLD 1 row selected. 9. Duplicate Row SQL>select * from emp where rowid not in(select min(rowid) from emp group by id); This Query retrieves all the duplicate rows based ID ( if any ID is repeated). From the second occurance onwards. 10. Greatest 5 SQL>select sal from (select sal from emp order by sal desc)where rownum <=5; Retrieves the top 5 salaries(sal) from EMP table. 11. Set Operators Used to combine or compare multiple Select queris 1. 2. 3. 4. UNION UNION ALL (Duplicates) INTERSECT MINUS

1. UNION The Sep operators UNION is used to combine two or more select Queries. Here the Data type and number of colums in every select query should match.

7

2. UNION ALL The Sep operators UNION ALL is used to combine two or more select Queries. Here the Data type and number of colums in every select query should match. Union All retrieves Duplicates records 3. INTERSECT The set Operator INTERSECT is used to retrieve only the common rows from two or more select queries. The Data type and number of colums in every select query should match. 4. MINUS The Set operator MINUS retrieves all the records from the first query that are not there int the Second query. The Data type and number of colums in every select query should match. Refer the tables used for JOINS and see the following quries SQL>select dpt from dptb minus select dpt from empb; DPT ------------------------20 30 2 rows selected. SQL>select dpt from dptb union select dpt from empb; DPT ------------------------10 15 20 25 30 5 rows selected. SQL>select dpt from dptb union all select dpt from empb; DPT ------------------------10 15 20 25 30 10

8

15 25 8 rows selected. SQL>select dpt from dptb intersect select dpt from empb; DPT ------------------------10 15 25 3 rows selected. Here it is not necessary that the field name of both the quries should be the same. Only thing is the the data type should be the same. 12. Aggregate Functions 1. 2. 3. 4. 5. MIN() MAX() COUNT() AVG() SUM()

13. NVL – (Null Value Substitution) Function SQL>select nvl(a.id,0) ID, nvl(a.name,'NOBODY') NAME, nvl(a.dpt,10) DPT, b.dpt_name from empb a, dptb b where a.dpt(+)=b.dpt; ID NAME DPT DPT_NAME -------------------- --------------- -------------------- --------------101 aaa 10 uuu 102 bbb 15 vvv 0 NOBODY 10 www 103 ccc 25 xxx 0 NOBODY 10 yyy 5 rows selected. Refer the Tables given in the Join section. Here whenever the ID is NULL it gets substited with ‘0’ and whenever the NAME is NULL getting substitued with ‘NOBODY’.

9

14. DECODE - Function SQL>select dpt || ' --> ' || decode(dpt,10,'uuu', 15,'vvv', 'nnn' ) EMP_DPT from empb; EMP_DPT -----------------------------------------------10 --> uuu 15 --> vvv 25 --> nnn 3 rows selected. Refer Tables given in the Join Section. Here when the Department is ‘10’ it gives ‘uuu’ and when the department ‘15’ it gives ‘vvv’ and for rest(whatever is the department) it gives ‘nnn’ which is optional. 15. SysDate Functions The date formate basically depends on the NLS_DATE parameter setting in init.ora SQL>select sysdate from dual; SYSDATE ---------------------------9/23/2004 9:57:47 PM 1 row selected. SQL>select trunc(sysdate) from dual; TRUNC(SYSDA -----------------------9/23/2004 1 row selected.

10

SQL>select sysdate-2 from dual; SYSDATE-2 ----------9/21/2004 10:05:23 PM 1 row selected. SQL>select sysdate+2 from dual; SYSDATE+2 ----------9/25/2004 10:05:23 PM 1 row selected. SQL>select to_char(sysdate, 'dd-mon-rrrr') zz from dual; ZZ ----------23-sep-2004 1 row selected. SQL>select sysdate-(sysdate-1) from dual; SYSDATE-(SYSDATE-1) -----------------------------------1 1 row selected. SQL>select sysdate-(sysdate+5) from dual; SYSDATE-(SYSDATE+5) -------------------------5 1 row selected. SQL>select sysdate - sysdate from dual; SYSDATE-SYSDATE -------------------------

11

0 1 row selected. SQL>select sysdate-(to_char(sysdate, 'dd-mon-rrrr')) from dual; select sysdate-(to_char(sysdate, 'dd-mon-rrrr')) from dual * ERROR at line 1: ORA-01722: invalid number SQL>select next_day('1-JAN-2004', 'MONDAY') FROM DUAL; NEXT_DAY('1 ----------1/5/2004 1 row selected. SQL>select ADD_MONTHS('1-JAN-2004', -2) FROM DUAL; ADD_MONTHS( ----------11/1/2003 1 row selected. SQL>select LAST_DAY('1-JAN-2004') FROM DUAL; LAST_DAY('1 ----------1/31/2004 1 row selected. SQL>SELECT GREATEST('1-JAN-2004', '2-JAN-2004') FROM DUAL; GREATEST(' ---------2-JAN-2004 1 row selected.

12

16. To Get Oracle Version sql>select * from v$version; BANNER ----------------------------------------------------------Oracle8i Enterprise Edition Release 8.1.6.1.0 - Production PL/SQL Release 8.1.6.0.0 - Production CORE 8.1.6.0.0 Production TNS for 32-bit Windows: Version 8.1.6.0.0 - Production NLSRTL Version 3.4.1.0.0 - Production 5 rows selected. 17. DUAL table sql>desc dual; Name Null? Type ------------------------------- -------- ---DUMMY VARCHAR2(1) 18. Block Labels <<identifier>> Eg: <<labelOne>> Goto labelOne;

13

19. RefCursor create or replace package pkg as type ref_cur is ref cursor; procedure p1(x out ref_cur); end pkg; -------------------------------------------------------create or replace package body pkg as procedure p1(x out ref_cur) is c ref_cur; y emp%rowtype; begin open c for select * from emp; loop fetch c into y; exit when c%notfound; dbms_output.put_line(y.id || ' ' || y.name || ' ' || y.dpt || ' ' || y.sal ); end loop; exception when others then dbms_output.put_line(sqlerrm); end; end pkg; ------------------------------------------------SQL> set serverout on SQL> variable b refcursor SQL> exec pkg.p1(:b); 3 aaa 10 2000 2 bbb 5 3000 1 ccc 15 2500 PL/SQL procedure successfully completed.

14

Quick Reference 1. Exception Handling
PL/SQL block is successfully ended PL/SQL block is terminated with unhandled exception What is Exception? It is an error condition, which terminates the execution of a block. It is a run time condition. Types of Exceptions 3 types of Exceptions 1. Pre-Defined – Is raised Implicitly EXAMPLES (CREATE TABLE ERR_MSG (MESSAGE VARCHAR2(250));) DECLARE V_ENAME EMPLOYEES.LAST_NAME%TYPE; V_SAL EMPLOYEES.SALARY%TYPE:=&P_SAL; BEGIN SELECT LAST_NAME INTO V_ENAME FROM EMPLOYEES WHERE SALARY=V_SAL; INSERT INTO ERR_MSG(MESSAGE) VALUES (V_ENAME||'-'||TO_CHAR(V_SAL)); EXCEPTION WHEN NO_DATA_FOUND THEN INSERT INTO ERR_MSG(MESSAGE) VALUES ('NO EMPLOYEE WITH A SALARY OF '||TO_CHAR(V_SAL)); WHEN TOO_MANY_ROWS THEN INSERT INTO ERR_MSG(MESSAGE) VALUES ('MORE THAN ONE EMPLOYEE WITH A SALARY OF'|| TO_CHAR(V_SAL)); WHEN OTHERS THEN INSERT INTO ERR_MSG (MESSAGE) VALUES (' SOME OTHER ERROR OCCURRED'); END;

2. User-Defined – Is raised Explicitly. They are not associated with Oracle Error. EXAMPLE VARIABLE G_MESSAGE VARCHAR2(50) DECLARE V_SAL EMPLOYEES.SALARY%TYPE:=&P_SAL;

15 V_LOW_SAL V_HIGH_SAL V_NO_EMP EMPLOYEES.SALARY%TYPE:=V_SAL-100; EMPLOYEES.SALARY%TYPE:=V_SAL+100; NUMBER(7); EXCEPTION; EXCEPTION;

E_NO_EMP_RETURNED E_MORE_THAN_ONE_EMP BEGIN

SELECT COUNT(LAST_NAME) INTO V_NO_EMP FROM EMPLOYEES WHERE SALARY BETWEEN V_LOW_SAL AND V_HIGH_SAL; IF V_NO_EMP=0 THEN RAISE E_NO_EMP_RETURNED; ELSIF V_NO_EMP>1 THEN RAISE E_MORE_THAN_ONE_EMP; END IF;

EXCEPTION WHEN E_NO_EMP_RETURNED THEN :G_MESSAGE:=’THERE IS NO EMPLOYEE SALARY BETWEEN ‘|| TO_CHAR(V_LOW_SAL)||’ AND ‘||TO_CHAR(V_HIGH_SAL); WHEN E_MORE_THAN_ONE_EMP THEN :G_MESSAGE:=’THERE IS/ARE ‘||TO_CHAR(V_NO_EMP)||’ EMPLOYEE/S WITH SALARY BETWEEN ‘||TO_CHAR(V_LOW_SAL)||’ AND ‘|| TO_CHAR(V_HIGH_SAL); WHEN OTHERS THEN :G_MESSAGE:=’SOME OTHER ERROR OCCURRED….’; END; / PRINT G_MESSAGE 3. Non-Predefined – Is raised Implicitly. They are associated with Oracle Errors. (PRAGMA Exception Init) Giving the significant names to the ORACLE ERROR CODE with a meaning full message. EXAMPLE 1 -2292  INTEGRITY CONSTRAINT VIOLATION DEFINE P_DEPTNO=199 DECLARE E_EMPS_REMAINING EXCEPTION; PRAGMA EXCEPTION_INIT(E_EMPS_REMAINING, -2292); BEGIN DELETE FROM DEPARTMENTS WHERE DEPARTMENT_ID=&P_DEPTNO; COMMIT; EXCEPTION WHEN E_EMPS_REMAINING THEN

16 DBMS_OUTPUT.PUT_LINE(‘CAN NOT REMOVE DEPT ‘|| TO_CHAR(&P_DEPTNO)||’. EMPLOYEES EXIST’); END; RAISE: Used to raise user-defined exceptions also can raise an exception where the exception is to be raised forcefully. How Exceptions are Raised? There are 2 ways to raise an exceptions 1. Implicitly 2. Explicitly – To execute we use RAISE key word Propagation of Exceptions /* BLOCK A */ DECLARE ….. BEGIN ….. EXCEPTION /* BLOCK B */ DECLARE …. BEGIN …. EXCEPTION ….. (EXCEPTION-1) END; …… (EXCEPTION-2) END; Note: If error occurs in Block B Exception-1 will be raised if Exception-1 is not present then control will be passed to Exception-2 of block A SQLCODE & SQLERRM Cannot be directly used in the value clause of an insert statement. SQLCODE  Returns the numeric value for the error code SQLERRM  Returns the message associated with the error number. EXAMPLE DECLARE V_ERROR_CODE NUMBER; V_ERROR_MESSAGE VARCHAR2(255); BEGIN ………………… ………………… EXCEPTION ………………… ………………… WHEN OTHERS THEN ROLLBACK; V_ERROR_CODE:=SQLCODE; V_ERROR_MESSAGE:=SQLERRM;

17 INSERT INTO ERRORS VALUES (V_ERROR_CODE,V_ERROR_MESSAGE); END; Note: Create a table ‘errors’ with columns accordingly.

2. what is normalization? Basically, it's the process of efficiently organizing data in a database. There are two goals of the normalization process: eliminate redundant data (for example, storing the same data in more than one table) and ensure data dependencies make sense (only storing related data in a table). Both of these are worthy goals as they reduce the amount of space a database consumes and ensure that data is logically stored.

Well normalized data makes programming (relatively) easy, and works very well in multi-platform, enterprise wide environments. Non-normalized data leads to heartbreak. NORMALIZATION: THE
FIRST THREE FORMS

First Normal Form: No repeating groups. As an example, it might be tempting to make an invoice table with columns for the first, second, and third line item (see above). This violates the first normal form, and would result in large rows, wasted space (where an invoice had less than the maximum number of line items), and *horrible* SQL statements with a separate join for each repetition of the column. First form normalization requires you make a separate line item table, with it's own key (in this case the combination of invoice number and line number) (See below).

18

Second Normal Form: Each column must depend on the *entire* primary key. As an example, the customer information could be put in the line item table (see above). The trouble with that is that the customer goes with the invoice, not with each line on the invoice. Putting customer information in the line item table will cause redundant data, with it's inherant overhead and difficult modifications. Second form normalization requires you place the customer information in the invoice table (see below).

19

Third Normal Form: Each column must depend on *directly* on the primary key. As an example, the customer address could go in the invoice table (see above), but this would cause data redundancy if several invoices were for the same customer. It would also cause an update nightmare when the customer changes his address, and would require extensive programming to insert the address every time an existing customer gets a new invoice. Third form normalization requires the customer address go in a separate customer table with its own key (customer), with only the customer identifier in the invoice table (see below).

3. SUPPLIED PACKAGES Several packaged procedures are provided with the Oracle Server, either to extend the functionality of the database or to give PL/SQL access to some SQL features. You may take advantage of the functionality provided by these packages when creating your application, or you may simply want to use these packages for ideas in creating your own stored procedures. This section lists each of the supplied packages and indicates where they are described in more detail. These packages run as the invoking user rather than the package owner. The packaged procedures are callable through public synonyms of the same name.

20

Packages Supporting SQL Features
Oracle supplies the following packaged procedures to give PL/SQL access to some features of SQL:
• • • •

DBMS_DDL DBMS_SESSION DBMS_TRANSACTION DBMS_UTILITY

Table 10-3 describes each of these packages. The footnotes at the end of Table 10-3 explain any restrictions on the use of each procedure. You should consult the package specifications for the most up-to-date information on these packages. Package Procedure(Arguments) alter_compile(type varchar2, schema varchar2, name varchar2) (notes 1, 2, 3, 4) DBMS_DDL analyze_object(type varchar2, schema varchar2, name varchar2, method varchar2, estimate_rows number default null, estimate_percent number default null) SQL Command Equivalent ALTER PROCEDURE proc COMPILE ALTER FUNCTION func COMPILE ALTER PACKAGE pack COMPILE ANALYZE INDEX ANALYZE TABLE ANALYZE CLUSTER

DBMS_ SESSION

close_database_link( dblink varchar2) reset_package (see note 5)

ALTER SESSION CLOSE DATABASE dblink This procedure reinitializes the state of all packages; there is no SQL equivalent ALTER SESSION SET nls_param = nls_param_values

set_nls(param varchar2, value varchar2) (notes 1,4)

21

set_role(role_cmd varchar2) (notes 1, 6)

SET ROLE ...

set_sql_trace(sql_trace boolean) ALTER SESSION SET SQL_TRACE = [TRUE | FALSE] unique_session_id return varchar2 is_role_enabled return boolean This function returns a unique session ID; there is no SQL equivalent. This function is used to determine if a role is enabled; there is no SQL equivalent.

set_close_cached_open_cursors( ALTER SESSION SET close_cursors boolean) CLOSE_CACHED_OPEN_ CURSORS free_unused_user_memory This procedure lets you reclaim unused memory; there is no SQL equivalent. ALTER SESSION ADVISE COMMIT ALTER SESSION ADVISE ROLLBACK ALTER SESSION ADVISE NOTHING COMMIT COMMIT COMMENT text

advise_commit advise_rollback advise_nothing DBMS_ TRANSACTION commit (notes 1,2,4) commit_Comment(cmnt varchar2) (notes 1,2,4) commit_force(xid varchar2, scn varchar2 default null) (notes 1,2,3,4) read_only (notes 1,3,4) read_write (notes 1,3,4) rollback (notes 1,2,4) rollback_force(xid varchar2) (notes 1,2,3,4) rollback_savepoint(

COMMIT FORCE text ...

SET TRANSACTION READ ONLY SET TRANSACTION READ WRITE ROLLBACK ROLLBACK ... FORCE text ... ROLLBACK ... TO SAVEPOINT ...

22

svpt varchar2) (notes 1,2,4) savepoint(savept varchar2) (notes 1,2,4) use_rollback_segment( rb_name varchar2) (notes 1,2,4) purge_mixed(xid in number) begin_discrete_transaction (notes 1,3,4,5) local_transaction_id( create_transaction BOOLEAN default FALSE) return VARCHAR2 step_id return number compile_schema(schema varchar2) (notes 1,2,3,4) DBMS_UTILITY SAVEPOINT savepoint SET TRANSACTION USE ROLLBACK SEGMENT segment See Oracle8 Server Distributed Systems for more information See the Oracle8 Server Tuning manual for more information See Oracle8 Server Distributed Systems for more information

See Oracle8 Server Distributed Systems for more information This procedure is equivalent to calling alter_compile on all procedures, functions, and packages accessible by you. Compilation is completed in dependency order. This procedure is equivalent to calling analyze_object on all objects in the given schema.

analyze_schema( schema varchar2, method varchar2, estimate_rows number default null, estimate_percent number default null) analyze_part_object( schema in varchar2 default null, object_name in varchar2 default null, object_type in char default 'T', command_type in char default 'E', command_opt in varchar2 default null, sample_clause in varchar2 default 'sample 5 percent')

ANALYZE TABLE | INDEX [<schema>.]<object_name> PARTITION <pname> [<command_type>] [<command_opt>] [<sample_clause>]" for each partition of the object, run in parallel using job queues. This procedure submits a job for each partition; you can control the number of concurrent jobs with the initialization parameter

23

JOB_QUEUE_PROCESSES. Object_type must be T (table) or I (index). Command_type can be: - C (compute statistics) - E (estimate statistics) - D (delete statistics) - V (validate structure). For V, command_opt can be 'CASCADE' when object_type is T. For C or E, command_opt can be FOR table, FOR all LOCAL indexes, FOR all columns or a combination of some of the 'for' options of analyze statistics (table). Sample_clause specifies the sample clause to use when command_type is E. format_error_stack return varchar2 format_call_stack return varchar2 is_parallel_server return boolean get_time return number This function formats the error stack into a variable. This function formats the current call stack into a variable. This function returns TRUE when running in Parallel Server mode. This function returns the time in hundredths of a second.

name_resolve(name in varchar2, See Oracle8 Server Distributed DBMS_UTILITY context in number, Systems for more information. schema out varchar2, (continued) part1 out varchar2, part2 out varchar2, dblink out varchar2, part1_type out number, object_number out number)

4. What is an Integrity Constraints ? An integrity constraint is a declarative way to define a business rule for a column of a table. • Can an Integrity Constraint be enforced on a table if some existing table data does not satisfy the constraint ? No.

24

Describe the different type of Integrity Constraints supported by ORACLE ? 1.NOT NULL Constraint - Disallows NULLs in a table's column. 2.UNIQUE Constraint - Disallows duplicate values in a column or set of columns. 3.PRIMARY KEY Constraint - Disallows duplicate values and NULLs in a column or set of columns. 4.FOREIGN KEY Constrain - Require each value in a column or set of columns match a value in a related table's UNIQUE or PRIMARY KEY. 5.CHECK Constraint - Disallows values that do not satisfy the logical expression of the constraint.

What is difference between UNIQUE constraint and PRIMARY KEY constraint ? A column defined as UNIQUE can contain NULLs while a column defined as PRIMARY KEY can't contain Nulls. Describe Referential Integrity ? A rule defined on a column (or set of columns) in one table that allows the insert or update of a row only if the value for the column or set of columns (the dependent value) matches a value in a column of a related table (the referenced value). It also specifies the type of data manipulation allowed on referenced data and the action to be performed on dependent data as a result of any action on referenced data. What are the Referential actions supported by FOREIGN KEY integrity constraint? UPDATE and DELETE Restrict - A referential integrity rule that disallows the update or deletion of referenced data. DELETE Cascade - When a referenced row is deleted all associated dependent rows are deleted. What is self-referential integrity constraint ? If a foreign key reference a parent key of the same table is called selfreferential integrity constraint. What are the Limitations of a CHECK Constraint ? The condition must be a Boolean expression evaluated using the values in the row being inserted or updated and can't contain subqueries, sequence, the SYSDATE,UID,USER or USERENV SQL functions, or the pseudo columns LEVEL or ROWNUM. What is the maximum number of CHECK constraints that can be defined on a column ? No Limit.

25