+ All Categories
Home > Documents > Oracle Questions and Answers 3

Oracle Questions and Answers 3

Date post: 10-Apr-2018
Category:
Upload: ashok-babu
View: 215 times
Download: 0 times
Share this document with a friend

of 25

Transcript
  • 8/8/2019 Oracle Questions and Answers 3

    1/25

    Quick Reference

    1.TriggersThere are two kinds of triggers basically.

    (1) Row Level Triggers(2) Statement Level TriggersIt can be again broadly classified as follows

    Row Level

    BEFORE INSERTAFTER INSERTBEFORE UPDATEAFTER UPDATEBEFORE DELETEAFTER DELETE

    StatementLevel

    BEFORE INSERT

    AFTER INSERTBEFORE UPDATEAFTER UPDATEBEFORE DELETEAFTER DELETE

    2. CursorOracle server uses work areas called private SQL areas to execute SQL statements and tostore processing information. PL/SQL cursors can be used to name a private SQL areaand 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 cursorswould 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;

    1

  • 8/8/2019 Oracle Questions and Answers 3

    2/25

    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 ImplicitOracle does it.

    Cursor Attributes (cursor variables)

    1. %found2. %notfound3. %isopen4. %rowcount

    4. SQL Commands1. 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 DELETETruncate reuse storage will retain thespace

    Rollback is possible for delete as itcreates rollback segments

    Truncate cannot be conditional. Delete can be conditional.Truncate resets high-water mark if dropstorage option is given.

    Delete dont reset.

    6. JoinsJoins are used to combine rows from two or more Tables. There are different kinds of Joins

    1. Self Join2. 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

    2

  • 8/8/2019 Oracle Questions and Answers 3

    3/25

    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 103102 bbb 15 101103 ccc 25 102

    3 rows selected.

    SQL> select * from dptb;

    DPT DPT_NAME------------------------- ----------

    10 uuu15 vvv20 www25 xxx30 yyy

    5 rows selected.

    1. Self Join

    Joining a table to itself.Self Join is used to combine rows of the same table in a different way by satisfyingcertain conditions. Take the case of table EMPB. Suppose we need to display the IDalong MNG (Manager) Names. See the Query given below.

    SQL>select worker.id, manager.name from empb worker, empb managerwhere worker.MNG=manager.ID order by worker.id;

    ID NAME-------------------- ---------------

    101 ccc102 aaa103 bbb

    3 rows selected.

    3

  • 8/8/2019 Oracle Questions and Answers 3

    4/25

    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 uuu102 bbb 15 101 15 vvv103 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 uuu102 bbb 15 101 10 uuu103 ccc 25 102 10 uuu101 aaa 10 103 15 vvv

    102 bbb 15 101 15 vvv103 ccc 25 102 15 vvv101 aaa 10 103 20 www102 bbb 15 101 20 www103 ccc 25 102 20 www101 aaa 10 103 25 xxx102 bbb 15 101 25 xxx103 ccc 25 102 25 xxx101 aaa 10 103 30 yyy102 bbb 15 101 30 yyy103 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.

    4

  • 8/8/2019 Oracle Questions and Answers 3

    5/25

    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 uuu102 bbb vvv

    www103 ccc xxx

    yyy

    5 rows selected.

    In the above query result it is clear that as the Department Numbers 20, 30 are not therewith 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 DPT_NAME---- ---------- ------------------------- ------------------------- ------------ ----------------

    101 aaa 10 103 10 uuu101 aaa 10 103 15 vvv101 aaa 10 103 20 www101 aaa 10 103 25 xxx101 aaa 10 103 30 yyy102 bbb 15 101 10 uuu102 bbb 15 101 15 vvv102 bbb 15 101 20 www102 bbb 15 101 25 xxx102 bbb 15 101 30 yyy103 ccc 25 102 10 uuu103 ccc 25 102 15 vvv103 ccc 25 102 20 www

    103 ccc 25 102 25 xxx103 ccc 25 102 30 yyy

    15 rows selected.

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

    5

  • 8/8/2019 Oracle Questions and Answers 3

    6/25

    7. Global Temporary tablesCan be created for temporary purpose,On commit preserve rows Available for that transaction, till commit is firedOn commit delete rows -- Available for entire session

    CREATE GLOBAL TEMPORARY TABLE A (A NUMBER) ON COMMIT PRESERVE ROWSCREATE 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 thesecond occurance onwards.

    10. Greatest 5

    SQL>select sal from (select sal from emp order by sal desc)where rownum

  • 8/8/2019 Oracle Questions and Answers 3

    7/25

    2. UNION ALLThe 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 records3. 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 shouldmatch.

    4. MINUS The Set operator MINUS retrieves all the records from the first query that are not thereint the Second query. The Data type and number of colums in every select query shouldmatch.

    Refer the tables used for JOINS and see the following quries

    SQL> select dpt from dptb minus select dpt from empb;

    DPT-------------------------

    2030

    2 rows selected.

    SQL> select dpt from dptb union select dpt from empb;

    DPT-------------------------

    1015202530

    5 rows selected.

    SQL> select dpt from dptb union all select dpt from empb;

    DPT-------------------------

    101520253010

    7

  • 8/8/2019 Oracle Questions and Answers 3

    8/25

    1525

    8 rows selected.

    SQL> select dpt from dptb intersect select dpt from empb;

    DPT-------------------------

    101525

    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. MIN()2. MAX()3. COUNT()4. AVG()5. 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 uuu102 bbb 15 vvv0 NOBODY 10 www103 ccc 25 xxx0 NOBODY 10 yyy

    5 rows selected.

    Refer the Tables given in the Join section. Here whenever the ID is NULL it getssubstited with 0 and whenever the NAME is NULL getting substitued withNOBODY.

    8

  • 8/8/2019 Oracle Questions and Answers 3

    9/25

    14. DECODE - Function

    SQL> select dpt || ' --> ' || decode(dpt,10,'uuu',15,'vvv','nnn' ) EMP_DPT from empb;

    EMP_DPT------------------------------------------------10 --> uuu15 --> vvv

    25 --> nnn3 rows selected.

    Refer Tables given in the Join Section. Here when the Department is 10 it gives uuuand when the department 15 it gives vvv and for rest(whatever is the department) itgives 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 PM1 row selected.

    SQL> select trunc(sysdate) from dual;

    TRUNC(SYSDA------------------------9/23/20041 row selected.

    9

  • 8/8/2019 Oracle Questions and Answers 3

    10/25

    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-------------------------

    10

  • 8/8/2019 Oracle Questions and Answers 3

    11/25

    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.

    11

  • 8/8/2019 Oracle Questions and Answers 3

    12/25

    16. To Get Oracle Version

    sql>select * from v$version ;

    BANNER

    -----------------------------------------------------------Oracle8i Enterprise Edition Release 8.1.6.1.0 - ProductionPL/SQL Release 8.1.6.0.0 - ProductionCORE 8.1.6.0.0 ProductionTNS 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

    Eg: Goto labelOne;

    12

  • 8/8/2019 Oracle Questions and Answers 3

    13/25

    19. RefCursor

    create or replace package pkg astype 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) isc ref_cur;y emp%rowtype;

    beginopen c for select * from emp;loopfetch c into y;

    exit when c%notfound;dbms_output.put_line(y.id || ' ' || y.name || ' ' || y.dpt || ' ' || y.sal );end loop;exceptionwhen others thendbms_output.put_line(sqlerrm);end;end pkg;-------------------------------------------------

    SQL> set serverout onSQL> variable b refcursor SQL> exec pkg.p1(:b);3 aaa 10 20002 bbb 5 30001 ccc 15 2500

    PL/SQL procedure successfully completed.

    13

  • 8/8/2019 Oracle Questions and Answers 3

    14/25

    Quick Reference

    1. Exception HandlingPL/SQL block is successfully endedPL/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 Exceptions3 types of Exceptions

    1. Pre-Defined Is raised Implicitly

    EXAMPLES

    (CREATE TABLE ERR_MSG (MESSAGE VARCHAR2(250));)

    DECLAREV_ENAME EMPLOYEES.LAST_NAME%TYPE;V_SAL EMPLOYEES.SALARY%TYPE:=&P_SAL;

    BEGINSELECT LAST_NAMEINTO V_ENAMEFROM EMPLOYEESWHERE SALARY=V_SAL;INSERT INTOERR_MSG(MESSAGE)VALUES (V_ENAME||'-'||TO_CHAR(V_SAL));

    EXCEPTIONWHEN NO_DATA_FOUND THEN

    INSERT INTO ERR_MSG(MESSAGE)VALUES ('NO EMPLOYEE WITH A SALARY OF '||TO_CHAR(V_SAL));

    WHEN TOO_MANY_ROWS THENINSERT INTO ERR_MSG(MESSAGE)VALUES ('MORE THAN ONE EMPLOYEE WITH A SALARY OF'||TO_CHAR(V_SAL));

    WHEN OTHERS THENINSERT INTO ERR_MSG (MESSAGE)VALUES (' SOME OTHER ERROR OCCURRED');

    END;

    2. User-Defined Is raised Explicitly. They are not associated withOracle Error.

    EXAMPLE

    VARIABLE G_MESSAGE VARCHAR2(50)DECLARE

    V_SAL EMPLOYEES.SALARY%TYPE:=&P_SAL;

    14

  • 8/8/2019 Oracle Questions and Answers 3

    15/25

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

    E_NO_EMP_RETURNED EXCEPTION;E_MORE_THAN_ONE_EMP EXCEPTION;

    BEGINSELECT COUNT(LAST_NAME)INTO V_NO_EMPFROM EMPLOYEESWHERE SALARY BETWEEN V_LOW_SAL AND V_HIGH_SAL;

    IF V_NO_EMP=0THEN

    RAISE E_NO_EMP_RETURNED;ELSIF V_NO_EMP>1THEN

    RAISE E_MORE_THAN_ONE_EMP;END IF;

    EXCEPTIONWHEN 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 withOracle Errors.(PRAGMA Exception Init)Giving the significant names to the ORACLE ERROR CODE with a meaning fullmessage.

    EXAMPLE 1

    -2292 INTEGRITY CONSTRAINT VIOLATION

    DEFINE P_DEPTNO=199

    DECLAREE_EMPS_REMAINING EXCEPTION;PRAGMA EXCEPTION_INIT(E_EMPS_REMAINING, -2292);

    BEGINDELETE FROMDEPARTMENTSWHERE DEPARTMENT_ID=&P_DEPTNO;COMMIT;

    EXCEPTIONWHEN E_EMPS_REMAINING THEN

    15

  • 8/8/2019 Oracle Questions and Answers 3

    16/25

  • 8/8/2019 Oracle Questions and Answers 3

    17/25

    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 twogoals of the normalization process: eliminate redundant data (for example, storingthe 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 reducethe amount of space a database consumes and ensure that data is logically stored.

    Well normalized data makes programming (relatively) easy, and works very well inmulti-platform, enterprise wide environments. Non-normalized data leads to heartbreak.

    N ORMALIZATION : T HE FIRST THREE FORMS

    First Normal Form: No repeating groups. As an example, it might be tempting to make an invoice table withcolumns for the first, second, and third line item (see above). This violates the firstnormal form, and would result in large rows, wasted space (where an invoice had lessthan 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 aseparate line item table, with it's own key (in this case the combination of invoice number and line number) (See below).

    17

  • 8/8/2019 Oracle Questions and Answers 3

    18/25

    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 thatthe 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 overheadand difficult modifications. Second form normalization requires you place the customer information in the invoice table (see below).

    18

  • 8/8/2019 Oracle Questions and Answers 3

    19/25

    Third Normal Form: Each column must depend on *directly* on the primary key. As an example, thecustomer address could go in the invoice table (see above), but this would cause dataredundancy if several invoices were for the same customer. It would also cause an updatenightmare 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 tablewith its own key (customer), with only the customer identifier in the invoice table (see

    below).

    3. S UPPLIED P ACKAGES

    Several packaged procedures are provided with the Oracle Server, either to extend thefunctionality of the database or to give PL/SQL access to some SQL features. You maytake 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 inmore 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.

    19

  • 8/8/2019 Oracle Questions and Answers 3

    20/25

    Packages Supporting SQL Features

    Oracle supplies the following packaged procedures to give PL/SQL access to somefeatures 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 packagespecifications for the most up-to-date information on these packages.

    Package Procedure(Arguments) SQL Command Equivalent

    DBMS_DDL

    alter_compile(type varchar2,schema varchar2,name varchar2)(notes 1, 2, 3, 4)

    ALTER PROCEDURE procCOMPILE

    ALTER FUNCTION funcCOMPILE

    ALTER PACKAGE pack COMPILE

    analyze_object(type varchar2,schema varchar2,name varchar2,method varchar2,estimate_rows number default null,estimate_percent number default null)

    ANALYZE INDEX

    ANALYZE TABLE

    ANALYZE CLUSTER

    DBMS_ SESSION

    close_database_link(dblink varchar2)

    ALTER SESSION CLOSEDATABASE dblink

    reset_package (see note 5) This procedure reinitializes the stateof all packages; there is no SQLequivalent

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

    ALTER SESSION SETnls_param =nls_param_values

    20

    http://www-rohan.sdsu.edu/doc/oracle/server803/A54642_01/ch7b.htm#20951http://www-rohan.sdsu.edu/doc/oracle/server803/A54642_01/ch7b.htm#20951http://www-rohan.sdsu.edu/doc/oracle/server803/A54642_01/ch7b.htm#20951http://www-rohan.sdsu.edu/doc/oracle/server803/A54642_01/ch7b.htm#20951http://www-rohan.sdsu.edu/doc/oracle/server803/A54642_01/ch7b.htm#20951http://www-rohan.sdsu.edu/doc/oracle/server803/A54642_01/ch7b.htm#20951
  • 8/8/2019 Oracle Questions and Answers 3

    21/25

    set_role(role_cmd varchar2)(notes 1, 6)

    SET ROLE ...

    set_sql_trace(sql_trace boolean) ALTER SESSION SETSQL_TRACE = [TRUE | FALSE]

    unique_session_idreturn varchar2

    This function returns a uniquesession ID; there is no SQLequivalent.

    is_role_enabledreturn boolean

    This function is used to determine if a role is enabled; there is no SQLequivalent.

    set_close_cached_open_cursors(close_cursors boolean)

    ALTER SESSION SETCLOSE_CACHED_OPEN_ CURSORS

    free_unused_user_memory This procedure lets you reclaimunused memory; there is no SQLequivalent.

    DBMS_ TRANSACTION

    advise_commit ALTER SESSION ADVISECOMMIT

    advise_rollback ALTER SESSION ADVISEROLLBACK

    advise_nothing ALTER SESSION ADVISE NOTHING

    commit (notes 1,2,4) COMMIT

    commit_Comment(cmntvarchar2)(notes 1,2,4)

    COMMIT COMMENT text

    commit_force(xid varchar2,scn varchar2default null)(notes 1,2,3,4)

    COMMIT FORCE text ...

    read_only (notes 1,3,4) SET TRANSACTION READONLY

    read_write (notes 1,3,4) SET TRANSACTION READWRITE

    rollback (notes 1,2,4) ROLLBACK

    rollback_force(xid varchar2)(notes 1,2,3,4)

    ROLLBACK ... FORCE text ...

    rollback_savepoint( ROLLBACK ... TO SAVEPOINT ...

    21

  • 8/8/2019 Oracle Questions and Answers 3

    22/25

    svpt varchar2)(notes 1,2,4)

    savepoint(savept varchar2)(notes 1,2,4)

    SAVEPOINT savepoint

    use_rollback_segment(rb_name varchar2)(notes 1,2,4)

    SET TRANSACTION USEROLLBACK SEGMENT segment

    purge_mixed(xid in number) See Oracle8 Server DistributedSystems for more information

    begin_discrete_transaction(notes 1,3,4,5)

    See the Oracle8 Server Tuningmanual for more information

    local_transaction_id(create_transaction BOOLEANdefault FALSE)return VARCHAR2

    See Oracle8 Server DistributedSystems for more information

    step_id return number See Oracle8 Server DistributedSystems for more information

    DBMS_UTILITY

    compile_schema(schemavarchar2)(notes 1,2,3,4)

    This procedure is equivalent tocalling alter_compile on all

    procedures, functions, and packagesaccessible by you. Compilation iscompleted in dependency order.

    analyze_schema(

    schema varchar2,method varchar2,estimate_rows number defaultnull,estimate_percent number default null)

    This procedure is equivalent to

    calling analyze_object on allobjects in the given schema.

    analyze_part_object(schema in varchar2 default null,object_name in varchar2default null,object_type in char default 'T',command_type in char default 'E',command_opt in varchar2default null,sample_clause in varchar2default 'sample 5 percent')

    ANALYZE TABLE | INDEX[.]PARTITION [][][]"for each partition of the object, runin parallel using job queues. This

    procedure submits a job for each partition; you can control the number of concurrent jobs with theinitialization parameter

    22

  • 8/8/2019 Oracle Questions and Answers 3

    23/25

    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 beFOR table, FOR all LOCALindexes, FOR all columns or acombination of some of the 'for'options of analyze statistics (table).Sample_clause specifies the sampleclause to use when command_type is

    E.format_error_stack return varchar2

    This function formats the error stack into a variable.

    format_call_stack return varchar2

    This function formats the current callstack into a variable.

    is_parallel_server return boolean

    This function returns TRUE whenrunning in Parallel Server mode.

    get_timereturn number

    This function returns the time inhundredths of a second.

    DBMS_UTILITY

    (continued)

    name_resolve(name in varchar2,context in number,schema out varchar2,

    part1 out varchar2, part2 out varchar2,dblink out varchar2,

    part1_type out number,object_number out number)

    See Oracle8 Server DistributedSystems for more information.

    4. What is an Integrity Constraints ?An integrity constraint is a declarative way to define a business rule for acolumn of a table.

    Can an Integrity Constraint be enforced on a table if some existing tabledata does not satisfy the constraint ?No.

    23

  • 8/8/2019 Oracle Questions and Answers 3

    24/25

    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 acolumn 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 logicalexpression 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 asPRIMARY KEY can't contain Nulls.

    Describe Referential Integrity ?A rule defined on a column (or set of columns) in one table that allows theinsert 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 relatedtable (the referenced value). It also specifies the type of datamanipulation allowed on referenced data and the action to be performed ondependent data as a result of any action on referenced data.

    What are the Referential actions supported by FOREIGN KEY integrityconstraint?

    UPDATE and DELETE Restrict - A referential integrity rule that disallows theupdate or deletion of referenced data.DELETE Cascade - When a referenced row is deleted all associated dependentrows are deleted.

    What is self-referential integrity constraint ?If a foreign key reference a parent key of the same table is called self-referential integrity constraint.

    What are the Limitations of a CHECK Constraint ?The condition must be a Boolean expression evaluated using the values inthe row being inserted or updated and can't contain subqueries, sequence,the SYSDATE,UID,USER or USERENV SQL functions, or the pseudo columnsLEVEL or ROWNUM.

    What is the maximum number of CHECK constraints that can be defined on acolumn ?No Limit.

    24

  • 8/8/2019 Oracle Questions and Answers 3

    25/25

    25


Recommended