SlideShare a Scribd company logo
Declaring an Autonomous Function in a Package
Example 6-43 Declaring an Autonomous Function in a Package
CREATE OR REPLACE PACKAGE emp_actions AS -- package specification
FUNCTION raise_salary (emp_id NUMBER, sal_raise NUMBER) RETURN NUMBER;
END emp_actions;
/
CREATE OR REPLACE PACKAGE BODY emp_actions AS -- package body
-- code for function raise_salary
FUNCTION raise_salary (emp_id NUMBER, sal_raise NUMBER) RETURN NUMBER IS
PRAGMA AUTONOMOUS_TRANSACTION;
new_sal NUMBER(8,2);
BEGIN
UPDATE employees SET salary = salary + sal_raise WHERE employee_id = emp_id;
COMMIT;
SELECT salary INTO new_sal FROM employees WHERE employee_id = emp_id;
RETURN new_sal;
END raise_salary;
END emp_actions;
/
Create GLOBAL TEMPORARY Table.
CREATE GLOBAL TEMPORARY TABLE admin_work_area
(startdate DATE,
enddate DATE,
class CHAR(20))
ON COMMIT DELETE ROWS;
Posted by Asif at 8:30 PM
CREATE TRIGGER Statement
Using Triggers:Example 9-1 CREATE TRIGGER Statement
CREATE OR REPLACE TRIGGER Print_salary_changes
BEFORE DELETE OR INSERT OR UPDATE ON emp
FOR EACH ROW
WHEN (NEW.EMPNO > 0)
DECLARE
sal_diff number;
BEGIN
sal_diff := :NEW.SAL - :OLD.SAL;
dbms_output.put('Old salary: ' || :OLD.sal);
dbms_output.put(' New salary: ' || :NEW.sal);
dbms_output.put_line(' Difference ' || sal_diff);
END;
/
CREATE TRIGGER -Calling a Procedure in a Trigger Body:
CREATE TRIGGER: Calling a Procedure in a Trigger Body: Example You could create
the salary_check trigger described in the preceding example by calling a procedure instead of providing
the trigger body in a PL/SQL block. Assume you have defined a procedure check_sal in the hr schema,
which verifies that an employee's salary is in an appropriate range. Then you could create the
trigger salary_check as follows:
CREATE TRIGGER salary_check
BEFORE INSERT OR UPDATE OF salary, job_id ON employees
FOR EACH ROW
WHEN (new.job_id <> 'AD_VP')
CALL check_sal(:new.job_id, :new.salary, :new.last_name)
Posted by Asif at 4:34 AM
Hierarchical Level Query Example using SYS_CONNECT_BY_PATH
SYS_CONNECT_BY_PATH: is valid only in hierarchical queries. It returns the path of a column value
from root to node, with column values separated by char for each row returned
by CONNECT BY condition.
Both column and char can be any of the datatypes CHAR, VARCHAR2, NCHAR, or NVARCHAR2.
The string returned is of VARCHAR2 datatype and is in the same character set as column.
Examples
The following example returns the path of employee names from employee Kochhar to
all employees of Kochhar (and their employees):
SELECT LPAD(' ', 2*level-1)||SYS_CONNECT_BY_PATH(last_name, '/') "Path"
FROM employees
START WITH last_name = 'Kochhar'
CONNECT BY PRIOR employee_id = manager_id;
Path
---------------------------------------------------------------
/Kochhar
/Kochhar/Greenberg
/Kochhar/Greenberg/Faviet
/Kochhar/Greenberg/Chen
/Kochhar/Greenberg/Sciarra
/Kochhar/Greenberg/Urman
/Kochhar/Greenberg/Popp
/Kochhar/Whalen
/Kochhar/Mavris
/Kochhar/Baer
/Kochhar/Higgins
/Kochhar/Higgins/Gietz
Hierarchical Queries -CONNECT_BY_ROOT Examples
Hierarchical Queries: CONNECT_BY_ROOT Examples The following example returns the last name
of each employee in department 110, each manager above that employee in the hierarchy, the number
of levels between manager and employee, and the path between the two:
SELECT last_name "Employee", CONNECT_BY_ROOT last_name "Manager",
LEVEL-1 "Pathlen", SYS_CONNECT_BY_PATH(last_name, '/') "Path"
FROM employees
WHERE LEVEL > 1 and department_id = 110
CONNECT BY PRIOR employee_id = manager_id;
Employee Manager Pathlen Path
--------------- ------------ ---------- -----------------------------------
Higgins Kochhar 1 /Kochhar/Higgins
Gietz Kochhar 2 /Kochhar/Higgins/Gietz
Gietz Higgins 1 /Higgins/Gietz
Higgins King 2 /King/Kochhar/Higgins
Gietz King 3 /King/Kochhar/Higgins/Gietz
Avoiding Collection Exceptions
Avoiding Collection Exceptions
In most cases, if you reference a nonexistent collection element, PL/SQL raises a predefined
exception. Consider the following example:
DECLARE
TYPE NumList IS TABLE OF NUMBER;
nums NumList; -- atomically null
BEGIN
/* Assume execution continues despite the raised exceptions. */
nums(1) := 1; -- raises COLLECTION_IS_NULL (1)
nums := NumList(1,2); -- initialize table
nums(NULL) := 3 -- raises VALUE_ERROR (2)
nums(0) := 3; -- raises SUBSCRIPT_OUTSIDE_LIMIT (3)
nums(3) := 3; -- raises SUBSCRIPT_BEYOND_COUNT (4)
nums.DELETE(1); -- delete element 1
IF nums(1) = 1 THEN ... -- raises NO_DATA_FOUND (5)
In the first case, the nested table is atomically null. In the second case, the subscript is null. In
the third case, the subscript is outside the legal range. In the fourth case, the subscript exceeds
the number of elements in the table. In the fifth case, the subscript designates a deleted
element.
The following list shows when a given exception is raised:
Collection Exception Raised when...
COLLECTION_IS_NULL
you try to operate on an atomically null collection.
NO_DATA_FOUND
a subscript designates an element that was deleted, or a nonexistent element of an associative
array.
SUBSCRIPT_BEYOND_COUNT
a subscript exceeds the number of elements in a collection.
SUBSCRIPT_OUTSIDE_LIMIT
a subscript is outside the allowed range.
VALUE_ERROR
a subscript is null or not convertible to the key type. This exception might occur if the key is
defined as a PLS_INTEGER range, and the subscript is outside this range.
In some cases, you can pass invalid subscripts to a method without raising an exception. For
instance, when you pass a null subscript to procedure DELETE, it does nothing. Also, you can
replace deleted elements without raising NO_DATA_FOUND, as the following example shows:
DECLARE
TYPE NumList IS TABLE OF NUMBER;
nums NumList := NumList(10,20,30); -- initialize table
BEGIN
nums.DELETE(-1); -- does not raise SUBSCRIPT_OUTSIDE_LIMIT
nums.DELETE(3); -- delete 3rd element
dbms_output.put_line(nums.COUNT); -- prints 2
nums(3) := 30; -- allowed; does not raise NO_DATA_FOUND
dbms_output.put_line(nums.COUNT); -- prints 3
END;
Posted by Asif at 1:28 AM
ORACLE-BASE - Using Ref Cursors To Return Recordsets
Using Ref Cursors To Return Recordsets
The Reference Cursor which is also called the Cursor Variables is available since Oracle 7.3 the REF
CURSOR type has been available to allow recordsets to be returned from stored procedures and functions.
Oracle 9i introduced the predefined SYS_REFCURSOR type, meaning we no longer have to define our
own REF CURSOR types. The example below uses a ref cursor to return a subset of the records in
the EMP table.
The following procedure opens a query using a SYS_REFCURSOR output parameter. Notice the cursor is
not closed in the procedure. It is up to the calling code to manage the cursor once it has been opened.
CREATE OR REPLACE
PROCEDURE get_emp_rs (p_deptno IN emp.deptno%TYPE,
p_recordset OUT SYS_REFCURSOR) AS
BEGIN
OPEN p_recordset FOR
SELECT ename,
empno,
deptno
FROM emp
WHERE deptno = p_deptno
ORDER BY ename;
END GetEmpRS;
/
The resulting cursor can be referenced from PL/SQL as follows.
SET SERVEROUTPUT ON SIZE 1000000
DECLARE
l_cursor SYS_REFCURSOR;
l_ename emp.ename%TYPE;
l_empno emp.empno%TYPE;
l_deptno emp.deptno%TYPE;
BEGIN
get_emp_rs (p_deptno => 30,
p_recordset => l_cursor);
LOOP
FETCH l_cursor
INTO l_ename, l_empno, l_deptno;
EXIT WHEN l_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(l_ename || ' | ' || l_empno || ' | ' || l_deptno);
END LOOP;
CLOSE l_cursor;
END;
/
Posted by
Oracle PL/SQL - Raise User-Defined Exception With Custom SQLERRM -
Stack Overflow
User defined Exception with Naming and assigning the Error Code no.
1 declare
2 ex_custom EXCEPTION;
3 PRAGMA EXCEPTION_INIT( ex_custom, -20001 );
4 begin
5 raise_application_error( -20001, 'This is a custom error' );
6 exception
7 when ex_custom
8 then
9 dbms_output.put_line( sqlerrm );
10* end;
SQL> /
ORA-20001: This is a custom error
PL/SQL procedure successfully completed.
Compound Triggers , Avoid Mutating-Table Error
Using Compound Triggers to Avoid Mutating-Table Error
You can use compound triggers to avoid the mutating-table error (ORA-04091) described in Trigger
Restrictions on Mutating Tables.
Scenario: A business rule states that an employee's salary increase must not exceed 10% of the
average salary for the employee's department. This rule must be enforced by a trigger.
Solution: Define a compound trigger on updates of the table hr.employees, as in Example 9-4. The
state variables are initialized each time the trigger fires (even when the triggering statement is
interrupted and restarted).
Example 9-4 Compound Trigger that Avoids Mutating-Table Error
CREATE OR REPLACE TRIGGER Check_Employee_Salary_Raise
FOR UPDATE OF Salary ON Employees
COMPOUND TRIGGER
Ten_Percent CONSTANT NUMBER := 0.1;
TYPE Salaries_t IS TABLE OF Employees.Salary%TYPE;
Avg_Salaries Salaries_t;
TYPE Department_IDs_t IS TABLE OF Employees.Department_ID%TYPE;
Department_IDs Department_IDs_t;
TYPE Department_Salaries_t IS TABLE OF Employees.Salary%TYPE
INDEX BY VARCHAR2(80);
Department_Avg_Salaries Department_Salaries_t;
BEFORE STATEMENT IS
BEGIN
SELECT AVG(e.Salary), NVL(e.Department_ID, -1)
BULK COLLECT INTO Avg_Salaries, Department_IDs
FROM Employees e
GROUP BY e.Department_ID;
FOR j IN 1..Department_IDs.COUNT() LOOP
Department_Avg_Salaries(Department_IDs(j)) := Avg_Salaries(j);
END LOOP;
END BEFORE STATEMENT;
AFTER EACH ROW IS
BEGIN
IF :NEW.Salary - :Old.Salary >
Ten_Percent*Department_Avg_Salaries(:NEW.Department_ID)
THEN
Raise_Application_Error(-20000, 'Raise too big');
END IF;
END AFTER EACH ROW;
END Check_Employee_Salary_Raise;
Mutating Oracle triggers
Avoiding Mutating triggers
The insertto the childtable causedthe foreignkeytovalidate the dataonthe parent (whichfiredthe
trigger) causingthe insertof the childtable toresultina mutatingtable erroron the parenttable.
The Oracle mutatingtriggererroroccurs whena triggerreferencesthe table thatownsthe trigger,
resultinginthe "ORA-04091: table name ismutating,trigger/functionmaynotsee it."message.
 Don't use triggers - The bestway to avoidthe mutatingtable errorisnot to use triggers. While
