Question : How to debug the procedure ?

Answer : You can use DBMS_OUTPUT oracle supplied package or DBMS_DEBUG pasckage. Question : 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 : Can Commit,Rollback ,Savepoint be used in Database Triggers?If yes than HOW? If no Why?With Reasons Question : 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 use procedures instead of functions. Question : How we can create a table through procedure ? Answer: You can create table from procedure using Execute immediate command. create procedure p1 is begin EXECUTE IMMEDIATE 'CREATE TABLE temp AS SELECT * FROM emp ' ; END; Question : What is ref cursor. Ref Cursor is cursor variable. It is a pointer to a result set. It is useful in scenarios when result set is created in one program and the processing of the same in some other, might be written in different language, e.g. firing the select is done in PL/SQL and the processing will be done in java. Its a run time query binding with the cursor variable. Normal cursors are static cursors becaz they get acquited of query at the compile time. Question : What is pl/sql?what are the advantages of pl/sql? 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. PL/SQL is Very Usefully Language & Tools of Oracle to Manipulate,Restrict,Validate & Control the Unauthorized Access of Data From the Database. We Can easily show multiple records of the multiple table at same time. And Using control statement like Loops & If else & Select case we control the database. Question : State the advantage and disadvantage of Cursor? Answer : Advantage : In pl/sql if you want perform some actions more than one records you should user these cursors only. bye using these cursors you process the query records. you can easily move the records and you can exit from procedure when you required by using cursor attributes. disadvantage: using implicit/explicit cursors are depended by sutiation. if the result set is les than 50 or 100 records it is better to go for implicit cursors. if the result set is large then you should use exlicit cursors. other wise it will put burdon on cpu. Question: State the difference between implicit and explicit cursor's. 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 and process and closes autometically. the explicit cursor should be declared and closed by the user. Implict cursor can be used to handle single record (i.e) the select query used should not yield more than one row.if u have handle more than one record then Explict cursor should be used. Question : 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 for function 1

Question : How we can create a table in PL/SQL block. which is used for fast response from Oracle Engine. l_stmt := 'create table '|| p_table_name || ' as (select * from emp )'.put_line(emprec. no exit statement needed implicit open. Question : How to disable multiple triggers of a table at at a time? Answer : ALTER TABLE<TABLE NAME> DISABLE ALL TRIGGER ALTER TABLE TT_DCB DISABLE ALL TRIGGERS Question : can we declare a column having number data type and its scale is larger than pricesion 2 . We can create table in procedure as explained in above case. It gives the location in database where row is physically stored. end loop. DBMS_OUTPUT.Hexa decimal number each and every row having unique. Answer : CREATE OR REPLACE PROCEDURE ddl_create_proc (p_table_name IN VARCHAR2) AS l_stmt VARCHAR2(200). insert records into it??? is it possible by some procedure or function?? please give example. Question : 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.empno).put_line('end '). execute IMMEDIATE l_stmt. ROWNUM: It gives a sequence number in which rows are retrieved from the database. This rule applies to function and procedures also ORACLE ERROR NO starts with ORA 00001 Question : In a Distributed Database System Can we execute two queries simultaneously ? Justify ? Answer : As Distributed database system based on 2 phase commit. but we can't create or perform any DDL in functions.put_line('STARTING ').Used in searching ROWNUM .close occurs We have avoided declaration of cursor. Question : Answer : Explian rowid.rownum?What are the pseduocolumns we have? ROWID .. Once it is declared it can be referred even before defining it in the PL/SQL. BEGIN DBMS_OUTPUT.CURRVAL Of sequence are some exampls ROWID : It gives the hexadecimal string representing the address of a row.the given example will create cursor with some system generated name.Difference is Stored Procedure must return multiple value and function must return single value . EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.fetch.It is a integer number also unique for sorting Normally TOP N query is independent of 2 nd query so of course we can run.put_line('exception '||SQLERRM || 'message'||sqlcode).. Question : 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 ex: for emprec in (select * from emp) loop dbms_output. END. Other Psudo Column are NEXTVAL.Stored Procedure/Function is a compiled database object.

