Download presentation
Presentation is loading. Please wait.
Published byTimothy Chambers Modified over 9 years ago
1
Cursor
2
Cursors Operations Cursors adalah suatu nama area yang berisi hasil dari suatu statement SQL. 1. OPEN 2. FETCH 3. CLOSE
3
Cursors Attribute 1. %FOUND 2. %NOTFOUND 3. %ROWCOUNT 4. %ISOPEN
4
Function & Procedure
5
Function FUNCTION Nama_Function (parameter) RETURN TYPE IS deklarasi variabel BEGIN statement; RETURN(variable/value); END;
6
Procedure PROCEDURE Nama_Procedure (parameter) IS deklarasi variabel BEGIN statement; EXCEPTION statement; END;
7
Parameter Syntax parameter_name [IN | OUT | IN OUT] datatype [:= expr]
8
Procedure Parameter Modes Procedure IN OUT Argumen (DECLARE) BEGIN END; EXCEPTION Calling Environment IN Argument OUT Argument
9
Function Parameter Modes Function (DECLARE) BEGIN END; EXCEPTION Calling Environment IN Argument
10
Procedure vs Function ProcedureFunction Execute as a PL/SQL statement Called as part of an expression No RETURN datatypeMust contain a RETURN datatype Can return a valueMust return a value
11
Example DECLARE v_tax number; v_sal emp.salary%TYPE; BEGIN SELECT salary into v_sal FROM emp WHERE id = 97001; v_tax := Tax(v_sal); EXCEPTION WHEN NO_DATA_FOUND THEN v_tax := 0; END; FUNCTION Tax(v_value IN NUMBER) RETURN NUMBER IS BEGIN RETURN(v_value *.07); END Tax;
12
Example DECLARE v_idemp.id%TYPE := 97001; v_salemp.salary%TYPE; BEGIN SELECT salary into v_sal FROM emp WHERE id = v_id; Change_Salary(v_id, v_sal*1.1); EXCEPTION WHEN NO_DATA_FOUND THEN NULL; END; PROCEDURE Change_Salary (v_emp_id IN NUMBER, v_new_salary IN NUMBER) IS BEGIN UPDATE s_emp SET salary = v_new_salary WHERE id = v_emp_id; COMMIT; END Change_Salary;
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.