the object-orientedOracle provides"methods"thatare associatedwithtables,mostsavvyPL/SQL
developersavoidtriggersunlessabsolutelynecessary.
 Use an "after" or "insteadof" trigger- If youmust use a trigger,it'sbestto avoidthe mutating
table errorby usingan "after"trigger,toavoidthe currency issuesassociatedwithamutatingtable. For
example,usingatrigger":afterupdate onxxx",the original update hascompletedandthe table will not
be mutating.
 Re-work the trigger syntax - Dr. Hall has some greatnoteson mutatingtable errors,andoffers
otherwaysto avoidmutatingtableswith acombinationof row-levelandstatement-leveltriggers.
 Use autonomous transactions - You can avoidthe mutatingtable errorby markingyourtrigger
as an autonomoustransaction,makingitindependentfromthe table thatcallsthe procedure.
At the endof the day,the mutatingtable erroris usuallythe resultof apoor applicationdesignand
mutatingtriggersshouldbe avoidedwheneverpossible.
Steve Callanhasthese notesonthe ORA-04091 error:
"Here isa problemmanydevelopersruninto:ORA-04091 table owner.table_name ismutating,
trigger/functionmaynotsee it.In manycases,the cause of thiserror isdue to code withina triggerthat
looksat or touchesthe data withinthe table the trigger isbeingcalledorinvokedfrom.
The reasonOracle raisesthiserror isrelatedtoone of Oracle'sprimarystrengthsasa relational
database managementsystem.The particularstrengthinquestionhere isthatof havinga read
consistentview of data.
It isworthwhile tonote thatthisORA-04091 error occurs notonlyin the "pure"database development
environment,butalsointhe Oracle toolstype of developmentenvironmentsuchasOracle SQL*Forms.
AnothersolutionreliesonusinganINSTEAD-OFtriggerinsteadof the triggeryoumeanttouse when
youreceivedthe error.Anothersolutionisactuallymore of apreventative measure,namely,usingthe
righttype of triggerforthe taskat hand.
Perhapsthe greateststrengthorutilityof anINSTEAD-OFtriggerisitsabilitytoupdate whatwould
normallyappeartobe non-updateableviews.Simpleviews(prettymuchbasedonasingle base table)
generallyare inherentlyupdateableviaDML statementsissuedagainstthe view.
However,whenaviewbecomesmore complex (multiple tablesorviewsusedinvariousjoinconditions
to create the newsingle view),there isagoodchance that many columns,asreferencedbythe view,
lose their"updateable-ness."
So,beingthe data dictionaryview/tablename triviawizardthat youare,youknow to querythe
XXX_UPDATABLE_COLUMNSviews,substitutingUSER,ALL or DBA for XXXas applicable.
There are exceptionstothisrule aboutviewsbeinginherentlyupdateable.The exceptions(or
restrictions) include viewsthatuse aggregate functions;groupfunctions;use of the DISTINCTkeyword;
use of GROUP BY, CONNECTBY or STARTWITH clauses;anduse of some joins.Inmanycases,use of the
INSTEAD-OFtriggerfeature allowsyoutoworkaroundthese restrictions.
INSTEAD-OFtriggersare alsouseful forFormsdevelopersbecause formsare commonlybasedonviews.
The INSTEAD-OFtrigger,beinga"real"trigger,andnot a true form trigger,isstoredonthe server."

