Professional Documents
Culture Documents
Page 1 of 5
A FUNCTION is always returns a value using the return statement. A PROCEDURE may return one or more values through parameters or may not return at all.
A function can be called from sql statements and queries while procedure can be called in a begin end block only.
Contact Jyoti
In case of function,it must have return type. In case of procedure,it may or may n't have return type. In case of function, only it takes IN parameters IN case of procedure only it take IN,OUT,INOUT parameters..
A function always return a values while procedure can return one or more values through Parameters. A function can call directly by sql statement like select func_name from dual while procedure cannot.
Contact Madhavi
A FUNCTION always returns a value using the return statement. And a FUNCTION can also use OUT parameter to return a value. But Return statment must be there. A PROCEDURE may return one or more values through parameters or may not return at all. A function can be called from sql stmt and pl/sql stmt. A procedure can be called within pl/sql stmt.
3/6/2010
Page 2 of 5
In case of function,it must have return type. In case of procedure, it don't need return keyword.
Functions and Procedures both can return values using OUT parameter. But Functions has return clause to return value and Procedures does not have return statement. Functions can be used in the sql statement and can be used as the part of the expression but Procedures can't be used.
Function can have both IN and OUT parameter. Procedure cannot have return type but may return value through OUT parameter.
FUNCTION: -It must have return type. -It mainly used for calculation purpose. -It is part of PL/SQL block.(that is return value to block for exection of remaining code) PROCEDURE: -It may or may not return value. -It is mainly to perform a task. -It is a complete PL/SQL block. -It is used to perform DML operation.
3/6/2010
Page 3 of 5
Contact Bharadwaj
procedure is called as part of a statement..function is called as part of an expression. There are some purity level for a function..procedure dont have such restrictions.
Contact Bikash
We use function when we wnt to compute or calculate , where as procedure use for an action
Difference Between Function and Procedure 1.Function get terminated if error occure while Procedure continue. 2. Function compiled every time on calling but Procedure compiled one time and stored in compiled format for furthur use.
1) Function has to Return One Value. Howecer procedure may or may not return any values.we can return the values via procedure using OUT/IN OUT varaibles. 2)Unlike Procedures We can call function in a Select statement. Exception being we can't use those functions in select which has OUT varaibles. 3) We can call functions during declaration itself. e.g declare x number := func(); ---that is all i know.
3/6/2010
Page 4 of 5
Functions Compute some value Should return a value It must return only one value Not possible to use OUT and IN OUT parameters, only IN parameter is allowed. We can able to call functions in SELECT statement
Contact priya
Functions Compute some value Should return a value It must return only one value Not possible to use OUT and IN OUT parameters, only IN parameter is allowed. We can able to call functions in SELECT statement Procedures Do some actions May return a value or may not Possible to return more than one value Possible to use IN, OUT and IN OUT parameters We cannot able to call in SELECT statement
Contact priya
3/6/2010
Page 5 of 5
function is a collection of sql and plsql statments in function we can assign the return type dataype in procedure we can not assign the return type datatype with using function we can return only one output. wih using procedure we can return multiple output using parameters. in function whenever declaring a variable it's type of in parameter in procedure variable type is in inout out
Contact abhay
Procedures: 1. Execute as a PL/SQL statement. 2. Do not contain RETURN clause in the header. 3. Can return none, one, or many values. 4. Can contain a RETURN statement. Function: 1. Invoke as part of an expression 2. Must contain a RETURN clause in the header 3. Must return a single value 4. Must contain at least one RETURN
3/6/2010
What is Raise_application_error ?
Page 1 of 2
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.
RAISE_APPLICATION_ERROR is a procedure of package DBMS which allows to issue user_defined error message.
The RAISE_APPLICATION_ERROR is a procedure defined by Oracle that allows the developer to raise an exception and associate an error number and message with the procedure other than just Oracle errors.
It is Its a STANDARD procedure to communicate with a pre defined exception interactively by returning a nonstandard error code and error message. error_number : between -20000 to -20999 message : 2048 bytes This can be used in both execution and exception setion; Ex: 1 : ..... BEGIN ... delete from employees where manager_id = v_mgr; if SQL%NOTFOUND then RAISE_APPLICATION_ERROR(-20020,'This is not a valid manager'); end if; .... --------------------------ex:2 : ...... EXCEPTION when NO_DATA_FOUND then
3/6/2010
What is Raise_application_error ?
Page 2 of 2
3/6/2010
Name the tables where characteristics of Package, procedure and functions are stored ?
Page 1 of 1
user_source,user_objects
Contact madhavi
characteristics of DB objects are stored in data dictionary. Which can be accessed by Data dict. views like (user/all/DBA_objects/source).
Contact pankaj
user_source,user_objects
Contact suvrat
3/6/2010
What is difference between stored procedures and application procedures,stored function ... Page 1 of 2
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
Stored Procedure/Function is a compiled database object, which is used for fast response from Oracle Engine.Difference is Stored Procedure must return multiple value and function must return single value .
Procedure:Execute as a PL/SQL statement,No RETURN clause in the header,Can return none, one, or many values,Can contain a RETURN statement Function:-Invoke as part of an expression,Must contain a RETURN clause in the header,Must return a single value,Must contain at least one RETURN statement
Contact Dev
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 Stored Procedure/Function is a compiled database object, which is used for fast response from Oracle Engine.Difference is Stored Procedure must return multiple value and function must return single value .
Contact kiran
The basic difference between function and procedure is that a procedure can never be used in a sql statement while a function can be used
3/6/2010
What is difference between stored procedures and application procedures,stored function ... Page 2 of 2
Contact paritosh
Difference between Stored Procedure and Application Procedure: Stored Procedure is a named PLSQL block that will be compiled and used for further use. If maintained across Servers, they can be used for different applications and Users. Application Procedures are the one which will be used for local apps, this can be called local block of code. Apart from technical characteristics, same will apply to the differences between Stored Functions and Application Functions. Difference between Procedures and Functions: a. Functions can be used in a select statement where as procedures cannot b. Procedure takes both input and output parameters but Functions takes only input parameters c. Functions cannot return values of type text, ntext, image & timestamps where as procedures can d. Functions can be used as user defined datatypes in create table but procedures cannot ***Eg:-create table <tablename>(name varchar(10),salary getsal(name)) Here getsal is a user defined function which returns a salary type, when table is created no storage is allotted for salary type, and getsal function is also not executed, But when we are fetching some values from this table, getsal function get?s executed and the return Type is returned as the result set.
3/6/2010
Page 1 of 2
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.
Contact Dinesh
It is not mandatory that when the query retrieves more than one record then explicit cursor should be used. If the number of records is less than 100 then implicit cursor should be used. e.g. set serverout on; begin for i in (select * from emp) loop dbms_output.put_line(i.empno); end loop; end; /
Contact Sukhamoy
Cursor: It is automatically created by oracle for all sql dml statements including the query that returns one row. Explicit cursor: These are created and managed by the user.And used for multi row select statement.
Contact josu
Implicit cursors are oracle created and used internally by oracle,the only implicit cursor is sql.
3/6/2010
Page 2 of 2
Contact Ashish
Cursors are used for the purpose of storing the intermediate results when executing a SQL Query or a block of code... Implicit Cursors are by default declared by ORacle itself and hence there is no scope of storing resultset with more than one record where as Explicit Cursors are declared by the User and hence can define the parameters with measure to store the no of records.
3/6/2010
How we can create a table in PL/SQL block. insert records into it??? is it possible by som... Page 1 of 2
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;
We can create table in procedure as explained in above case. but we can't create or perform any DDL in functions.
the above given answer is correct. but we can also create or perform any ddl in functions. I have tested myself
Contact Mike
we can create a table through pl/sql block with dbms_sql package and execute immediate statement. CREATE OR REPLACE PROCEDURE PROC_CREATE_NEW_TABLE(STMT VARCHAR2) IS
3/6/2010
How we can create a table in PL/SQL block. insert records into it??? is it possible by som... Page 2 of 2
AUTHID CURRENT_USER BEGIN EXECUTE IMMEDIATE STMT; END; here AUTHID CURRENT_USER is used to create a table under current user privileges. through this procedure we can add our own fields of a table on run time,even it is not depended on structure of an existing table. Insertion record into the table, because it is DML operation so we can easily create a procedure with simple statements or execute immediate statement.
3/6/2010
Page 1 of 3
WHERE CURRENT OF clause in an UPDATE,DELETE statement refers to the latest row fetched from a cursor. Database Triggers
Where CURRENT OF clause means cursor points to present row of the cursor
WHERE CURRENT OF clause in an UPDATE,DELETE statement refers to the latest row fetched from a cursor.
Contact Alagappan A M
This clause use for update & delete most resent row with out help of ROWID and befour update lock the particular row in the base table.FOR UPDATE clause is manditory for this clause.
Take an example, Cursor is Select * from EMP; and in cursor we write Update Emp set sal = sal + 100; that means the fetching loops will execute as many times as rows returned by the cursor and the update will also be done for the same number of times. Now suppose, If we put a where clause in the update statement, then the result would also not be predictable. In the third case, we use the WHERE CURRENT OF clause in the where clause, this point out to the current row returned by the cursor. In that case, Oracle differentiate all the rows on the basis of RowID. But what happens if someone changes one row in the table.....that means the rowid would be changed. So we have to manually lock all the rows of that table by writing the FOR UPDATE/DELETE clause. So In case of WHERE CURRENT OF clause, we should use the FOR UPDATE/DELETE clause
3/6/2010
Page 2 of 3
also. This is known as the Pessimistic/Manual Locking and this the major difference between the Implicit Cursors and Explicit Cursors.
UPDATE and DELETE statements can use a WHERE CURRENT OF clause if they reference a cursor declared FOR UPDATE. This syntax indicates that the UPDATE or DELETE should modify the current row identified by the FOR UPDATE cursor. The syntax is: [UPDATE | DELETE ] ... WHERE CURRENT OF cursor_name;By using WHERE CURRENT OF, you do not have to repeat the WHERE clause in the SELECT statement. For example: DECLARE CURSOR wip_cur IS SELECT acct_no, enter_date FROM wip WHERE enter_date < SYSDATE -7 FOR UPDATE; BEGIN FOR wip_rec IN wip_cur LOOP INSERT INTO acct_log (acct_no, order_date) VALUES (wip_rec.acct_no, wip_rec.enter_ date); DELETE FROM wip WHERE CURRENT OF wip_cur; END LOOP; END;
If your program has positioned the cussor on a row,u can update its data by using update statemnet with where current clause.
Contact priya
Where current of is used to delete or update the current row that is being processed in the cursor loop.
3/6/2010
Page 3 of 3
WHERE CURRENT OF CLAUSE is used when referencing the current row from an explicit cursor. this clause allows to apply updates and deletes to the row currently being addressed,without the need to explicitly reference ROWID. We must use the FOR UPDATE clause in the cursor query, such thay the rows are locked on open.
3/6/2010
Page 1 of 1
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
ROWID : It gives the hexadecimal string representing the address of a row. It gives the location in database where row is physically stored. ROWNUM: It gives a sequence number in which rows are retrieved from the database.
Contact jyothsna
ROWID : Every record in a database is uniquely identified by system generated value called Rowid. It Is a 18 character hexma decimal value. These Rowid's are physically existence. ROWNUM : It is a pseduocolumn which generates the sequence of numeric values based on the position of the records in the output. These ROWNUM'S logically generated. NEXTVAL,CURRVAL,SYSDATE,LEVEL ARE PSEDUOCOLUMNS
3/6/2010
Page 1 of 2
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.
Disadvantage: Each time we fetch a row from the cursor, it result a network round trip, where as a normal select statement query make only one round trip.
The guy's answer at the top of this page about "Cursors" is probably not wrong but sounds wrong and it is hard to understand, it sounds like he has tried to type the answer in english but it is shameful, his english is totally broken, it is bad. You guys at coolinterview.com should do something about such posting to keep up the readership.
Advantage of cursor 1.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 don't need hit the database several time. Cursor always points the latest rows. Disadvantage of cursor 1.As such there is no disadvantage of cursor.
3/6/2010
Page 2 of 2
Advantages: Cursors are somewhat like Pointers of Oracle, Oracle executes a query and assign some name to that memory location, which is known as Cursor. Cursors are used for storing data temperarorily. Cursors are used for storing, managing and retrieving data. Cursors stores in the RAM so the data access and retrieval is fast. Disadvantage: No such disadvantage. Only thing is that rather than storing data in an intermediate variable and fetching it one by one via cursor and then processing it sequentially, we can use Collections. By using collections, we can pass the bundle of Data at once.
Cursors adv: easier to retrieve a batch of records into the cursor and then perform manipulations on them before displaying the results. Disadvantage: The biggest disadvantage of cursors is that they eat up you RAM. If you're retrieving a large number of records into your cursor inside a procedure on an OLAP database, it will take a long long time to execute that procedure. The better alternative would be to retrieve directly from one or more table using selection criteria to eliminate records, and perform manipulation on each record on the fly.
cursor is nothing but it's a memory area of executing sql or oracle statements. Advantage: 1. We can retrieve more than one record by one query. 2. It's use our RAM so retrieval is fast. 3. By using Collection we can retrieve the bundle of data in cursor. Disadvantage: No such of disadvantage of cursor. When we use cursor one thing is necessary. When I have select only 50 or 100 rows we should use implicit cursor and when more record then we should use Explicit cursor.
3/6/2010
How many types of database triggers can be specified on a table ? What are they ?
Page 1 of 1
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. If WHEN clause is specified, the trigger fires according to the returned Boolean value.
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 TRIGGER 4. 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
3/6/2010
Page 1 of 1
Currently, cursor variables are subject to the following restrictions:You cannot declare cursor variables 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 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 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 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 is expected. For example, you cannot reference a cursor variable in a cursor FOR loop
u cannot declare cursor in package specification not allowed when using db links cannot use comparison operators cannot assign NULL cursor's values cannot be stored in table columns cannot be used with associative array, nested tables and varray cannot be use one where the other is expected cannot reference a cursor variable in cursor FOR LOOP cannot direclty goto any columns
Posted by: NA
Contact NA
3/6/2010
Can Commit,Rollback ,Savepoint be used in Database Triggers?If yes than HOW? If no ...
Page 1 of 1
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.
As workaround, one can use autonomous transactions. Autonomous transactions execute separate from the current transaction. Unlike regular triggers, autonomous triggers can contain COMMIT and ROLLBACK statements
Contact Jobs
Having Commit / Rollback inside a trigger defeats the standard of whole transaction's commit / rollback al together. Once trigger execution is complete then only a transaction can be said as complete and then only commit should take place. If we still want to carry out some action which should be initiated from trigger but should be commited irrespective of trigger completion / failure we can have AUTONOMUS TRANSACTION. Inside Automomus transaction block we can have Commit and it will act as actual commit. Specific queries a most welcome. D.
Contact Durgesh
We can't perform two action at a time in a trigger i.e trigger action and coomit/rollback/save point.Otherwise deadlock situation occur as a result we will get a error in the transaction.
3/6/2010
Page 1 of 3
Trigger is an event driven PL/SQL block. Event may be any DML transaction.
database,
Cursor is a stored select statement for that current session. It will not be stored in the 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.
Contact Girish P
Cursor cursor is a private sql work area. Every sql statement executed by oracle server has an individual cursor associated with it. Cursor are two types 1.Implicit cursor 2.Explicit cursor Implicit cursor: Implicit cursors are declared by pl/sql implicitly at the time of DML statement and select statement in pl/sql including queries that returns single row. cursor have four attributes 1. SQL%ROWCOUNT 2. SQL%ISOPEN 3. SQL%NOTFOUND 4. SQL%FOUND SQL%ROWCOUNT-Basically it returns number. means number of rows affected by present sql statement. SQL%ISOPEN-Always evalutes false because implicit cursor automatically closed after execution of sql statement. SQL%FOUND-Always evalutes true because one or more rows are affected by recent sql statement SQL%NOTFOUND-Always evalutes true when no rows are affected by present sql statement. example of explicit cursor DECLARE v_empno employees.employee_id%TYPE; v_name employees.last_name%TYPE; CURSOR emp_cur IS SELECT employee_id,last_name FROM employees BEGIN OPEN emp_cur; LOOP
3/6/2010
Page 2 of 3
FETCH emp_cur INTO v_empno,v_name ; EXIT WHEN emp_cur%ROWCOUNT>10 OR emp_cur%NOTFOUND; DBMS_OUTPUT.PUT_LINE('employee_id:'||TO_CHAR(v_empno) 'employee_name:'||'v_name'); END LOOP; CLOSE emp_cur; END; Trigger:-Trigger is pl/sql block or procedure that is associated with table,view,schema and database. Execute immidiately when particular event take place. there are two types of trigger 1.Application trigger:fires automatically when event occurs with particular application. 2.Database trigger:Fires when data such as DML oparation occured at that time. DML triggers are two types 1.Statementlevel trigger 2.Rowlevel trigger statement level trigger-statement level trigger means trigger body execute once for the triggering event.this is default.A statement level trigger fire once even no rows are affected at all. Row level- Trigger body execute once for each row affected by triggering event.if no rows are affected in that case trigger body not executed. trigger example CREATE OR REPLACE TRIGGER secure_emp BEFORE INSERT ON employees BEGIN TO_CHAR(SYSDATE,'DY')IN('SUN','SAT') OR TO_CHAR((SYSDATE,'HH24:MI')NOT BETWEEN '08:00' AND '18:00')THEN RAISE_APPLICATION_ERROR(-20253,'u may insert employee information at business hrs'); END; ||
Cursor: cursor is temporary work area in pl/sql. Type of cusor: 1.Implict Cursor 2.Explicit Cursor 3.Cursor for loop 4.Cursor With Parametter
3/6/2010
Page 3 of 3
5.Cursor for Update 6.Ref Cursor Curosr Attributes: %foud %notfound %rowCount %isopen Trigger: Trigger is asscoiated with table or database event(when a table affect like dml operation that time occurs fire) Types of Trigger: we can write 12 types trigger
Contact raja
Trigger is a stored procedure that invokes automatically when the event occurs. We can write 12 types of triggers on table and 15 types of triggers on views. Cursor pointer or handler to the context area . 2 types of cursors are there implicit and explicit cursors.
3/6/2010
Page 1 of 3
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.
Contact Girish P
Cursor cursor is a private sql work area. Every sql statement executed by oracle server has an individual cursor associated with it. Cursor are two types 1.Implicit cursor 2.Explicit cursor Implicit cursor: Implicit cursors are declared by pl/sql implicitly at the time of DML statement and select statement in pl/sql including queries that returns single row. cursor have four attributes 1. SQL%ROWCOUNT 2. SQL%ISOPEN 3. SQL%NOTFOUND 4. SQL%FOUND SQL%ROWCOUNT-Basically it returns number. means number of rows affected by present sql statement. SQL%ISOPEN-Always evalutes false because implicit cursor automatically closed after execution of sql statement. SQL%FOUND-Always evalutes true because one or more rows are affected by recent sql statement SQL%NOTFOUND-Always evalutes true when no rows are affected by present sql statement. example of explicit cursor DECLARE v_empno employees.employee_id%TYPE; v_name employees.last_name%TYPE; CURSOR emp_cur IS SELECT employee_id,last_name FROM employees BEGIN OPEN emp_cur; LOOP
3/6/2010
Page 2 of 3
FETCH emp_cur INTO v_empno,v_name ; EXIT WHEN emp_cur%ROWCOUNT>10 OR emp_cur%NOTFOUND; DBMS_OUTPUT.PUT_LINE('employee_id:'||TO_CHAR(v_empno) 'employee_name:'||'v_name'); END LOOP; CLOSE emp_cur; END; Trigger:-Trigger is pl/sql block or procedure that is associated with table,view,schema and database. Execute immidiately when particular event take place. there are two types of trigger 1.Application trigger:fires automatically when event occurs with particular application. 2.Database trigger:Fires when data such as DML oparation occured at that time. DML triggers are two types 1.Statementlevel trigger 2.Rowlevel trigger statement level trigger-statement level trigger means trigger body execute once for the triggering event.this is default.A statement level trigger fire once even no rows are affected at all. Row level- Trigger body execute once for each row affected by triggering event.if no rows are affected in that case trigger body not executed. trigger example CREATE OR REPLACE TRIGGER secure_emp BEFORE INSERT ON employees BEGIN TO_CHAR(SYSDATE,'DY')IN('SUN','SAT') OR TO_CHAR((SYSDATE,'HH24:MI')NOT BETWEEN '08:00' AND '18:00')THEN RAISE_APPLICATION_ERROR(-20253,'u may insert employee information at business hrs'); END; ||
Cursor: cursor is temporary work area in pl/sql. Type of cusor: 1.Implict Cursor 2.Explicit Cursor 3.Cursor for loop 4.Cursor With Parametter
3/6/2010
Page 3 of 3
5.Cursor for Update 6.Ref Cursor Curosr Attributes: %foud %notfound %rowCount %isopen Trigger: Trigger is asscoiated with table or database event(when a table affect like dml operation that time occurs fire) Types of Trigger: we can write 12 types trigger
Contact raja
Trigger is a stored procedure that invokes automatically when the event occurs. We can write 12 types of triggers on table and 15 types of triggers on views. Cursor pointer or handler to the context area . 2 types of cursors are there implicit and explicit cursors.
3/6/2010
What are two virtual tables available during database trigger execution ?
Page 1 of 1
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. UPDATE TRIGGER OLD- old value. NEW- new updated value. DELETE TRIGGER OLD - old value. NEW - no value.
3/6/2010
Page 1 of 2
In PL/SQL ,pointer has a datatype REF X where REF-Reference X-class of objects Cursor Variables has a datatype REF-CURSOR where Cursor Varibales are like pointers which hold the memory location of some item instead of the item itself.
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.
Contact Sukhamoy
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.
Contact Rup
Ref cursors are used when we want to use the cursor which is not bound to a specific query. Cursor variables can be tied to many such type of compatible queries.
Contact Jyothsna
Ref cursor is user defined type.Ref cursor allows any type of query for the cursor.Ref cursor is a global declaration of the cursor.Ref cursor is re-usable. Ref cursor reduces the number of declarations of the cursor in the entire plsql program.Ref cursor is either static or dynamic.
3/6/2010
Page 2 of 2
Contact jaali
Ref cursor is a cursor variable is used to pass the result sets between sub programs. Ref cursors are 2 types 1.weak Ref cursor and 2. Strong Ref cursor If a ref cursor should not return any value then it is called as weak ref cursor and if a cursor returns the value then it is strong ref cursor. weak ref cursors are more flexible because you can associate a weakly typed cursor varible to any query
Contact Aruna
Ref cursor is a dynamic cursor with which we can change our query contents at run time. once it is defined thereafter we can declare a cursor variable of that(ref cursor) data type and write any number of type compatible query against this cursor variable.
3/6/2010
Page 1 of 1
% 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 cursor c1 is select empno,deptno from emp; e_rec c1 %ROWTYPE.
3/6/2010
Page 1 of 2
put a dbms output_putline statment which will dislapay that your procedure is executing successfully up to which stage.
Contact sanjay
By using the sql developer tools and in that use breakpoints (the location from which u want to debug and execute line by line at the same time you will notice the current value of the executed statement below in another windows) and don't forgot to enable the dbms_output ). In this way you can do the same things
We can also do line by line execution using tools such as Pl/ SQL Developer, Toad etc
if you want to tune a package then you can use dbms_profiler. if you want to debug use dbms_debug procedure. Thanks, Sudipta
Contact Sudipta
3/6/2010
Page 2 of 2
3/6/2010
What will the Output for this Coding? Declare Cursor c1 is select * from emp FORUPDA... Page 1 of 3
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".
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).
Contact Ash
You will get an error. Since, the commit/rollback closes the cursor and release the lock if you use for update of, so trying to fetch out of a closed cursor will raise an error.
Contact Nattu
The procedure executes successfully.COMMIT will not close the cursor. declare b boolean; cursor c is select * from emp for update; rec c%rowtype; begin open c; fetch c into rec; dbms_output.put_line('NAME is'||rec.ename); commit; if c%isopen then dbms_output.put_line('Cursor is not closed '||c%rowcount); end if; fetch c into rec; dbms_output.put_line('NAME is'||rec.ename); end; O/P **** NAME isSMITH Cursor is not closed 1 NAME isALLEN
3/6/2010
What will the Output for this Coding? Declare Cursor c1 is select * from emp FORUPDA... Page 2 of 3
Contact Srikri
This coding get sucessful but after completed this query we con't delete or update to the EMP table because of we used FOR UPDATE clause, they explictly locked the entire row still not relese.
The cursor will execute for first record and then for second record it will raise exception. Because the ROWS which were locked by FOR UPDATE clause, now been released by commit.
The following error will occur as there is a space between IN TO. ERROR at line 8: ORA-06550: line 8, column 11: PLS-00103: Encountered the symbol "IN" when expecting one of the following: . into bulk
Contact Chella
It will ORA:01002 fetch out of sequence error If the cursor has been opened with the FOR UPDATE clause, fetching after a COMMIT will return the error.
Contact kalam
3/6/2010
What will the Output for this Coding? Declare Cursor c1 is select * from emp FORUPDA... Page 3 of 3
If the table which we are using in the cursor is empty then procedure will run successfully. But if table contains rows in it, it will give error as " fetch out of sequence"
3/6/2010
Page 1 of 1
Function is called as part of an expression. sal := calculate_sal ('a822'); procedure is called as a PL/ SQL statement calculate_bonus ('A822');
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
Contact Hirenkumar
Function: Example Select get_name(Emp_id) from dual. Procedure: Example Begin Process_employee(EMP_ID); end;
3/6/2010
Page 1 of 1
It stores in standard_package.
3/6/2010