Java Plsql

  • Upload
    subhjit

  • View
    263

  • Download
    0

Embed Size (px)

Citation preview

  • 7/28/2019 Java Plsql

    1/21

    100 Interview Question and Answers on

    PL/SQL

    QUESTION 1 : What is PL/SQL?

    ANSWER ::PL/SQL is a procedural language that has both interactive SQL and procedural programming language

    constructs such as iteration, conditional branching.

    QUESTION 2 : What is the basic structure of PL/SQL?

    ANSWER ::PL/SQL uses block structure as its basic structure. Anonymous blocks or nested blocks can be used in

    PL/SQL.

    QUESTION 3 : What is PL/SQL block?

    ANSWER ::A set of related declarations and procedural statements is called block.

    QUESTION 4 : What are the components of a PL/SQL Block?

    ANSWER ::

    Declarative part, Executable part and Execption part.

    QUESTION 5 : What are the datatypes a available in PL/SQL?

    ANSWER ::

    Some scalar data types such asNUMBER, VARCHAR2, DATE, CHAR, LONG, BOOLEAN.Some composite data types such as RECORD & TABLE.

    QUESTION 6 : What are % TYPE and % ROWTYPE? What are the advantages of using these

    over datatypes?

    ANSWER ::

    % TYPE provides the data type of a variable or a database column to that variable.

    % ROWTYPE provides the record type that represents a entire row of a table or view or columns

    selected in the cursor.

    The advantages are: I. need not know about variables data typeii. If the database definition of a column in a table changes, the data type of a variable changes

    accordingly.

    QUESTION 7 : What is difference between % ROWTYPE and TYPE RECORD ?

    ANSWER ::

    % ROWTYPE is to be used whenever query returns a entire row of a table or view.

    http://tacklemantra.com/2012/09/13/interview-question-and-answers-on-plsql/http://tacklemantra.com/2012/09/13/interview-question-and-answers-on-plsql/http://tacklemantra.com/2012/09/13/interview-question-and-answers-on-plsql/http://tacklemantra.com/2012/09/13/interview-question-and-answers-on-plsql/
  • 7/28/2019 Java Plsql

    2/21

    TYPE rec RECORD is to be used whenever query returns columns of different table or views and

    variables.

    E.g. TYPE r_emp is RECORD (eno emp.empno% type,ename emp ename %type );e_rec emp% ROWTYPE

    Cursor c1 is select empno,deptno from emp;e_rec c1 %ROWTYPE.

    QUESTION 8. What is PL/SQL table?ANSWER ::

    Objects of type TABLE are called PL/SQL tables, which are modelled as (but not the same as)

    database tables, PL/SQL tables use a primary PL/SQL tables can have one column and a primary key.

    QUESTION 9. What is a cursor? Why Cursor is required?

    ANSWER ::

    Cursor is a named private SQL area from where information can be accessed.

    Cursors are required to process rows individually for queries returning multiple rows.

    QUESTION 10. Explain the two types of Cursors?

    ANSWER ::

    There are two types of cursors, Implict Cursor and Explicit Cursor.PL/SQL uses Implict Cursors for queries.

    User defined cursors are called Explicit Cursors. They can be declared and used.

    QUESTION 11. What are the PL/SQL Statements used in cursor processing?

    ANSWER ::

    DECLARE CURSOR cursor name, OPEN cursor name, FETCH cursor name INTO or Record types,CLOSE cursor name.

    QUESTION 12. What are the cursor attributes used in PL/SQL?

    ANSWER ::%ISOPEN - to check whether cursor is open or not

    % ROWCOUNT - number of rows featched/updated/deleted.

    % FOUND - to check whether cursor has fetched any row. True if rows are featched.% NOT FOUND - to check whether cursor has featched any row. True if no rows are featched.

    These attributes are proceded with SQL for Implict Cursors and with Cursor name for Explict Cursors.

    QUESTION 13. What is a cursor for loop?ANSWER ::Cursor for loop implicitly declares %ROWTYPE as loop index,opens a cursor, fetches rows of values

    from active set into fields in the record and closes when all the records have been processed.

    eg. FOR emp_rec IN C1 LOOP

    salary_total := salary_total +emp_rec sal;END LOOP;

  • 7/28/2019 Java Plsql

    3/21

    QUESTION 14. What will happen after commit statement ?

    ANSWER ::Cursor C1 is

    Select empno,

    ename from emp;Begin

    open C1; loop

    Fetch C1 intoeno.ename;

    Exit When

    C1 %notfound;

    commit;end loop;

    end;

    The cursor having query as SELECT . FOR UPDATE gets closed after COMMIT/ROLLBACK.The cursor having query as SELECT. does not get closed even after COMMIT/ROLLBACK.

    QUESTION 15. Explain the usage of WHERE CURRENT OF clause in cursors ?

    ANSWER ::

    WHERE CURRENT OF clause in an UPDATE,DELETE statement refers to the latest row fetchedfrom a cursor.

    QUESTION 16. What is a database trigger ? Name some usages of database trigger ?

    ANSWER ::

    Database trigger is stored PL/SQL program unit associated with a specific database table. Usages are

    Audit data modifications, Log events transparently, Enforce complex business rules Derive columnvalues automatically, Implement complex security authorizations. Maintain replicate tables.

    QUESTION 17. How many types of database triggers can be specified on a table? What are

    they?

    ANSWER ::

    Insert Update Delete

    Before Row o.k. o.k. o.k.

    After Row o.k. o.k. o.k.

    Before Statement o.k. o.k. o.k.

    After Statement o.k. o.k. o.k.

    If FOR EACH ROW clause is specified, then the trigger for each Row affected by the statement.

  • 7/28/2019 Java Plsql

    4/21

    If WHEN clause is specified, the trigger fires according to the retruned boolean value.

    QUESTION 18. Is it possible to use Transaction control Statements such a ROLLBACK or

    COMMIT in Database Trigger? Why?

    ANSWER ::It is not possible. As triggers are defined for each table, if you use COMMIT of ROLLBACK in a

    trigger, it affects logical transaction processing.

    QUESTION 19. What are two virtual tables available during database trigger execution?

    ANSWER ::The table columns are referred as OLD.column_name and NEW.column_name.

    For triggers related to INSERT only NEW.column_name values only available.

    For triggers related to UPDATE only OLD.column_name NEW.column_name values only available.

    For triggers related to DELETE only OLD.column_name values only available.

    QUESTION 20. What happens if a procedure that updates a column of table X is called in a

    database trigger of the same table?

    ANSWER ::

    Mutation of table occurs.

    QUESTION 21. Write the order of precedence for validation of a column in a table ?

    ANSWER ::

    I. done using Database triggers.ii. done using Integarity Constraints.

    QUESTION 22. What is an Exception? What are types of Exception?ANSWER ::

    Exception is the error handling part of PL/SQL block. The types are Predefined and user_defined.Some of Predefined execptions are

    CURSOR_ALREADY_OPEN

    DUP_VAL_ON_INDEX

    NO_DATA_FOUNDTOO_MANY_ROWS

    INVALID_CURSOR

    INVALID_NUMBER

    LOGON_DENIEDNOT_LOGGED_ON

    PROGRAM-ERROR

    STORAGE_ERRORTIMEOUT_ON_RESOURCE

    VALUE_ERROR

    ZERO_DIVIDEOTHERS.

  • 7/28/2019 Java Plsql

    5/21

    QUESTION 23 WHAT IS The PRAGMA EXECPTION_INIT ?

    ANSWER ::The PRAGMA EXECPTION_INIT tells the complier to associate an exception with an oracle error.

    To get an error message of a specific oracle error.e.g. PRAGMA EXCEPTION_INIT (exception name, oracle error number)

    QUESTION 24. What is Raise_application_error?

    ANSWER ::

    Raise_application_error is a procedure of package DBMS_STANDARD which allows to issue an

    user_defined error messages from stored sub-program or database trigger.

    QUESTION 25. What are the return values of functions SQLCODE and SQLERRM?

    ANSWER ::

    SQLCODE returns the latest code of the error that has occured.

    SQLERRM returns the relevant error message of the SQLCODE.

    QUESTION 26. Where the Pre_defined_exceptions are stored?

    ANSWER ::

    In the standard package.Procedures, Functions & Packages;

    QUESTION 27. What is a stored procedure?

    ANSWER ::

    A stored procedure is a sequence of statements that perform specific function.

    QUESTION 30. What is difference between a PROCEDURE & FUNCTION?

    ANSWER ::

    A FUNCTION is alway returns a value using the return statement.

    A PROCEDURE may return one or more values through parameters or may not return at all.

    QUESTION 31. What are advantages of Stored Procedures?

    ANSWER ::

    Extensibility,Modularity, Reusability, Maintainability and one time compilation.

    QUESTION 32. What are the modes of parameters that can be passed to a procedure?

    ANSWER ::IN,OUT,IN-OUT parameters.

    QUESTION 33. What are the two parts of a procedure?

    ANSWER ::

    Procedure Specification and Procedure Body.

  • 7/28/2019 Java Plsql

    6/21

    QUESTION 34. Give the structure of the procedure?

    ANSWER ::

    PROCEDURE name (parameter list..)is

    local variable declarations

    BEGIN

    Executable statements.Exception.

    exception handlers

    end;

    QUESTION 35. Give the structure of the function?

    ANSWER ::

    FUNCTION name (argument list ..) Return datatype islocal variable declarations

    Begin

    executable statements

    Exceptionexecution handlers

    End;

    QUESTION 36. Explain how procedures and functions are called in a PL/SQL block ?

    ANSWER ::

    Function is called as part of an expression.

    sal := calculate_sal (a822);procedure is called as a PL/SQL statementcalculate_bonus (A822);

    QUESTION 37. What is Overloading of procedures?

    ANSWER ::

    The Same procedure name is repeated with parameters of different datatypes and parameters indifferent positions, varying number of parameters is called overloading of procedures.

    e.g. DBMS_OUTPUT put_line

    QUESTION 38. What is a package? What are the advantages of packages?

    ANSWER ::

    Package is a database object that groups logically related procedures.

    The advantages of packages are Modularity, Easier Applicaton Design, and Information.Hiding,. Reusability and Better Performance.

  • 7/28/2019 Java Plsql

    7/21

    QUESTION 39. What are two parts of package?

    ANSWER ::

    The two parts of package are PACKAGE SPECIFICATION & PACKAGE BODY.Package Specification contains declarations that are global to the packages and local to the schema.

    Package Body contains actual procedures and local declaration of the procedures and cursor

    declarations.

    QUESTION 40. What is difference between a Cursor declared in a procedure and Cursor

    declared in a package specification

    ANSWER ::

    A cursor declared in a package specification is global and can be accessed by other procedures orprocedures in a package.

    A cursor declared in a procedure is local to the procedure that can not be accessed by other procedures.

    QUESTION 41. How packaged procedures and functions are called from the following ?

    a. Stored procedure or anonymous block

    b. an application program such a PRC *C, PRO* COBOLc. SQL *PLUS

    ANSWER ::a. PACKAGE NAME.PROCEDURE NAME (parameters);

    variable := PACKAGE NAME.FUNCTION NAME (arguments);

    EXEC SQL EXECUTEb.

    BEGIN

    PACKAGE NAME.PROCEDURE NAME (parameters)

    variable := PACKAGE NAME.FUNCTION NAME (arguments);END;

    END EXEC;c. EXECUTE PACKAGE NAME.PROCEDURE if the procedures does not have any out/in-outparameters. A function can not be called.

    QUESTION 42 : What is TTITLE and BTITLE?

    ANSWER ::ttitle and btitle used in sql * in reports . to show the header and footer of the reports.

    QUESTION 43 : Explian rowid,rownum?What are the pseduocolumns we have?

    ANSWER ::

    ROWID Hexa decimal number each and every row having unique.Used in searching

    ROWNUM It is a integer number also unique for sorting Normally TOP N Analysys.

    Other Psudo Column are

    NEXTVAL,CURRVAL Of sequence are some exampls

  • 7/28/2019 Java Plsql

    8/21

    QUESTION 44 : In pl/sql functions what is use of out parameter even though we have return

    statement ?.

    ANSWER ::

    With out parameters you can get the more than one out values in the calling program. It is

    recommended not to use out parameters in functions. If you need more than one out values then useprocedures instead of functions.

    QUESTION 45 : How to debug the procedure ?

    ANSWER ::

    put a dbms output_putline statment which will dislapay that your procedure is executing successfullyup to which stage.

    QUESTION 46 : Can Commit,Rollback ,Savepoint be used in Database Triggers?If yes than

    HOW? If no Why?With Reasons .

    ANSWER ::

    we cannot commit inside a trigger.As we all know that when a dml is complete one can issue a commit.

    A trigger if created is fired before the dml completes.so we cannot commit intermediately.

    QUESTION 47 : What is trigger,cursor,functions in pl-sql and we need sample programs about

    it?

    ANSWER ::

    Trigger is an event driven PL/SQL block. Event may be any DML transaction.

    Cursor is a stored select statement for that current session. It will not be stored in the database, it is a

    logical component.Function is a set of PL/SQL statements or a PL/SQL block, which performs an operation and must

    return a value.

    QUESTION 48 :What will the Output for this Coding? Declare Cursor c1 is select * from emp

    FORUPDATE; Z c1%rowtype; Begin Open C1; Fetch c1 into Z; Commit; Fetch c1 in to Z; end;

    ANSWER ::

    By declaring this cursor we can update the table emp through z,means wo not need to write table namefor updation,it may be only by z.

    selecting in FOR UPDATE mode locks the result set of rows in update mode, which means that row

    cannot be updated or deleted until a commit or rollback is issued which will release the row(s).

    QUESTION 49 : Explain how procedures and functions are called in a PL/SQL block ?

    ANSWER ::

    Function is called as part of an expression.

    sal := calculate_sal (a822);procedure is called as a PL/SQL statement

    calculate_bonus (A822);

  • 7/28/2019 Java Plsql

    9/21

    Function can be called from SQL query + explicitly as well

    e.g 1)select empno,salary,fn_comm(salary)from employee;

    2)commision=fn_comm(salary);

    Procedure can be called from begin-end clause.

    e.g.Begin

    (proc_comm(salary);

    )

    end

    QUESTION 50 : How many types of database triggers can be specified on a table ? What are

    they ?

    ANSWER ::

    Baically there only 1 type of trigger which can be fired on the table. .i.e., DML TRIGGER.

    There are 14 types of DML TRIGGER

    But we can fire only 12 types of triggers, because remaining 2 types of triggers fire on View.

    1. Before insert on ROW LEVEL TRIGGER

    2. 1. AFTER insert on ROW LEVEL TRIGGER

    3. Before insert on STATEMENT LEVEL TRIGGER4. After insert on STATEMENT LEVEL TRIGGER

    5. Before update on ROW LEVEL TRIGGER

    6. After update on ROW LEVEL TRIGGER

    7. Before update on STATEMENT LEVEL TRIGGER.8. After update on STATEMENT LEVEL TRIGGER.

    9. Before Delete on STATEMENT LEVEL TRIGGER.

    10 After Delete on STATEMENT LEVEL TRIGGER.

    11. Before Delete on ROW LEVEL TRIGGER.

    12 After Delete on ROW LEVEL TRIGGER

    QUESTION 51 : How we can create a table in PL/SQL block. insert records into it??? is itpossible by some procedure or function?? please give example

    ANSWER ::CREATE OR REPLACE PROCEDURE ddl_create_proc (p_table_name IN VARCHAR2)

    AS

    l_stmt VARCHAR2(200);

  • 7/28/2019 Java Plsql

    10/21

    BEGIN

    DBMS_OUTPUT.put_line(STARTING );

    l_stmt := create table || p_table_name || as (select * from emp );

    execute IMMEDIATE l_stmt;

    DBMS_OUTPUT.put_line(end );

    EXCEPTION

    WHEN OTHERS THEN

    DBMS_OUTPUT.put_line(exception ||SQLERRM || message||sqlcode);

    END;

    We can create table in procedure as explained in above case. but we cant create or perform any DDL

    in functions.

    QUESTION 52 : What is pl/sql?what are the advantages of pl/sql?

    ANSWER ::

    PL/SQL(a product of Oracle) is the programming language extension of sql.It is a full-fledged language although it is specially designed for database centric activities.

    QUESTION 53 : How to disable multiple triggers of a table at at a time?ANSWER ::

    ALTER TABLE

    DISABLE ALL TRIGGER

    QUESTION 54 : 1)What is the starting oracle error number? 2)What is meant by forward

    declaration in functions?

    ANSWER ::One must declare an identifier before referencing it. Once it is declared it can be referred even before

    defining it in the PL/SQL. This rule applies to function and procedures also

    QUESTION 55 : Name the tables where characteristics of Package, procedure and functions arestored ?

    ANSWER ::

    User_objects, User_Source and User_error.

    QUESTION 56 : In a Distributed Database System Can we execute two queries simultaneously ?

    Justify ?

    ANSWER ::

  • 7/28/2019 Java Plsql

    11/21

    As Distributed database system based on 2 phase commit,one query is independent of 2 nd query so of

    course we can run.

    QUESTION 57 : What is difference between stored procedures and application

    procedures,stored function and application function?

    ANSWER ::Stored procedures are sub programs stored in the database and can be called & execute multiple times

    where in an application procedure is the one being used for a particular application same is the way forfunction.

    QUESTION 58 : How to avoid using cursors? What to use instead of cursor and in what cases to

    do so?

    ANSWER ::

    just use subquery in for clause

    example:

    for emprec in (select * from emp)loop

    dbms_output.put_line(emprec.empno);

    end loop;

    no exit statement neededimplicit open,fetch,close occurs

    QUESTION 59 : State the difference between implicit and explicit cursors ?.

    ANSWER ::

    Implicit Cursor are declared and used by the oracle internally. whereas the explicit cursors are

    declared and used by the user. more over implicitly cursors are no need to declare oracle creates andprocess and closes autometically. the explicit cursor should be declared and closed by the user.

    QUESTION 60 : What are the components of a PL/SQL block ?

    ANSWER ::

    components of PL/SQL are:declare:

    (optional) variable declare

    Begin:

    (Mandatory)Procedural statement

    Exception:

    (optional)

    error to be trapped

    End:(Mandatory)

  • 7/28/2019 Java Plsql

    12/21

    So BEGIN and END are required in PL/SQL block

    QUESTION 61 : What is difference between a Cursor declared in a procedure and Cursor

    declared in a package specification ?

    ANSWER ::

    A cursor declared in a package specification is global and can be accessed by other procedures orprocedures in a package.

    A cursor declared in a procedure is local to the procedure that can not be accessed by other procedures.

    One more differene is cursor declared in a package specification must have RETURN type

    QUESTION 62 : What is SQL Deadlock?

    ANSWER ::Deadlock is a unique situation in a multi user system that causes two or more users to wait indefinitely

    for a locked resource. First user needs a resource locked by the second user and the second user needs

    a resource locked by the first user. To avoid dead locks, avoid using exclusive table lock and if using,use it in the same sequence and use Commit frequently to release locks.

    QUESTION 63 : The most important DDL statements in SQL are?

    ANSWER ::CREATE TABLE creates a new database table

    ALTER TABLE alters (changes) a database table

    DROP TABLE deletes a database tableCREATE INDEX creates an index (search key)

    DROP INDEX deletes an index.

    QUESTION 64 : he IN operator may be used if you know the exact value you want to return for

    at least one of the columns.

    ANSWER ::

    SELECT column_name FROM table_name WHERE column_name IN (value1,value2,..)

    QUESTION 65 : What are two parts of package ?

    ANSWER ::1)package specification

    2)package body

    package specification :

    where the variables r global and all the packages can access with that variable.it contains thedeclaration of variables.(variables r global)

    package body:

    where the procedures and functions are collected in that packages.the variable declared with inpackage body of a function or procedure they are not used outside of that procedure.(the variables are

    private used by that specific procedure or function.

  • 7/28/2019 Java Plsql

    13/21

    QUESTION 66 : What are the Restrictions on Cursor Variables?

    ANSWER ::

    You cannot declare cursor variables in a package spec. For example, the following declaration is notallowed:

    CREATE PACKAGE emp_stuff ASTYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;

    emp_cv EmpCurTyp; not allowedEND emp_stuff;

    You cannot pass cursor variables to a procedure that is called through a database link.

    If you pass a host cursor variable to PL/SQL, you cannot fetch from it on the server side unless youalso open it there on the same server call.

    You cannot use comparison operators to test cursor variables for equality, inequality, or nullity.

    You cannot assign nulls to a cursor variable.

    Database columns cannot store the values of cursor variables. There is no equivalent type to use in a

    CREATE TABLE statement.You cannot store cursor variables in an associative array, nested table, or varray.

    Cursors and cursor variables are not interoperable; that is, you cannot use one where the other isexpected. For example, you cannot reference a cursor variable in a cursor FOR loop.

    QUESTION 67 : State the advantage and disadvantage of Cursor?

    ANSWER ::

    Advantage of cursor1.Basically cursor is a logical place or it is active set.

    when a single query returns more than one rows in that case we can use the cursor. we dont need hit

    the database several time. Cursor

    always points the latest rows.

    Disadvantage of cursor

    1.As such there is no disadvantage

    of cursor.

    QUESTION 68 : How we can create a table through procedure ?

    ANSWER ::

    You can create table from procedure using Execute immediate command.

    create procedure p1 isbegin

    EXECUTE IMMEDIATE CREATE TABLE temp AS

    SELECT * FROM emp ;END;

    QUESTION 69 : How packaged procedures and functions are called from the following? a.

    Stored procedure or anonymous block b. an application program such a PRC *C, PRO*

  • 7/28/2019 Java Plsql

    14/21

    COBOL c. SQL *PLUS ?

    ANSWER ::

    a. PACKAGE NAME.PROCEDURE NAME (parameters);variable := PACKAGE NAME.FUNCTION NAME (arguments);

    EXEC SQL EXECUTE

    b.BEGIN

    PACKAGE NAME.PROCEDURE NAME (parameters)

    variable := PACKAGE NAME.FUNCTION NAME (arguments);END;

    END EXEC;

    c. EXECUTE PACKAGE NAME.PROCEDURE if the procedures does not have any out/in-out

    parameters. A function can not be called.

    QUESTION 70 : Where the Pre_defined_exceptions are stored ?

    ANSWER ::In the standard package.

    Procedures, Functions & Packages ;

    QUESTION 71 : Below is the table

    city gender name

    delhi male adelhi female b

    mumbai male c

    mumbai female d

    delhi male e

    I want the o/p as follows:

    male female

    delhi 2 1

    mumbai 1 1

    write the query that can yield the o/p mentioned above?

    ANSWER ::

    select a.city,a.male,b.female from

    (select city,count(gender) male from city where gender=m'group by city,gender)ajoin

    (select city,count(gender) female from city where gender=f group by city,gender)b

    on a.city=b.city

    QUESTION 72 : Operators used in SELECT statements are?

    ANSWER ::

    = Equal

  • 7/28/2019 Java Plsql

    15/21

    or != Not equal

    > Greater than

    < Less than>= Greater than or equal

  • 7/28/2019 Java Plsql

    16/21

    statements cannot be issued against them. This type of table is indexed

    by a binary integer counter (it cannot be indexed by another type of

    number) whose value can be referenced using the number of the index.Remember that PL/SQL tables exist in memory only, and therefore don?t

    exist in any persistent way, disappearing after the session ends.

    A PL/SQL TABLE DECLARATIONThere are two steps in the declaration of a PL/SQL table. First, you must

    define the table structure using the TYPE statement. Second, once a table

    type is created, you then declare the actual table.

    FOR EXAMPLE

    DECLARE

    Table structure definition

    TYPE NameType IS TABLE OFCustomer.name_name%TYPE

    INDEX BY BINARY_INTEGER;

    Create the actual tableCnameTab NameType;

    KnameTab NameType;

    BEGIN

    NULL; END;

    QUESTION 79 : What is Mutating SQL Table?

    ANSWER ::Mutating Table is a table that is currently being modified by an Insert, Update or Delete statement.

    Constraining Table is a table that a triggering statement might need to read either directly for a SQLstatement or indirectly for a declarative Referential Integrity constraints. Pseudo Columns behaves likea column in a table but are not actually stored in the table. E.g. Currval, Nextval, Rowid, Rownum,

    Level etc.

    QUESTION 80 : What are two virtual tables available during database trigger execution ?

    ANSWER ::The table columns are referred as OLD.column_name and NEW.column_name.

    For triggers related to INSERT only NEW.column_name values only available.

    For triggers related to UPDATE only OLD.column_name NEW.column_name values only available.For triggers related to DELETE only OLD.column_name values only available.

    Two tables are: OLD and NEW.

    Insert Trigger :

    OLD no value.NEW inserted value.

  • 7/28/2019 Java Plsql

    17/21

    UPDATE TRIGGER -

    OLD- old value.

    NEW- new updated value.

    DELETE TRIGGER

    OLD old value.NEW no value.

    QUESTION 81 : What is Union?

    ANSWER ::

    Union is the product of two or more tables.

    QUESTION 82 : IS Stored Function Is Pre-Compiled as Stored Procedure ? If No Why

    ANSWER ::

    stored procedure means the pre-compiled precedure ,which is used for a specific action to be executedmore than one times whenever you called from coding in the programe.

    stored procedure is an important concept in the application developement in oracle.

    QUESTION 83 : What is Character Functions?

    ANSWER ::Character Functions are INITCAP, UPPER, LOWER, SUBSTR & LENGTH. Additional functions are

    GREATEST & LEAST. Group Functions returns results based upon groups of rows rather than one

    result per row, use group functions. They are AVG, COUNT, MAX, MIN & SUM.

    QUESTION 84 : How many types of database triggers can be specified on a table? What are

    they?ANSWER ::

    Insert Update DeleteBefore Row o.k. o.k. o.k.

    After Row o.k. o.k. o.k.

    Before Statement o.k. o.k. o.k.

    After Statement o.k. o.k. o.k.If FOR EACH ROW clause is specified, then the trigger for each Row affected by the statement.

    If WHEN clause is specified, the trigger fires according to the returned Boolean value.

    QUESTION 85 : What is difference between % ROWTYPE and TYPE RECORD?

    ANSWER ::% ROWTYPE is to be used whenever query returns a entire row of a table or view.

    TYPE rec RECORD is to be used whenever query returns columns of different

    table or views and variables.E.g. TYPE r_emp is RECORD (eno emp.empno% type,ename emp ename %type

    );

    e_rec emp% ROWTYPE

  • 7/28/2019 Java Plsql

    18/21

    cursor c1 is select empno,deptno from emp;

    e_rec c1 %ROWTYPE.

    One more point : When we have a variable of typer RECORD we have declare additional variables butwith %rowtype, we can only have the fields that are present in the table

    QUESTION 86 : If the application is running very slow? At what points you need to go about

    the database in order to improve the performance?

    ANSWER ::For improving performance, we need to check the sql statement blocks , because for every sql

    satement execution transfor to sql engine and come back to plsq engine that process takes more time to

    process the plsql block.

    QUESTION 87 : How we can create a table in PL/SQL block. insert records into it? is it possible

    by some procedure or function? please give example?

    ANSWER ::

    CREATE OR REPLACE PROCEDURE ddl_create_proc (p_table_name IN VARCHAR2)

    AS

    l_stmt VARCHAR2(200);

    BEGIN

    DBMS_OUTPUT.put_line(STARTING );

    l_stmt := create table || p_table_name || as (select * from emp );

    execute IMMEDIATE l_stmt;

    DBMS_OUTPUT.put_line(end );

    EXCEPTION

    WHEN OTHERS THEN

    DBMS_OUTPUT.put_line(exception ||SQLERRM || message||sqlcode);

    END;

    QUESTION 88 : what is the starting oracle error number? what is meant by forward

    declaration in functions?

    ANSWER ::

    One must declare an identifier before referencing it. Once it is declared it can be referred even before

    defining it in the PL/SQL. This rule applies to function and procedures also

  • 7/28/2019 Java Plsql

    19/21

    QUESTION 89 : What is difference b/w stored procedures and application procedures, stored

    function and application function?

    ANSWER ::Stored procedures are subprogrammes stored in the database and can be called &executee multiple

    times wherein an application procedure is the one being used for a particular application same is the

    way for function.

    Both can be executed any number of times. Only difference is that stored procedures/ functions arestored in database in complied format while the application procedures/functions are not in

    precomplied format and at run time has to be compiled.

    QUESTION 90 : How to know the last executed procedure?

    ANSWER ::

    Execute procedure name (parameter1,parameter2)

    Select timestamps, owner, obj_name, action_name from dba_audit_trail;this statement gives last

    executed time for procedure , function & package.

    QUESTION 91 : How can a function retun more than one value in oracle with proper example?

    ANSWER ::

    yes we can use objects, arrays to return more than one value.

    Basically as per property of function it has to return one value. So the other values can be returned

    from the out parameter of the function.

    But its advised if you want more that one return value go for procedure however function will alsoyield the same result.

    QUESTION 92 : Explain If the entire disk is corrupted how will you and what are the steps to

    recover the database?

    ANSWER ::

    if the entire disk is corrupted and no backup is there do nothing sit and relax their is no possibility of

    recovery a backup is required for restoration and for recovery redo log and archive logs.

    Once if you have theses than think of recovering ..a dba should always plan for the recovery scenariodepending upon the criticality of the database.oracle provides 0% data loss facilty through data guard

    and online backup .its dba who has to decide.

    QUESTION 93 : Can we declare a column having number data type and its scale is larger thanpricesion ex: column_name NUMBER(10,100), column_name NUMBAER(10,-84)

    ANSWER ::

    Yes,we can declare a column with above condition.table created successfully.

    yes, 100 is the total size and 10 is included in 100

  • 7/28/2019 Java Plsql

    20/21

    QUESTION 94 : How to know the last executed procedure?

    ANSWER ::

    Execute procedure name (parameter1,parameter2)

    Select timestamps, owner, obj_name, action_name from dba_audit_trail;this statement gives last

    executed time for procedure , function & package.

    QUESTION 95 : What happens if a procedure that updates a column of table X is called in a

    database trigger of the same table?

    ANSWER ::

    Mutation of table occurs.

    QUESTION 96 : What is an Exception? What are types of Exception?

    ANSWER ::Exception is the error handling part of PL/SQL block. The types are Predefined and user defined.

    Some of Predefined exceptions are.

    CURSOR_ALREADY_OPENDUP_VAL_ON_INDEX

    NO_DATA_FOUND

    TOO_MANY_ROWS

    INVALID_CURSORINVALID_NUMBER

    LOGON_DENIED

    NOT_LOGGED_ONPROGRAM-ERROR

    STORAGE_ERROR

    TIMEOUT_ON_RESOURCE

    VALUE_ERRORZERO_DIVIDE

    OTHERS.

    exception is an identifier and error handling part of pl/sql types := 1)predifined2) user defined.

    QUESTION 97 : What happens if a procedure that updates a column of table X is called in a

    database trigger of the same table?

    ANSWER ::Mutation of table occurs.

    QUESTION 98 : How can a function retun more than one value in oracle?

    ANSWER ::

    yes we can use objects, arrays to return more than one value .

    QUESTION 99 : What are the Restrictions on Cursor Variables?

    ANSWER ::

    Currently, cursor variables are subject to the following restrictions:You cannot declare cursor variables

  • 7/28/2019 Java Plsql

    21/21

    in a package spec. For example, the following declaration is not allowed:CREATE PACKAGE

    emp_stuff AS TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE; emp_cv

    EmpCurTyp; not allowedEND emp_stuff;You cannot pass cursor variables to a procedure that iscalled through a database link.If you pass a host cursor variable to PL/SQL, you cannot fetch from it

    on the server side unless you also open it there on the same server call.You cannot use comparison

    operators to test cursor variables for equality, inequality, or nullity.You cannot assign nulls to a cursorvariable.Database columns cannot store the values of cursor variables. There is no equivalent type to

    use in a CREATE TABLE statement.You cannot store cursor variables in an associative array, nested

    table, or varray.Cursors and cursor variables are not interoperable; that is, you cannot use one wherethe other is expected. For example, you cannot reference a cursor variable in a cursor FOR loop

    QUESTION 100 :What will the Output for this Coding> Declare Cursor c1 is select * from emp

    FORUPDATE; Z c1%rowtype; Begin Open C1; Fetch c1 into Z; Commit; Fetch c1 in to Z; end;

    ANSWER ::By declaring this cursor we can update the table emp through z,means wo not need to write table name

    for updation,it may be only by z.

    By issuing the TCL like commit or rollback, the cursor will be closed automatically, you cannat fetch

    again.

    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::