More Related Content

What's hot

Les05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group FunctionLes05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group Function
NETsolutions Asia: NSA – Thailand, Sripatum University: SPU
 
Les02
Les02Les02
Oracle - Program with PL/SQL - Lession 01
Oracle - Program with PL/SQL - Lession 01Oracle - Program with PL/SQL - Lession 01
Oracle - Program with PL/SQL - Lession 01
Thuan Nguyen
 
Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09
Thuan Nguyen
 
Les02 Restricting And Sorting Data
Les02 Restricting And Sorting DataLes02 Restricting And Sorting Data
Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17
Thuan Nguyen
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
Reka
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les12 creating views
Les12 creating viewsLes12 creating views
Oracle PL/SQL Bulk binds
Oracle PL/SQL Bulk bindsOracle PL/SQL Bulk binds
Oracle PL/SQL Bulk binds
Scott Wesley
 
Les10
Les10Les10
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Oracle 11g new features for developers
Oracle 11g new features for developersOracle 11g new features for developers
Oracle 11g new features for developers
Scott Wesley
 
Les09
Les09Les09
Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricks
Yanli Liu
 
Les04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple TableLes04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple Table
NETsolutions Asia: NSA – Thailand, Sripatum University: SPU
 
Les03 Single Row Function
Les03 Single Row FunctionLes03 Single Row Function
Oracle 11g PL/SQL notes
Oracle 11g PL/SQL notesOracle 11g PL/SQL notes
Oracle 11g PL/SQL notes
anilakduygu
 
