Introduction to PL/SQL
Author:Farhan Arain
Language: eng
Format: mobi
Published: 2016-03-18T22:00:00+00:00
SELECT empno,
ename,
sal,
inc_sal (sal) after_increment
FROM emp
WHERE sal > (SELECT MAX (inc_sal (sal))
FROM emp
WHERE deptno = 10)
/
Output
EMPNO ENAME SAL AFTER_INCREMENT
---------- ------------------------------ ---------- ---------------
7900 JAMES 17600 19360
1ote: Output can be different according to the data in EMP tables
There are some restrictions in calling functions from SQL Expressions A function must follow following rules to be callable from SQL Expression 1. It should be a stored function
2. It should accept only IN parameters
3. It should have valid SQL data types in parameters not PL/SQL specific type like collections.
4. It should not contain any DML statement
5. It should not perform DML or it should not query the table if this function is used in UPDATE/DELETE statement of the same table otherwise “Table is mutating” error will rise.
6. It should not contain COMMIT, ROLLBAK, SAVPOINT statements
As shown in the following example, the function is inserting a record into EMP table so when same function is used in Update statement of the same table the error is raised.
Example 2
CREATE OR REPLACE FUNCTION insert_emp (p_val NUMBER) RETURN NUMBER
IS
BEGIN
INSERT INTO emp
(empno,
ename,
deptno
)
VALUES (101,
'AQSA',
10
);
RETURN (p_val * .1);
END;
/
OUTPUT
PLSQL procedure successfully completed
UPDATE emp
SET sal = insert_emp (sal)
WHERE empno = 7900
/
OUTPUT
SET sal=INSERT_emp(sal)
*
ERROR at line 2:
ORA-04091: table SCOTT.EMP is mutating, trigger/function may not see it ORA-06512: at "SCOTT.INSERT_EMP", line 5
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
A Swirl of Ocean by Melissa Sarno(50819)
The Book of Dreams (Saxon Series) by Severin Tim(33307)
Cecilia; Or, Memoirs of an Heiress — Volume 1 by Fanny Burney(32436)
Cecilia; Or, Memoirs of an Heiress — Volume 2 by Fanny Burney(31872)
Cecilia; Or, Memoirs of an Heiress — Volume 3 by Fanny Burney(31857)
Call Me by Your Name by André Aciman(20375)
Eleanor and Park by Rainbow Rowell(15359)
Always and Forever, Lara Jean by Jenny Han(14803)
Norse Mythology by Gaiman Neil(13210)
For the Love of Europe by Rick Steves(13037)
Crooked Kingdom: Book 2 (Six of Crows) by Bardugo Leigh(12220)
Shadow Children #03 - Among the Betrayed by Margaret Peterson Haddix(11840)
Among the Betrayed by Margaret Peterson Haddix(11554)
Twisted Palace by Erin Watt(11087)
Six of Crows by Leigh Bardugo(10054)
They Both Die at the End by Adam Silvera(9722)
P.S. I Still Love You by Jenny Han(9522)
Fangirl by Rainbow Rowell(9098)
Thirteen Reasons Why by Jay Asher(8799)