Executable part and Exception part. Fetch c1 into Z.You cannot use comparison operators to test cursor variables for equality. There is no equivalent type to use in a CREATE TABLE statement.You cannot store cursor variables in an associative array. which means that row cannot be updated or deleted until a commit or rollback is issued which will release the row(s). cursor variables are subject to the following restrictions:You cannot declare cursor variables in a package spec. we can declare a column with above condition. or varray. Question : What is PL/SQL ? Answer : PL/SQL is a procedural language that has both interactive SQL and procedural programming language constructs such as iteration. Fetch c1 in to Z. end. DECLARE --all the variables u use in ur program should be declared here --BEGIN --application logic goes here -EXCEPTION HANDLING --very imp END Question : What are the components of a PL/SQL block ? Answer : A set of related declarations and procedural statements is called block. VARCHAR2. conditional branching. nested table. Question : What are the components of a PL/SQL Block ? Answer : Declarative part.100). Question : What is the basic structure of PL/SQL ? Answer : PL/SQL uses block structure as its basic structure. you cannot use one where the other is expected. table created successfully. Begin Open C1. 3 . We can create the table like create table as1(id number(10. or nullity. DATE. Commit. For example. Some composite data types such as RECORD & may be only by "z".Database columns cannot store the values of cursor variables. you cannot fetch from it on the server side unless you also open it there on the same server call. column_name NUMBAER(10.You cannot pass cursor variables to a procedure that is called through a database link. selecting in FOR UPDATE mode locks the result set of rows in update mode. inequality.not allowedEND emp_stuff.ex: column_name NUMBER(10.You cannot assign nulls to a cursor variable. -. Anonymous blocks or nested blocks can be used in PL/SQL. the following declaration is not allowed:CREATE PACKAGE emp_stuff AS TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE.means wo not need to write table name for updation. For example. it will give error Question : What are the Restrictions on Cursor Variables? Answer : Currently. CHAR.-84) Ans: Yes. Z c1%rowtype. Answer : By declaring this cursor we can update the table emp through z. that is.11)) but we cant insert the data into the table.Cursors and cursor variables are not interoperable.If you pass a host cursor variable to PL/SQL. emp_cv EmpCurTyp. LONG. BOOLEAN. Datatypes PL/SQL Question : What are the datatypes a available in PL/SQL ? Some scalar data types such as NUMBER. you cannot reference a cursor variable in a cursor FOR loop Question : What will the Output for this Coding> Declare Cursor c1 is select * from emp FORUPDATE.

PL/SQL tables use a primary PL/SQL tables can have one column and a primary key. CLOSE cursor name. Question : What is PL/SQL table ? Answer : Objects of type TABLE are called "PL/SQL tables".open the cursor. In that case.Here all the DML statement is executed and to processing statement. %TYPE provides datatypes of the particular column of the table. FETCH cursor name INTO or Record types.empno% type. Implicit cursor is open for all DML statement. % ROWTYPE provides the record type that represents a entire row of a table or view or columns selected in the cursor.Question : What are % TYPE and % ROWTYPE ? What are the advantages of using these over datatypes? Ans: % TYPE provides the data type of a variable or a database column to that variable.ename emp ename %type ).basically it's a implicit cursor. then fetch the value from the active set. The oracle server uses works areas called private sql area.%rowtype automatically change the datatypes for the variable which is created by user Question : 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. if we change any datatypes of the column. This way we can make declaration of PL/SQL tables. Cursors TYPE tab IS TABLE OF VARCHAR2(30).Explicit cursor.programmer creates explicit cursor. secondly if we don't know the data type of some column %rowtype is useful for that. Cursors are required to process rows individually for queries returning multiple rows. They are also reffed as Nested Table and are pat of PLSQL collections. TYPE r_emp is RECORD (eno emp. there are two types of cursor 1. The advantages are : I. TYPE rec RECORD is to be used whenever query returns columns of different table or views and variables. PL/SQL uses Implicit Cursors for queries. E. finally. They can be declared and used. Need not know about variable's data type ii. User defined cursors are called Explicit Cursors.after execute the statement cursor is atomatically closed. Implicit Cursor and Explicit Cursor. If the database definition of a column in a table changes.implicit cursor 2.deptno from emp. They are used for bulk data processing. OPEN cursor name. e_rec c1 %ROWTYPE. Question : What is a cursor ? Why Cursor is required ? Cursor is a named private SQL area from where information can be accessed. Question : Explain the two type of Cursors ? Answer : There are two types of cursors. e_rec emp% ROWTYPE cursor c1 is select empno. which are modeled as (but not the same as) database tables. explicit cursor is needed when query returns more than one rows. Explicit cursor Question : What are the PL/SQL Statements used in cursor processing ? Ans: DECLARE CURSOR cursor name. there are two types of cursor 1.Implicit cursor. 4 . 2. Explicit cursor is created by programmer. after fetching all the value. %ROWTYPE attribute is useful When we need to fetch entire row from the table.g. the data type of a variable changes accordingly. cursor is closed by programmer.

END LOOP. Question : What is a cursor for loop ? Answer : Cursor for loop implicitly declares %ROWTYPE as loop index. Usages are Audit data modifications. end loop. Question : Explain the usage of WHERE CURRENT OF clause in cursors ? WHERE CURRENT OF clause in an UPDATE. the database triggers are fires (executed) or called implicitly whenever the table is affected by any of the above said DML operations. which have to be called explicitly. all the changes data are parmanently stored in the database.DELETE statement refers to the latest row fetched from a cursor.----commit. does not get closed even after COMMIT/ROLLBACK. The code in the trigger defines the action the database needs to perform whenever some database manipulation (INSERT. Implement complex security authorizations. Unlike the stored procedure and functions. A database trigger fires with the privileges of owner not that of user A database trigger has three parts 1.. but in higher versions of Oracle there is no such limitation. A trigger constraint (Optional) 5 .number of rows fetched/updated/deleted..0 only 12 triggers could be associated with a given table.opens a cursor. % FOUND . eg. DELETE) takes place. fetches rows of values from active set into fields in the record and closes when all the records have been processed. After commit check whether cursor is open or not % ROWCOUNT . Enforce complex business rules Derive column values automatically. A database triggers is stored PL/SQL program unit associated with a specific database table or view. Database Triggers Where CURRENT OF clause means cursor points to present row of the cursor Question : 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..Question : What are the cursor attributes used in PL/SQL ? %ISOPEN . fetches rows of values from active set into fields in the record and closes when all the records have been check whether cursor has fetched any row. ename from emp. The cursor having query as SELECT. The cursor having query as SELECT . True if no rows are featched. Begin open C1. These attributes are proceeded with SQL for Implicit Cursors and with Cursor name for Explicit Cursors. True if rows are fetched. eg. Question : What will happen after commit statement ? Answer : Cursor C1 is Select empno... loop Fetch C1 into eno.all the transaction will be ended.ename. FOR emp_rec IN C1 LOOP salary_total := salary_total +emp_rec sal. end. FOR UPDATE gets closed after COMMIT/ROLLBACK.opens a cursor. Till oracle 7. FOR emp_rec IN C1 LOOP salary_total := salary_total +emp_rec check whether cursor has fetched any row. Log events transparently. Maintain replicate tables. UPDATE. END LOOP. % NOT FOUND . Cursor for loop implicitly declares %ROWTYPE as loop index. Exit When C1 %notfound. A triggering event 2.

Question : What are two virtual tables available during database trigger execution ? Answer : The table columns are referred as OLD.k. If WHEN clause is specified. This condition is specified using the WHEN clause. After Row o. The trigger fires automatically when any of these events occur A trigger constraint specifies a Boolean expression that must be true for the trigger to fire.k. o. Before Statement o.k.k.NO_DATA_FOUND 6 .TOO_MANY_ROWS 2. o. For triggers related to DELETE only OLD. o. done using Integarity Constraints.k. then the trigger for each Row affected by the statement. The types are Predefined and user defined.k.column_name. CURSOR_ALREADY_OPEN DUP_VAL_ON_INDEX NO_DATA_FOUND TOO_MANY_ROWS INVALID_CURSOR INVALID_NUMBER LOGON_DENIED NOT_LOGGED_ON PROGRAM-ERROR STORAGE_ERROR TIMEOUT_ON_RESOURCE VALUE_ERROR ZERO_DIVIDE OTHERS. or delete statement or a instance shutdown or startup etc. o. o. Row level trigger. After Statement o. The trigger action is a procedure that contains the code to be executed when the trigger fires. update. we can use TCL commands in trigger by using autonomous transactions feature of oracle. If FOR EACH ROW clause is specified. For triggers related to INSERT only NEW. ii. Answer : I & ii.3.INVALID_CURSOR 3. As triggers are defined for each table. Exception : Question : What is an Exception ? What are types of Exception ? Ans: Exception is the error handling part of PL/SQL block. Question : Write the order of precedence for validation of a column in a table ? I.column_name NEW.k. Some of Predefined exceptions are.k.k. if you use COMMIT of ROLLBACK in a trigger. For triggers related to UPDATE only OLD.column_name and NEW.k.Userdefined exception predefind exceptions are 1.k.column_name values only available. done using Database triggers. Question : How many types of database triggers can be specified on a table ? What are they ? Insert Update Delete Before Row o. o. o. Trigger action A triggering event can be an insert. the trigger fires according to the returned Boolean value.column_name values only available.Statement level trigger.column_name values only available. o.k. it affects logical transaction processing.Instead of trigger(created on views) Question : Is it possible to use Transaction control Statements such a ROLLBACK or COMMIT in Database Trigger ? Why ? Answer : It is not possible. Exception is two types 1.Predefind exception 2. An exception is an identifier/error that is handle by pl/sql block. Question : 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.

To get an error message of a specific oracle error. Exception. In case of function. RAISE_APPLICATION_ERROR is a procedure of package DBMS which allows to issue user_defined error message..INOUT parameters.It can be invoked. Question : What is a stored procedure ? Answer : A stored procedure is a sequence of statements that perform specific function. Functions & Packages . A PROCEDURE may return one or more values through parameters or may not return at all. basically procedure has three parts 1. In case of procedure. Question : What are advantages fo Stored Procedures Answer : Extensibility.variable declaretion(optional) 2.Question : What is Pragma EXECPTION_INIT ? Explain the usage ? Answer : The PRAGMA EXECPTION_INIT tells the complier to associate an exception with an oracle error.Exception(optional) suppose ex CREATE OR REPLACEPROCEDURE emp_pro( p_id IN employees. e.g..IN-OUT parameters. In case of function.) is local variable declarations BEGIN Executable statements. parameterised and must have return type. question : Give the structure of the procedure ? PROCEDURE name (parameter list. Reusability. A stored procedure is a named pl/sql block which performs an action. Maintainability and one time compilation.OUT. oracle error number) The PRAGMA_EXCEPTION_INIT tells the compiler to assosiate an exception with an oracle error.employee_id%TYPE) 7 .body(mandetory) 3. Question : What are the return values of functions SQLCODE and SQLERRM ? Answer : SQLCODE returns the latest code of the error that has occurred. Question : What are the two parts of a procedure ? Ans: Procedure Specification and Procedure Body. Procedures.OUT. only it takes IN parameters IN case of procedure only it take IN. Question : What is difference between a PROCEDURE & FUNCTION ? Answer : A FUNCTION is always returns a value using the return statement. PRAGMA EXCEPTION_INIT (exception name. SQLERRM returns the relevant error message of the SQLCODE.. Question : What are the modes of parameters that can be passed to a procedure ? Answer : IN. A function can be called from sql statements and queries while procedure can be called in a begin end block only. Question : 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..It is stored in the database as a schema object and can be repeatedly executed. SQLCODE returns the latest code of the error that has occured.Modularity. SQLERRM returns relevant massege of the error code Question : Where the Pre_defined_exceptions are stored ? Answer : In the standard package.. exception handlers may or may n't have return type.

v_mail FROM employees WHERE employee_id:=p_id.arg2. BEGIN SELECT last_name. sal := calculate_sal ('a822'). v_mail employees. package has two parts 1.. 2.. INTO v_name..Package specification program code .... DBMS_OUTPUT. DBMS_OUTPUT put_line What is a package ? What are the advantages of packages ? Overloading of procedure name of the procedure is same but the number of parameters should be different. Package Body contains actual procedures and local declaration of the procedures and cursor declarations..In that case. return <variable> exception exception statement end. if the two rules are satisfied in that case procedure will be overloaded.Package body In the specification. varying number of parameters is called overloading of procedures.variable declaration(optional) 2.procedure will be overloaded.... Question : What are two parts of package ? Answer : The two parts of package are PACKAGE SPECIFICATION & PACKAGE BODY. 8 . create or replace function <name>(arg1..function. / Question : Give the structure of the function ? Structure of the fuction same as procedure it has three parts type should be different.last_name%TYPE.PUT_LINE('NAME:'||v_name ||'MAILID:'||v_mail).) return datatype as ..where we declare variable. Question : Explain how procedures and functions are called in a PL/SQL block ? Function is called as part of an expression.function body(mandetory) 3. variable declaration begin .. e.Exception part(optional) FUNCTION name (argument list . procedure is called as a PL/SQL statement calculate_bonus ('A822'). Package Specification contains declarations that are global to the packages and local to the schema.. if the number of parameters are same in that case.procedure that is global to the package and local to the schema.IS v_name employees.) Return datatype is local variable declarations Begin executable statements Exception execution handlers End. Question : What is Overloading of procedures ? The Same procedure name is repeated with parameters of different datatypes and parameters in different positions.g.

PROCEDURE NAME (parameters) variable := PACKAGE NAME. PRO* COBOL c. Question : What is difference between a Cursor declared in a procedure and Cursor declared in a package specification ? A cursor declare in the package specification that can be accessed in the other procedure or procedures of the package. procedure and functions are stored ? User_objects.we can also declare private function and procedure which is not accessble out side the package.FUNCTION NAME (arguments). SQL *PLUS Answer : a. variable := PACKAGE NAME.Answer : A cursor declared in a package specification is global and can be accessed by other procedures or procedures in a package. EXECUTE PACKAGE NAME.package body contains the defination of the function.PROCEDURE NAME (parameters). A function can not be called. A cursor declared in a procedure is local to the procedure that can not be accessed by other procedures. BEGIN PACKAGE NAME. c. END EXEC.PROCEDURE if the procedures does not have any out/in-out parameters. Stored procedure or anonymous block b. Question : Answer : Name the tables where characteristics of Package. PACKAGE NAME. A cursor declare in the procedure that can't be accessed by other procedure.procedure. One more differene is cursor declared in a package specification must have RETURN type Question : How packaged procedures and functions are called from the following? a. an application program such a PRC *C. User_Source and User_error.FUNCTION NAME (arguments). EXEC SQL EXECUTE b. END. 9 .

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer: Get 4 months of Scribd and The New York Times for just $1.87 per week!

Master Your Semester with a Special Offer from Scribd & The New York Times