Oracle
OracleOracle
It6312 dbms lab-ex2
It6312 dbms lab-ex2It6312 dbms lab-ex2
It6312 dbms lab-ex2
MNM Jain Engineering College
 

What's hot (20)

Les05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group FunctionLes05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group Function
 
Les02
Les02Les02
Les02
 
Oracle - Program with PL/SQL - Lession 01
Oracle - Program with PL/SQL - Lession 01Oracle - Program with PL/SQL - Lession 01
Oracle - Program with PL/SQL - Lession 01
 
Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09
 
Les02 Restricting And Sorting Data
Les02 Restricting And Sorting DataLes02 Restricting And Sorting Data
Les02 Restricting And Sorting Data
 
Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 
Les12 creating views
Les12 creating viewsLes12 creating views
Les12 creating views
 
Oracle PL/SQL Bulk binds
Oracle PL/SQL Bulk bindsOracle PL/SQL Bulk binds
Oracle PL/SQL Bulk binds
 
Les10
Les10Les10
Les10
 
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Les01 Writing Basic Sql Statements
 
Oracle 11g new features for developers
Oracle 11g new features for developersOracle 11g new features for developers
Oracle 11g new features for developers
 
Les09
Les09Les09
Les09
 
Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricks
 
Les04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple TableLes04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple Table
 
Les03 Single Row Function
Les03 Single Row FunctionLes03 Single Row Function
Les03 Single Row Function
 
Oracle 11g PL/SQL notes
Oracle 11g PL/SQL notesOracle 11g PL/SQL notes
Oracle 11g PL/SQL notes
 
Oracle
OracleOracle
Oracle
 
It6312 dbms lab-ex2
It6312 dbms lab-ex2It6312 dbms lab-ex2
It6312 dbms lab-ex2
 

Similar to Trig

Oracle sql tuning
Oracle sql tuningOracle sql tuning
Oracle sql tuning
bishnupriya Panda
 
Sql query [select, sub] 4
Sql query [select, sub] 4Sql query [select, sub] 4
Sql query [select, sub] 4
Dr. C.V. Suresh Babu
 
Oracle
OracleOracle
Oracle
Yo Seven
 
Web Developer make the most out of your Database !
Web Developer make the most out of your Database !Web Developer make the most out of your Database !
Web Developer make the most out of your Database !
Jean-Marc Desvaux
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
Dr. C.V. Suresh Babu
 
Function Procedure Trigger Partition.pdf
Function Procedure Trigger Partition.pdfFunction Procedure Trigger Partition.pdf
Function Procedure Trigger Partition.pdf
Sanam Maharjan
 
DOODB_LAB.pptx
DOODB_LAB.pptxDOODB_LAB.pptx
DOODB_LAB.pptx
FilestreamFilestream
 
Sql Queries
Sql QueriesSql Queries
Sql Queries
webicon
 
Chapter9 more on database and sql
Chapter9 more on database and sqlChapter9 more on database and sql
Chapter9 more on database and sql
KV(AFS) Utarlai, Barmer (Rajasthan)
 
Sql
SqlSql
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek SharmaIntroduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
अभिषेक शर्मा
 
SQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update featureSQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update feature
Frans Jongma
 
Top MNC'S Interview questions and answers
Top MNC'S Interview questions and answersTop MNC'S Interview questions and answers
Top MNC'S Interview questions and answers
Madhu Dhare
 
Interacting with Oracle Database
Interacting with Oracle DatabaseInteracting with Oracle Database
Interacting with Oracle Database
Chhom Karath
 
sql statement
sql statementsql statement
sql statement
zx25 zx25
 
ADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptxADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptx
ArjayBalberan1
 
Les18
Les18Les18
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functions
Nitesh Singh
 
Oracle - Program with PL/SQL - Lession 05
Oracle - Program with PL/SQL - Lession 05Oracle - Program with PL/SQL - Lession 05
Oracle - Program with PL/SQL - Lession 05
Thuan Nguyen
 
Introduction Oracle Database 11g Release 2 for developers
Introduction Oracle Database 11g Release 2 for developersIntroduction Oracle Database 11g Release 2 for developers
Introduction Oracle Database 11g Release 2 for developers
Lucas Jellema
 

Similar to Trig (20)

Oracle sql tuning
Oracle sql tuningOracle sql tuning
Oracle sql tuning
 
Sql query [select, sub] 4
Sql query [select, sub] 4Sql query [select, sub] 4
Sql query [select, sub] 4
 
Oracle
OracleOracle
Oracle
 
Web Developer make the most out of your Database !
Web Developer make the most out of your Database !Web Developer make the most out of your Database !
Web Developer make the most out of your Database !
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
Function Procedure Trigger Partition.pdf
Function Procedure Trigger Partition.pdfFunction Procedure Trigger Partition.pdf
Function Procedure Trigger Partition.pdf
 
DOODB_LAB.pptx
DOODB_LAB.pptxDOODB_LAB.pptx
DOODB_LAB.pptx
 
Sql Queries
Sql QueriesSql Queries
Sql Queries
 
Chapter9 more on database and sql
Chapter9 more on database and sqlChapter9 more on database and sql
Chapter9 more on database and sql
 
Sql
SqlSql
Sql
 
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek SharmaIntroduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
 
SQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update featureSQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update feature
 
Top MNC'S Interview questions and answers
Top MNC'S Interview questions and answersTop MNC'S Interview questions and answers
Top MNC'S Interview questions and answers
 
Interacting with Oracle Database
Interacting with Oracle DatabaseInteracting with Oracle Database
Interacting with Oracle Database
 
sql statement
sql statementsql statement
sql statement
 
ADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptxADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptx
 
Les18
Les18Les18
Les18
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functions
 
Oracle - Program with PL/SQL - Lession 05
Oracle - Program with PL/SQL - Lession 05Oracle - Program with PL/SQL - Lession 05
Oracle - Program with PL/SQL - Lession 05
 
Introduction Oracle Database 11g Release 2 for developers
Introduction Oracle Database 11g Release 2 for developersIntroduction Oracle Database 11g Release 2 for developers
Introduction Oracle Database 11g Release 2 for developers
 

Recently uploaded

原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 

Recently uploaded (20)

原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 

Trig

  • 1. Declaring an Autonomous Function in a Package Example 6-43 Declaring an Autonomous Function in a Package CREATE OR REPLACE PACKAGE emp_actions AS -- package specification FUNCTION raise_salary (emp_id NUMBER, sal_raise NUMBER) RETURN NUMBER; END emp_actions; / CREATE OR REPLACE PACKAGE BODY emp_actions AS -- package body -- code for function raise_salary FUNCTION raise_salary (emp_id NUMBER, sal_raise NUMBER) RETURN NUMBER IS PRAGMA AUTONOMOUS_TRANSACTION; new_sal NUMBER(8,2); BEGIN UPDATE employees SET salary = salary + sal_raise WHERE employee_id = emp_id; COMMIT; SELECT salary INTO new_sal FROM employees WHERE employee_id = emp_id; RETURN new_sal; END raise_salary; END emp_actions; / Create GLOBAL TEMPORARY Table. CREATE GLOBAL TEMPORARY TABLE admin_work_area (startdate DATE, enddate DATE, class CHAR(20)) ON COMMIT DELETE ROWS; Posted by Asif at 8:30 PM CREATE TRIGGER Statement Using Triggers:Example 9-1 CREATE TRIGGER Statement CREATE OR REPLACE TRIGGER Print_salary_changes BEFORE DELETE OR INSERT OR UPDATE ON emp FOR EACH ROW WHEN (NEW.EMPNO > 0) DECLARE sal_diff number; BEGIN sal_diff := :NEW.SAL - :OLD.SAL; dbms_output.put('Old salary: ' || :OLD.sal); dbms_output.put(' New salary: ' || :NEW.sal); dbms_output.put_line(' Difference ' || sal_diff); END; /
  • 2. CREATE TRIGGER -Calling a Procedure in a Trigger Body: CREATE TRIGGER: Calling a Procedure in a Trigger Body: Example You could create the salary_check trigger described in the preceding example by calling a procedure instead of providing the trigger body in a PL/SQL block. Assume you have defined a procedure check_sal in the hr schema, which verifies that an employee's salary is in an appropriate range. Then you could create the trigger salary_check as follows: CREATE TRIGGER salary_check BEFORE INSERT OR UPDATE OF salary, job_id ON employees FOR EACH ROW WHEN (new.job_id <> 'AD_VP') CALL check_sal(:new.job_id, :new.salary, :new.last_name) Posted by Asif at 4:34 AM Hierarchical Level Query Example using SYS_CONNECT_BY_PATH SYS_CONNECT_BY_PATH: is valid only in hierarchical queries. It returns the path of a column value from root to node, with column values separated by char for each row returned by CONNECT BY condition. Both column and char can be any of the datatypes CHAR, VARCHAR2, NCHAR, or NVARCHAR2. The string returned is of VARCHAR2 datatype and is in the same character set as column. Examples The following example returns the path of employee names from employee Kochhar to all employees of Kochhar (and their employees): SELECT LPAD(' ', 2*level-1)||SYS_CONNECT_BY_PATH(last_name, '/') "Path" FROM employees START WITH last_name = 'Kochhar' CONNECT BY PRIOR employee_id = manager_id; Path --------------------------------------------------------------- /Kochhar /Kochhar/Greenberg /Kochhar/Greenberg/Faviet /Kochhar/Greenberg/Chen /Kochhar/Greenberg/Sciarra /Kochhar/Greenberg/Urman /Kochhar/Greenberg/Popp /Kochhar/Whalen /Kochhar/Mavris /Kochhar/Baer /Kochhar/Higgins /Kochhar/Higgins/Gietz Hierarchical Queries -CONNECT_BY_ROOT Examples Hierarchical Queries: CONNECT_BY_ROOT Examples The following example returns the last name of each employee in department 110, each manager above that employee in the hierarchy, the number of levels between manager and employee, and the path between the two: SELECT last_name "Employee", CONNECT_BY_ROOT last_name "Manager", LEVEL-1 "Pathlen", SYS_CONNECT_BY_PATH(last_name, '/') "Path" FROM employees WHERE LEVEL > 1 and department_id = 110 CONNECT BY PRIOR employee_id = manager_id;
  • 3. Employee Manager Pathlen Path --------------- ------------ ---------- ----------------------------------- Higgins Kochhar 1 /Kochhar/Higgins Gietz Kochhar 2 /Kochhar/Higgins/Gietz Gietz Higgins 1 /Higgins/Gietz Higgins King 2 /King/Kochhar/Higgins Gietz King 3 /King/Kochhar/Higgins/Gietz Avoiding Collection Exceptions Avoiding Collection Exceptions In most cases, if you reference a nonexistent collection element, PL/SQL raises a predefined exception. Consider the following example: DECLARE TYPE NumList IS TABLE OF NUMBER; nums NumList; -- atomically null BEGIN /* Assume execution continues despite the raised exceptions. */ nums(1) := 1; -- raises COLLECTION_IS_NULL (1) nums := NumList(1,2); -- initialize table nums(NULL) := 3 -- raises VALUE_ERROR (2) nums(0) := 3; -- raises SUBSCRIPT_OUTSIDE_LIMIT (3) nums(3) := 3; -- raises SUBSCRIPT_BEYOND_COUNT (4) nums.DELETE(1); -- delete element 1 IF nums(1) = 1 THEN ... -- raises NO_DATA_FOUND (5) In the first case, the nested table is atomically null. In the second case, the subscript is null. In the third case, the subscript is outside the legal range. In the fourth case, the subscript exceeds the number of elements in the table. In the fifth case, the subscript designates a deleted element. The following list shows when a given exception is raised: Collection Exception Raised when... COLLECTION_IS_NULL you try to operate on an atomically null collection. NO_DATA_FOUND a subscript designates an element that was deleted, or a nonexistent element of an associative array. SUBSCRIPT_BEYOND_COUNT a subscript exceeds the number of elements in a collection. SUBSCRIPT_OUTSIDE_LIMIT a subscript is outside the allowed range.
  • 4. VALUE_ERROR a subscript is null or not convertible to the key type. This exception might occur if the key is defined as a PLS_INTEGER range, and the subscript is outside this range. In some cases, you can pass invalid subscripts to a method without raising an exception. For instance, when you pass a null subscript to procedure DELETE, it does nothing. Also, you can replace deleted elements without raising NO_DATA_FOUND, as the following example shows: DECLARE TYPE NumList IS TABLE OF NUMBER; nums NumList := NumList(10,20,30); -- initialize table BEGIN nums.DELETE(-1); -- does not raise SUBSCRIPT_OUTSIDE_LIMIT nums.DELETE(3); -- delete 3rd element dbms_output.put_line(nums.COUNT); -- prints 2 nums(3) := 30; -- allowed; does not raise NO_DATA_FOUND dbms_output.put_line(nums.COUNT); -- prints 3 END; Posted by Asif at 1:28 AM ORACLE-BASE - Using Ref Cursors To Return Recordsets Using Ref Cursors To Return Recordsets The Reference Cursor which is also called the Cursor Variables is available since Oracle 7.3 the REF CURSOR type has been available to allow recordsets to be returned from stored procedures and functions. Oracle 9i introduced the predefined SYS_REFCURSOR type, meaning we no longer have to define our own REF CURSOR types. The example below uses a ref cursor to return a subset of the records in the EMP table. The following procedure opens a query using a SYS_REFCURSOR output parameter. Notice the cursor is not closed in the procedure. It is up to the calling code to manage the cursor once it has been opened. CREATE OR REPLACE PROCEDURE get_emp_rs (p_deptno IN emp.deptno%TYPE, p_recordset OUT SYS_REFCURSOR) AS BEGIN OPEN p_recordset FOR SELECT ename, empno, deptno FROM emp WHERE deptno = p_deptno ORDER BY ename; END GetEmpRS; / The resulting cursor can be referenced from PL/SQL as follows.
  • 5. SET SERVEROUTPUT ON SIZE 1000000 DECLARE l_cursor SYS_REFCURSOR; l_ename emp.ename%TYPE; l_empno emp.empno%TYPE; l_deptno emp.deptno%TYPE; BEGIN get_emp_rs (p_deptno => 30, p_recordset => l_cursor); LOOP FETCH l_cursor INTO l_ename, l_empno, l_deptno; EXIT WHEN l_cursor%NOTFOUND; DBMS_OUTPUT.PUT_LINE(l_ename || ' | ' || l_empno || ' | ' || l_deptno); END LOOP; CLOSE l_cursor; END; / Posted by Oracle PL/SQL - Raise User-Defined Exception With Custom SQLERRM - Stack Overflow User defined Exception with Naming and assigning the Error Code no. 1 declare 2 ex_custom EXCEPTION; 3 PRAGMA EXCEPTION_INIT( ex_custom, -20001 ); 4 begin 5 raise_application_error( -20001, 'This is a custom error' ); 6 exception 7 when ex_custom 8 then 9 dbms_output.put_line( sqlerrm ); 10* end; SQL> / ORA-20001: This is a custom error PL/SQL procedure successfully completed. Compound Triggers , Avoid Mutating-Table Error Using Compound Triggers to Avoid Mutating-Table Error You can use compound triggers to avoid the mutating-table error (ORA-04091) described in Trigger Restrictions on Mutating Tables. Scenario: A business rule states that an employee's salary increase must not exceed 10% of the average salary for the employee's department. This rule must be enforced by a trigger.
  • 6. Solution: Define a compound trigger on updates of the table hr.employees, as in Example 9-4. The state variables are initialized each time the trigger fires (even when the triggering statement is interrupted and restarted). Example 9-4 Compound Trigger that Avoids Mutating-Table Error CREATE OR REPLACE TRIGGER Check_Employee_Salary_Raise FOR UPDATE OF Salary ON Employees COMPOUND TRIGGER Ten_Percent CONSTANT NUMBER := 0.1; TYPE Salaries_t IS TABLE OF Employees.Salary%TYPE; Avg_Salaries Salaries_t; TYPE Department_IDs_t IS TABLE OF Employees.Department_ID%TYPE; Department_IDs Department_IDs_t; TYPE Department_Salaries_t IS TABLE OF Employees.Salary%TYPE INDEX BY VARCHAR2(80); Department_Avg_Salaries Department_Salaries_t; BEFORE STATEMENT IS BEGIN SELECT AVG(e.Salary), NVL(e.Department_ID, -1) BULK COLLECT INTO Avg_Salaries, Department_IDs FROM Employees e GROUP BY e.Department_ID; FOR j IN 1..Department_IDs.COUNT() LOOP Department_Avg_Salaries(Department_IDs(j)) := Avg_Salaries(j); END LOOP; END BEFORE STATEMENT;
  • 7. AFTER EACH ROW IS BEGIN IF :NEW.Salary - :Old.Salary > Ten_Percent*Department_Avg_Salaries(:NEW.Department_ID) THEN Raise_Application_Error(-20000, 'Raise too big'); END IF; END AFTER EACH ROW; END Check_Employee_Salary_Raise; Mutating Oracle triggers Avoiding Mutating triggers The insertto the childtable causedthe foreignkeytovalidate the dataonthe parent (whichfiredthe trigger) causingthe insertof the childtable toresultina mutatingtable erroron the parenttable. The Oracle mutatingtriggererroroccurs whena triggerreferencesthe table thatownsthe trigger, resultinginthe "ORA-04091: table name ismutating,trigger/functionmaynotsee it."message.  Don't use triggers - The bestway to avoidthe mutatingtable errorisnot to use triggers. While the object-orientedOracle provides"methods"thatare associatedwithtables,mostsavvyPL/SQL developersavoidtriggersunlessabsolutelynecessary.  Use an "after" or "insteadof" trigger- If youmust use a trigger,it'sbestto avoidthe mutating table errorby usingan "after"trigger,toavoidthe currency issuesassociatedwithamutatingtable. For example,usingatrigger":afterupdate onxxx",the original update hascompletedandthe table will not be mutating.  Re-work the trigger syntax - Dr. Hall has some greatnoteson mutatingtable errors,andoffers otherwaysto avoidmutatingtableswith acombinationof row-levelandstatement-leveltriggers.  Use autonomous transactions - You can avoidthe mutatingtable errorby markingyourtrigger as an autonomoustransaction,makingitindependentfromthe table thatcallsthe procedure. At the endof the day,the mutatingtable erroris usuallythe resultof apoor applicationdesignand mutatingtriggersshouldbe avoidedwheneverpossible. Steve Callanhasthese notesonthe ORA-04091 error: "Here isa problemmanydevelopersruninto:ORA-04091 table owner.table_name ismutating, trigger/functionmaynotsee it.In manycases,the cause of thiserror isdue to code withina triggerthat looksat or touchesthe data withinthe table the trigger isbeingcalledorinvokedfrom.
  • 8. The reasonOracle raisesthiserror isrelatedtoone of Oracle'sprimarystrengthsasa relational database managementsystem.The particularstrengthinquestionhere isthatof havinga read consistentview of data. It isworthwhile tonote thatthisORA-04091 error occurs notonlyin the "pure"database development environment,butalsointhe Oracle toolstype of developmentenvironmentsuchasOracle SQL*Forms. AnothersolutionreliesonusinganINSTEAD-OFtriggerinsteadof the triggeryoumeanttouse when youreceivedthe error.Anothersolutionisactuallymore of apreventative measure,namely,usingthe righttype of triggerforthe taskat hand. Perhapsthe greateststrengthorutilityof anINSTEAD-OFtriggerisitsabilitytoupdate whatwould normallyappeartobe non-updateableviews.Simpleviews(prettymuchbasedonasingle base table) generallyare inherentlyupdateableviaDML statementsissuedagainstthe view. However,whenaviewbecomesmore complex (multiple tablesorviewsusedinvariousjoinconditions to create the newsingle view),there isagoodchance that many columns,asreferencedbythe view, lose their"updateable-ness." So,beingthe data dictionaryview/tablename triviawizardthat youare,youknow to querythe XXX_UPDATABLE_COLUMNSviews,substitutingUSER,ALL or DBA for XXXas applicable. There are exceptionstothisrule aboutviewsbeinginherentlyupdateable.The exceptions(or restrictions) include viewsthatuse aggregate functions;groupfunctions;use of the DISTINCTkeyword; use of GROUP BY, CONNECTBY or STARTWITH clauses;anduse of some joins.Inmanycases,use of the INSTEAD-OFtriggerfeature allowsyoutoworkaroundthese restrictions. INSTEAD-OFtriggersare alsouseful forFormsdevelopersbecause formsare commonlybasedonviews. The INSTEAD-OFtrigger,beinga"real"trigger,andnot a true form trigger,isstoredonthe server."