PLSQL Notes

April 2, 2018 | Author: Raghavendra Prabhu | Category: Pl/Sql, Subroutine, Software Engineering, Computer Data, Areas Of Computer Science


Comments



Description

------PL/SQL------It is a programming language which is used to define our own logics. It is used execute block of statements at a time and increase the performance. It supports variables and conditional statements and loops. It supports object oriented programming and supports composite data types. It supports handle the error handling mechanism. -----Block ------ -->It is one of the areas which are used to write Programming logic. -->Block has 3 sections: 1. Declaration Section: ** It is one of the sections which are used to declare variables, cursors and exceptions and so on. ** It is Optional Section. 2. Executable Section ** It is one of the Section which is used to write a Program Coding. ** It is Mandatory Section. 3. Exception Section ** It is one of the Section which is used to handle the errors at runtime. ** It is Optional Section. There are Two Types of blocks Supported by PL/SQL 1. Anonymous Block: ** These blocks do not have a name and also not stored in the Database. Ex1: DECLARE _______________ BEGIN ------------END; Ex2: BEGIN DBMS_OUTPUT.PUT_LINE("Welcome to E Business Solutions"); END; 2. Named Block: ** These blocks are having a name and also stored in database. Examples : Procedures , Functions, Packages and Triggers etc.. Variable -->It is one of the memory location which is used to store the data. -->Generally we declare the variables in declaration section. -->Variables Support default and not null. Syntax :Variable_Name Datatype ( Size ); Ex : Declare A Number (5); B Number (5) not null :=10; C Number (5) default 10; Ex-1 : Declare A Varchar2(20); Begin A := ‘Hello EBS’; Dbms_Output.Put_Line( A ); End; =>Storing a value into variable: Using assignment operator ( := ) we storing a value into variable. Syntax : Variable_Name := value; Ex : a :=50; =>Display Message ( or ) Varaible Value: We have one pre defined package which is used display the message or value in a program. Syntax : dbms_output.put_line ( ‘message’ ); dbms_output.put_line ( variable_name ); =>Select ------ Into ------ Clause: This clause is used to retrieve the data from table & storing into pl/sql variables. ename%type. Ex-1 : Declare Vno emp. Vname emp.put_line ( ‘ employee name is : ‘ || ‘ ‘ || vname ). RecordType ( or ) Pl/sql Record 4. var2. % RowType 3.Syntax : select col1. Syntax : variable_name table_name. IndexBy Table ( or ) Pl/sql Table (COLLECTIONS) VVIP ******* %Type: -->It is one of thedatatype which is used to assign the column datatype to a variable. Begin Select ename into vname from emp where empno=vno. col2 into var1. -->It is used to storeone value at a time. % Type 2. . Dbms_output. -->It is not possibleto hold more than one column values or row values. End. ---------DataTypes ---------1.empno%type:=&n.column_name%type. ename || ‘ ‘ || vrow. -->Pinpoint of data is not possible. Ex-1 : Declare Vrow emp%rowtype. Begin Select * into vrow from emp where empno=vno. Syntax : Type Typename is Record ( Val-1 Datatype. Syntax :variable_name table_name%rowtype.. -->Each of the time it override only one record. -->It is not possible to capture more than one table data. End.). Dbms_output. Var Typename . Val-2 Datatype.empno%type:=&n.% RowType -->It is one of thedatatype which is used assign all the column datatypes of table to a variable.sal ).…. Vno emp. -->It holds entire record of the same table.put_line ( vrow. Record Type ( or ) Pl/Sql Record -->Is is one of the user defined temporary data type which is used to store more than one table data ( or ) to assign more than one column datatypes. -->They must at least contain one element. loc%type). VLoc dept.empno%type:=&n. Vrec Rec.empno=vno.sal. End. Vno emp.deptno=dept.vsal||’.ename%type.sal%type.Ex : Declare Type Rec is record ( vname emp. .loc into vrec from emp.dept where emp.put_line(vrec.deptno and emp. Dbms_output.’||vrec. Begin Select ename.vloc). Vsal emp.vname||’.’||vrec. ----------------------Conditional Statements ----------------------1. .put_line ( B ). End if. End. Begin If a<20 then B:=’Yes’. If Else Condition 3. If Condition 2. Ex-1 : Declare A Number ( 4 ) :=&n. Dbms_output. Elsif Condition 4. End if. B Char ( 1 ). Case Condition =>If Condition: Syntax : If condition then Statements. B Char ( 10 ). End if. Dbms_output. Ex-1 : Declare A Number ( 4 ) :=&n. =>Elsif Condition Syntax : If condition-1 then . Else B:=’FALSE’. End. End if. Else Statements .put_line ( B ). Begin If a<20 then B:=’TRUE’.=>If Else Condition: Syntax : If condition then Statements . End if. =>Case Condition: . Else Statements.Statements. Ex-1 : Declare A Number ( 4 ) :=&n. Dbms_output. Begin If a<20 then B:=’Low Value’. Elsif condition-3 then Statements. Elsif condition-2 then Statements. Else B:=’Invalid Value’. B Char ( 15 ). End if. Elsif a>20 and a<100 then B:=’High Value’.put_line ( B ). End. -----Loops . Ex-1 : DECLARE VSAL NUMBER(10):=&N.PUT_LINE('VSAL IS'||' '||'INVALID'). WHEN VSAL>2000 THEN DBMS_OUTPUT. End Case. ELSE DBMS_OUTPUT. Else Statements.PUT_LINE('VSAL IS'||' '||'LOW').Syntax : Case ( column name ) When condition then Statements. BEGIN CASE WHEN VSAL<2000 THEN DBMS_OUTPUT. END. END CASE.PUT_LINE('VSAL IS'||' '||'HIGH'). When condition then Statements. -----1. End. While Loop 4. End loop.put_line ( ‘Welcome to k-onlines. Loop 2. Simple Loop 3. Syntax : Loop Code. End loop. End loop. Ex-2 : Declare N number(5):=1.com' ). . For Loop =>Simple Loop: Syntax : Loop Statements. Exit when condition. Ex-1 : Begin Loop Dbms_output. Begin Loop Dbms_output. End. End loop. Begin Loop Dbms_output. If n>=10 then Exit. Ex-3 : Declare N number(5):=1. End. N:=n+1.put_line ( n ). End loop.put_line ( n ). End if. =>While Loop: Syntax : While ( Condition ) Loop . N:=N+1. Exit when n>=10. End loop..outerbound . End loop.put_line ( N ). Begin For n in 1. End. Begin While n>=10 Loop Dbms_output. =>For Loop: Syntax : For variable_name in Loop Statements.. End loop.10 lowerbound.Statements. Ex-1: Declare N Number(4):=1. Ex-1: Declare N number(5). N:=N+1. Begin For n in reverse 1.10 Loop Dbms_output.put_line ( N ). End loop. End. End. End loop. Ex-2 Declare N number(5).Loop Dbms_output. ------------------------BIND VARIABLE/SESSION VARIABLE/HOST VARIABLE------------------------------------>These Variables are Session Variables Syntax: Variable a Number..put_line ( N ). Ex-1 : . Variable V Number. DECLARE A Number(5):=500. -------CURSOR -------- -->Cursor is a buffer area which is used to process Multiple records and also record by record process . BEGIN :v:=a/2. END. There are Two Types of Cursors: 1. Implicit Cursor 2. Types of Exceptions: 1. Explicit Cursor => IMPLICIT CURSOR : ---------EXCEPTIONS ----------->Exception is one of the activity which is used to handle the errors at runtime. Predefined Exception . Eg: . User-defined Exception 3. invalid_number 6.2. * ERROR is ORA-01403:no data found * To handle this error we are using NO_DATA_FOUND exception. when exception2 then statements. NO_DATA_FOUND: ---------------* When a PL/SQL block contains "Select into" clause and if requested data not available in the table. cursor_already_open 5. no_data_found 2. value_error 7. invalid_cursor 4. Predefined Exceptions are: 1. Syntax: when exception1 then statements. zero_divide 8. Oracle Server returns an error. too_many_rows 3. Un-named Exception *--> Predefined Exception: ** It is one of the Exception which are defined by Oracle. ** There are about 20 Exceptions defined by Oracle. when others then statements. others etc etc etc 1. we will catch the exception in below program DECLARE I EMP%ROWTYPE. --Above program will throw no data found exception.DECLARE I EMP%ROWTYPE. END. EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT. DBMS_OUTPUT.ENAME). DBMS_OUTPUT.'|| I.PUT_LINE("Employee Does not exist").ENAME). BEGIN SELECT * INTO I FROM EMP WHERE EMPNO=1111.'|| I.EMPNO||'. . 2.PUT_LINE(I. BEGIN SELECT * INTO I FROM EMP WHERE EMPNO=1111. TOO_MANY_ROWS: ---------------* When a Select into clause try to return more than one recor or more than one value then oracle server return error.EMPNO||'. END.PUT_LINE(I. '||I. we will catch the exception in below program DECLARE I EMP%ROWTYPE.'||I. --We can also include multiple exception catching code.EMPNO||'.DEPTNO).DEPTNO).'||I.ENAME||'. END.PUT_LINE("WE CANNOT DISPLAY MORE THAN ONE EMPLOYEE"). DBMS_OUTPUT. BEGIN SELECT * INTO I FROM EMP WHERE DEPTNO=40.* ERROR is ORA-01422:Exact fetch returns more than requested number of rows. END. BEGIN SELECT * INTO I FROM EMP WHERE DEPTNO=40. Like below example we can have both NO_DATA_FOUND and TOO_MANY_ROWS . --Above program will throw TOO_MANY_ROWS exception.'|| I.ENAME||'.EMPNO||'. Eg: DECLARE I EMP%ROWTYPE.PUT_LINE(I.PUT_LINE(I. EXCEPTION WHEN TOO_MANY_ROWS THEN DBMS_OUTPUT. DBMS_OUTPUT. * To handle this error we are using TOO_MANY_ROWS exception. PUT_LINE("WE CANNOT DISPLAY MORE THAN ONE EMPLOYEE"). END. * ERROR is ORA-01001: Invalid Cursor * To handle this error we are using INVALID_CURSOR exception.PUT_LINE(I. BEGIN SELECT * INTO I FROM EMP WHERE DEPTNO=40.PUT_LINE("Employee Does not exist"). INVALID_CURSOR: -----------------* Whenever we are performing invalid operations on a cursor. EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT. DBMS_OUTPUT.ENAME||'. server returns an error.DECLARE I EMP%ROWTYPE. WHEN TOO_MANY_ROWS THEN DBMS_OUTPUT.EMPNO||'. For eg: If we try to close a cursor without opening the cursor then Oracle server returns an error.DEPTNO).'||I. 3. Eg: .'|| I. '||I. EXIT WHEN C1%NOTFOUND. EXCEPTION WHEN INVALID_CURSOR THEN DBMS_OUTPUT.'||I. END. 4. CLOSE C1.ENAME||'. END LOOP. --Above program will throw Invalid Cursor exception.PUT_LINE("Open The Cursor Properly before closing"). BEGIN --> Note here we have not opened the cursor LOOP FETCH C1 INTO I. BEGIN --> Note here we have not opened the cursor LOOP FETCH C1 INTO I. I EMP%ROWTYPE.PUT_LINE(I. I EMP%ROWTYPE.SAL). CLOSE C1. END LOOP.PUT_LINE(I. CURSOR_ALREADY_OPEN: ----------------------- . DBMS_OUTPUT. EXIT WHEN C1%NOTFOUND.SAL). we will catch the exception in below program DECLARE CURSOR C1 IS SELECT * FROM EMP. END.DECLARE CURSOR C1 IS SELECT * FROM EMP. DBMS_OUTPUT.ENAME||'. Eg: DECLARE CURSOR C1 IS SELECT * FROM EMP.PUT_LINE(I.ENAME||'. I EMP%ROWTYPE.SAL). we will catch the exception in below program DECLARE CURSOR C1 IS SELECT * FROM EMP. Oracle server returns an error. EXIT WHEN C1%NOTFOUND. --Above program will throw CURSOR ALREADY OPEN exception. DBMS_OUTPUT.* Whenever we try to RE-OPEN the cursor without closing the cursor. . END LOOP. BEGIN OPEN C1 --> Note here we have opened the cursor LOOP OPEN C1 --> Note here we are again opening an already open cursor FETCH C1 INTO I. * ERROR is ORA-06511: CURSOR ALREADY OPEN * To handle this error we are using CURSOR_ALREADY_OPEN exception. END. CLOSE C1.'||I. we will catch the exception in below program BEGIN INSERT INTO EMP(EMP_NO.PUT_LINE(I.SAL) VALUES(111. END. END LOOP. *ERROR is ora-01722: invalid number *To handle this error we are using INVALID_ERROR Exception.SAL).'ABCD') . EXCEPTION CURSOR_ALREADY_OPEN THEN DBMS_OUTPUT. DBMS_OUTPUT.I EMP%ROWTYPE.SAL) VALUES(111.INVALID_NUMBER: ----------------*Whenever we try to convert string type to number Oracle server returns error. CLOSE C1.'ABCD'). EXIT WHEN C1%NOTFOUND.ENAME||'.'||I. --Above program will throw invalid number exception as we are trying to insert string into NUMBER datatype SAL. END. BEGIN OPEN C1 --> Note here we have opened the cursor LOOP OPEN C1 --> Note here we are again opening an already open cursor FETCH C1 INTO I.PUT_LINE("Cursor is Open already. Eg1: BEGIN INSERT INTO EMP(EMPNO. Please close before opening again"). 5. END.EXCEPTION WHEN INVALID_NUMBER THEN DBMS_OUTPUT. END. BEGIN . *Whenever we try to store large amount of data than the specified data type size in variable declaration then Oracle server returns error. 6.VALUE_ERROR: ----------------*Whenever we try to convert string type to number based on the condition then Oracle server returns error. Eg1: DECLARE Z NUMBER(10).PUT_LINE(Z). we will catch the exception in below program DECLARE Z NUMBER(10). BEGIN Z:='&X'+'&Y'. --Above program will throw numeric or value error exception. *ERROR is ora-06502: numeric or value error: character to number conversion error *To handle this error we are using VALUE_ERROR Exception. DBMS_OUTPUT.PUT_LINE("INSERT PROPER DATA ONLY"). --Above program will throw Divide by Zero exception. C NUMBER(10):=&C. 7. *Error is ORA-01476: divisor is equal to zero *To handle this error we are using ZERO_DIVIDE Exception. END.PUT_LINE(Z). we will catch the exception in below program . DBMS_OUTPUT. B NUMBER(10):=&B.PUT_LINE("ENTER THE PEOPER DATA ONLY"). BEGIN A:=B/C.Z:='&X'+'&Y'. Eg1: DECLARE A NUMBER(10).ZERO_DIVIDE: ----------------*Whenever we try to Divide by Zero then Oracle Server return a error. DBMS_OUTPUT. END. EXCEPTION WHEN VALUE_ERROR THEN DBMS_OUTPUT.PUT_LINE(A). EXCEPTION WHEN ZERO_DIVIDE THEN DBMS_OUTPUT. Exception Section --> If the Exceptions are raised in Executable section those exceptions are handled using either inner block or an outer block. Ex: . --> Where as If the Exception are raised in declaration section or in exception section those exceptions are handled using outer blocks only. BEGIN A:=B/C. Exception Section 2. B NUMBER(10):=&B. **-->EXCEPTION PROPAGATION -->Exceptions are also raised in 1.PUT_LINE(A). Executable Section 3. C NUMBER(10):=&C.PUT_LINE('VALUE OF C MUST BE GREATER THAN ZERO) END.DECLARE A NUMBER(10). DBMS_OUTPUT. *--> User-defined Exception: -------------------------> We can also create our own exception names and also raise whenever it is necessary. . END. END.PUT_LINE("THE LENGHT IS MORE").BEGIN DECLARE Z VARCHAR2(3):='ABCD'.PUT_LINE("INVALID STRING LENGTH"). EXCEPTION WHEN VALUE_ERROR THEN DBMS_OUTPUT. EXCEPTION WHEN VALUE_ERROR THEN DBMS_OUTPUT. DBMS_OUTPUT. These types of Exceptions are called as User Defined Exception. BEGIN Z:='ABCD'.PUT_LINE(Z). 1. . Ex: DECLARE A EXCEPTION. -->Raise Exception: --> Whenever it is required to raise user defined exception either in executable section or exception section. Handle Exception -->DECLARE EXCEPTION: --> In Declare section of the PL?SQL program we are defining our own Exception using Exception type.-->These Exceptions are divided into 3 steps. Syntax: userdefinedexception_name exception. Declare Exception 2. Raise Exception 3. in this case we are using raise keyword. BEGIN RAISE A. -->Handle Exception: --> We can also handle user defined exceptions same as predefined exception using predefined handler.Syntax: raise userdefinedexception_name Ex: DECLARE A EXCEPTION. Syntax: when userdefinedexception_name1 then . END. when userdefinedexception_name2 then statements. END IF.'DY')='SUN' THEN RAISE A. EXCEPTION WHEN A THEN . EX1: DECLARE A EXCEPTION. ------when others then statements.statements. BEGIN IF TO_CHAR(SYSDATE. BEGIN Z:=X+Y.PUT_LINE("MY EXCEPTION RAISED TODAY"). END IF. END. EX2: DECLARE X NUMBER(2):=&X. Z NUMBER(2). Y NUMBER(2):=&Y. IF Z>99 THEN RAISE A. A EXCEPTION. DBMS_OUTPUT. EXCEPTION .PUT_LINE(Z).DBMS_OUTPUT. LOOP FETCH C1 INTO I. BEGIN OPEN C1. END. SYNTAX: raise predefinedexceptionname. EX: DECLARE CURSOR C1 IS SELECT * FROM EMP WHERE JOB='CLERK'.PUT_LINE("MY USER DEFINED EXCEPTION RAISED"). I EMP %ROWTYPE.WHEN A THEN DBMS_OUTPUT. --> Raising Pre-defined Exception: -------------------------------> We can also raise Predefined Exception using RAISE statement. . SQL Code 2.DBMS_OUTPUT. END. --> Exceptions can be called inside another Exception ***IMP*** --> ERROR Trapping Functions: ------------------------------> There are two error Trapping functions supported by Oracle.EMPNO||'. END LOOP.PUT_LINE("YOUR JOB NOT AVAILABLE"). IF C1%NOTFOUND THEN RAISE NO_DATA_FOUND.'||I. SQL Errm 1. END IF.'||I. SQL CODE: --> It Returns error Numbers .PUT_LINE(I. EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT. 1.JOB).ENAME||'. CLOSE C1. DBMS_OUTPUT. Error_Number: Is given between -20000 to -20999 Error_message: Is given message upto 512 characters. BEGIN SELECT SAL INTO V_SAL FROM EMP WHERE EMPNO=7369. Syntax: raise_application_error (error_number. SQL Errm: --> It returns error number with error message. Ex: DECLARE V_SAL NUMBER(10).PUT_LINE(SQLCODE).2. ***IMP*** --> RAISE APPLICATION ERROR: -----------------------------> If you want to display your own user defined exception number and exception message then we can use this raise application error.error_message). DBMS_OUTPUT. .PUT_LINE(SQLERRM). END. IF I.'Salary is already very high'). EXCEPTION WHEN A THEN RAISE_APPLICATION_ERROR(-20000. ELSE UPDATE EMPLOYEES SET SALARY=SALARY+500 WHERE EMPLOYEE_ID=I. END. --> UN-NAMED EXCEPTION: --------------------------- --> If we want to handle other than 20 predefined errors we are using unnamed method. I EMPLOYEES%ROWTYPE.Ex: DECLARE A EXCEPTION.SALARY>2000 THEN RAISE A. END IF. BEGIN SELECT * INTO I FROM EMPLOYEES WHERE EMPLOYEE_ID=100. --> Because oracle define exception names for regularly occurred errors other than 20 they are not defining exception names .EMPLOYEE_ID. EX: DECLARE V_NO NUMBER(10). error_number). .e at the time of compilation only pl/sql runtime engine associate error number with exception name. --> Here pragma is a Compiler Directive. Syntax: pragma exception_init(userdefined_exception_name. EX2: DECLARE V EMP%ROWTYPE.PUT_LINE(V_NO). E EXCEPTION. BEGIN SELECT EMPNO INTO V_NO FROM EMP WHERE EMPNO=&NO. i. E EXCEPTION.-2291). --> This function is used in declare section of the PL/SQL Block. PRAGMA EXCEPTION_INIT(E.PUT_LINE('PRAGMA ERROR').--> In this case we are providing exception names and also associate this exception name with appropriate error number using exception_init function. END. EXCEPTION WHEN E THEN DBMS_OUTPUT. DBMS_OUTPUT. END. BEGIN SELECT * INTO V FROM EMP WHERE EMPNO=&ENO.-2012).PUT_LINE(V. --> Procedure can execute in only 3 ways .'||V.PUT_LINE('PRAGMA ERROR').PRAGMA EXCEPTION_INIT(E. 1. Procedures 2. Functions :-->PROCEDURES: ----------------> Procedures may or may not return a value. EXCEPTION WHEN E THEN DBMS_OUTPUT. DBMS_OUTPUT.ENAME). ************************************************************************************* ************************************************************************************* ************************************************************************************* ******************* ---------SUB PROGRAMS --------------> Sub Programs are named pl/sql blocks which is used to solve particular task. --> Procedure return more than one value while using the out parameter. --> There are two types of sub programs supported by Oracle.EMPNO||'. BEGIN SELECT * INTO V FROM EMP WHERE EMPNO=P_EMPNO. Ex2: CREATE OR REPLACE PROCEDURE PROC_NAME(p_EMPLOYEE_ID NUMBER) . b) Procedure Body --> In procedure body we are solving actual task. --> Procedure are used to improve the performance of business applications. CALL --> Procedure can not execute in select statement.'||V. END P1. EXEC 3.EMPNO||'. --> Procedure internally has one time compilation process. DBMS_OUTPUT.1. --> Every Procedure is having two parts a) Procedure Specification -->In procedure Specification we are specifying name of the procedure and types of the parameters. EX: CREATE OR REPLACE PROCEDURE P1(P_EMPNO NUMBER) IS V EMP%ROWTYPE.ENAME). Anonymous block 2.PUT_LINE(V. DEPARTMENTS C WHERE A.'||P_REC. P_EMP_END_DATE JOB_HISTORY.JOB_ID.P_EMP_END_DATE||'.START_DATE.DEPARTMENT _NAME INTO P_REC FROM EMPLOYEES A.DEPARTMENT_ID AND A.P_EMP_DEP_NAME).B. BEGIN SELECT A.EMPLOYEE_ID AND A.EMPLOYEE_ID=B.P_EMP_ID||'.'||P_REC.FIRST_NAME%TYPE.START_DATE%TYPE. -------> SHOW ERROR .END_DATE.DEPARTMENT_ID=C.'|| P_REC.PUT_LINE(P_REC.'|| P_REC.JOB_HISTORY B.EMPLOYEE_ID%TYPE.B.EMPLOYEE_ID. END PROC_NAME.A.EMPLOYEE_ID=P_EMPLOYEE_ID. P_EMP_JOB_ID JOB_HISTORY. DBMS_OUTPUT.P_EMP_ID).B.'||P_REC. P_REC REC.DEPARTMENT_ID=B.P_EMP_JOB_ID||'.DEPARTMENT_ID AND A.P_EMP_NAME||'.C. P_EMP_DEP_NAME DEPARTMENTS.PUT_LINE('We did not find any data for given Employee_id: '|| P_REC. P_EMP_START_DATE JOB_HISTORY. EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.END_DATE%TYPE. P_EMP_NAME EMPLOYEES.P_EMP_START_DATE||'.DEPARTMENT_NAME%TYPE).JOB_ID%TYPE.IS TYPE REC IS RECORD ( P_EMP_ID EMPLOYEES.FIRST_NAME. select count(1) FROM ALL_OBJECTS WHERE OBJECT_NAME='PROCEDURE'. OBJECT_NAME from ALL_OBJECTS where OBJECT_NAME='EMPLOYEE'. --> To find how many database Objects created by each user select OWNER. --> Executing the PROCEDURE: . -->to check columns in that table select OBJECT_NAME. we can check them DESC ALL_OBJECTS.function can be used to check errors while compiling database objects --------> All database objects are recorded in ALL_OBJECTS table. count(OBJECT_NAME) from ALL_OBJECTS group by OWNER.OBJECT_TYPE FROM ALL_OBJECTS WHERE OBJECT_NAME='P1'. --> To find the count of procedures. --> To find who created a Particular Table select OWNER. Method 3: CALL P11(7902). end. . I EMP%ROWTYPE.'||I.PUT_LINE(I. END LOOP. END P111. DBMS_OUTPUT.----------------------------Method 1 : EXEC P11(7902). CLOSE C1.'|| I.ENAME||'. BEGIN OPEN C1. EXIT WHEN C1%NOTFOUND.SAL||'. LOOP FETCH C1 INTO I.DEPTNO). Method 2 : Begin P11(7902). Ex2: Procedure with CURSOR CREATE OR REPLACE PROCEDURE P111(P_DEPTNO NUMBER) IS CURSOR C1 IS SELECT * FROM EMP WHERE DEPTNO=P_DEPTNO. FORMAL PARAMETERS 2. through this IN mode we can also pass default values using default or ":=" operator. 1. EX: . OUT mode 3. INOUT mode 1) IN MODE: --> By Default Procedure parameters is IN mode. IN mode 2. ACTUAL PARAMETERS --> Formal Parameters: --> Formal Parameters are defined in Procedure specification. --> There are three types of modes supported by oracle. --> In this case we must use two types of parameters: 1. --> IN Mode is used to pass the values into the Procedure body --> This mode behaves like a constant in Procedure body . --> In formal Parameters we are defining parameter name & mode of the parameter.--> Parameters in PROCEDURE: ------------------------------> Parameters are used to pass the value into Procedures and also return values from the PROCEDURE. P_DNAME IN VARCHAR2. 2.'b').PUT_LINE("RECORD IS INSERTED THROUGH PROCEDURE"). Named Notations 3.CREATE OR REPLACE PROCEDURE P1(P_DEPTNO IN NUMBER. END. Positional Notations: Ex: EXEC P1(1. 1. DBMS_OUTPUT.p_deptno=>2). --> There are 3 types of EXECUTION METHODS supported by IN parameter.P_LOC).p_loc=>'y'. 3. P_LOC IN VARCHAR2) IS BEGIN INSERT INTO DEPT VALUES(P_DEPTNO. Mixed Notations: .'a'. Named Notations: Ex: EXEC P1(p_dname=>'x'. Positional Notations 2.P_DNAME. Mixed Notations 1. Ex: EXEC p1(1.p_loc=>'n'). end.p_dname=>'m'. b OUT number) is begin b:=a*a. dbms_output. Ex1: create or replace procedure p1(a IN number.put_line(b). 2) OUT MODE: --> This Mode is used to return values from procedure body. NOTE: In Oracle if a subprogram contains OUT or INOUT parameters those subprograms are executed using 2 Methods: METHOD 1: USING BIND VARIABLE METHOD 2: USING ANONYMOUS BLOCK BIND VARIABLE: --> These variables are session variables . --> OUT mode internally behaves like a uninitialized variable in PROCEDURE body. --> These variables are created at host environment that's why these variables are also called as HOST VARIABLES. METHOD 2: Anonymous block Ex: DECLARE C NUMBER(4). --> These variables are not a PL/SQL variables.20. METHOD 1: Bind variable: Ex: VARIABLE B NUMBER. CREATE OR REPLACE PROCEDURE P3(PEMPLOYEE_ID NUMBER. PSALARY OUT NUMBER) IS .:b). Develop a Program for passing employee name as in parameter and return salary of that employee using out parameter from emp table. END. but we can also use these variables in PL/SQL to execute subprograms having out parameters. BEGIN P2(10.C). EXEC P1(10. Program: 1. END. Executing PROCEDURE: SET SERVEROUTPUT ON. DBMS_OUTPUT. EXEC P3(101. 3) INOUT MODE: . or we can also execute using session variable (Bind Variable) VARIABLE V NUMBER. Develop a Program for Passing deptno as a Parameter return how many employees are working in that Dept from emp table. END.PUT_LINE('Salary of the Employee with Emplpoyee_id: '||PEMPLOYEE_ID||' is : '||PSALARY).BEGIN SELECT SALARY INTO PSALARY FROM EMPLOYEES WHERE EMPLOYEE_ID=PEMPLOYEE_ID. BEGIN P3(101.SAL).:V). DECLARE SAL NUMBER(6). 2. END.PUT_LINE(A).--> This Mode is used to pass the values into Sub program and return the values from subprogram. --Assigning value 10 to variable A. EXEC P1(:A). EXEC :A:=10. // WE CANNOT EXECUTE ABOVE PROGRAM LIKE THIS P1(10). Ex1: CREATE OR REPLACE PROCEDURE P1(A IN OUT NUMBER) Is BEGIN A:=A*A. METHOD 2 : ANONYMOUS BLOCK DECLARE A NUMBER(10):=&N. AS IT IS AN INOUT VARIABLE. BEGIN P1(A). METHOD 1: BIND VARIABLE VARIABLE A NUMBER. DBMS_OUTPUT. . PUT_LINE(A). --> PRAGMA Autonomous Transaction in PROCEDURE: ------------------------------------------------Not Explained :-->FUNCTIONS: ----------------> Function is a named PL/SQL block which is used to Solve Particular task and by default functions return a single Value. END.PUT_LINE(A). END.DBMS_OUTPUT. DBMS_OUTPUT. EX2: CREATE OR REPLACE PROCEDURE P4(A IN OUT NUMBER) IS BEGIN SELECT SAL INTO A FROM EMPLOYEE WHERE EMPNO=A. . Ex: CREATE OR REPLACE FUNCTION F1( A VARCHAR2) RETURN VARCHAR2 IS BEGIN RETURN A. 1. Bind Variable 4. Anonymous Block 2. EXEC --> Like PROCEDURE Function is also having 2 Parts. Function Specification 2. Function Body --> In function specification we are specifying name of the function and type of the parameters where as in function body we are solving the actual task.--> Function allows to return Multiple Return Statements but it Execute only First return statement --> Function can execute in 4 ways: 1. . END. Select Statement 3. END. 4. 3.EXECUTING Function: 1. END. . Begin :A:=F1('WELCOME').PUT_LINE(A). ANONYMOUS Block: DECLARE A VARCHAR2(10):='WELCOME'. 2.PUT_LINE(F1('Welcome')). EXEC: EXEC DBMS_OUTPUT. SELECT: SELECT F1('WELCOME TO APPS') FROM DUAL. BEGIN A:=F1('Welcome'). DBMS_OUTPUT. BIND Variable: VARIABLE A Varchar2(10). B NUMBER) RETURN NUMBER IS BEGIN RETURN a+b. ELSE RETURN 'ODD NUMBER'. . NOTE: If we want to return more number of values from Function we are using OUT parameter.2)=0 THEN RETURN 'EVEN NUMBER'.Ex2: Identifying a Number even or ODD. END. END IF. EX3: Addition of two Numbers CREATE OR REPLACE FUNCTION FUN3(A NUMBER. END. CREATE OR REPLACE Function FUN2(A NUMBER) RETURN VARCHAR2 IS Begin IF MOD(A. P_LOC FROM DEPT WHERE DEPTNO=P_DEPTNO. P_DNAME OUT VARCHAR2.:b.:C). print b. RETUN P_DNAME. end. variable b varchar2(10).LOC INTO P_DNAME. INOUT paramters: variable a varchar2(10). Write a PL/SQL stored function for passing empno as parameter return gross salary from emp table based on following condition? . END. OUT . begin :A=fun4(10. print c.Ex: CREATE OR REPLACE FUNCTION FUN4(P_DEPTNO IN NUMBER. P_LOC OUT VARCHAR2) RETURN VARCHAR2 IS BEGIN SELECT DNAME. Executing Functions with IN. PROGRAM: 1. variable c varchar2(10). If Annual Salary > 10000 then tax=10% 2. procedures. cannot be nested . hra=> 10% of Salary da => 20% of Salary pf => 10% of salary 2. cursors. --> Generally Packages are used to Improve performance of the Application . If Annual Salary > 50000 then tax=30% ************************************************************************************* ************************************************************************************* ************************************************************************************* ******************* --------PACKAGES ----------> Package is a Database Object which is used to encapsulate variables.date as parameter return number of years that employee is working based on date from emp table. calculate tax based on following conditions by using emp table. --> Package does not accept Parameters. functions. Condition: 1. Write a PL/SQL stored function for passing empno. cannot be Invoked. If Annual Salary > 20000 then tax=20% 3. Write a PL/SQL stored function for passing empno as parameter . 3.Condition==> gross:=basic+hra+da+pf. types in to Single Unit. constants. because when we are calling packaged subprogram first time total package is automatically loaded into memory area. PROCEDURE DECLARATION. --> Whenever we are calling Subsequent sub program calls pl/sql run time engine calling those sub program from memory area. Package Body --> In package Specification we are defining global data and also declare objects. --> This Process automatically reduces disk I/O that's why package improves performance of the application --> Packages have two Sections: 1. FUNCTION DECLARATION. CONSTANT DECLARATION. sub programs where as in Package body we are implementing sub programs and also package body sub program internally behaves like a private sub program. TYPES DECLARATION. . Package Specification 2. Package Specification Syntax: CREATE OR REPLACE PACKAGE PACKAGE_NAME IS/AS GLOBAL VERIABLE DECLARATION. CURSOR DECLARATION. EXEC Package_Name. END. . Package Body Syntax: CREATE OR REPLACE PACKAGE BODY PACKAGE_NAME IS/AS PROCEDURE IMPLEMENTATION. Select Package_Name.Procedure_Name(Actual PARAMETERS).Function_Name(Actual PARAMETERS) from DUAL. PROCEDURE P2.END. EX1: CREATE OR REPLACE PACKAGE P1 IS PROCEDURE P1. Invoking Packaged Subprograms: 1. 2. FUNCTION IMPLEMENTATION. PUT_LINE("PROCEDURE P1").PROCEDURE NAME) EX2: CREATE OR REPLACE PACKAGE PACK1 IS . --> To execute one object from Package we have to execute in the way mentioned below. (PACKAGE NAME. EXEC PACK1.END. END P1.PUT_LINE("PROCEDURE P2") END P2.P1. PROCEDURE P2 BEGIN DBMS_OUTPUT. --> We can execute only one object from a Package at a time. CREATE OR REPLACE PACKAGE BODY PACK1 IS PROCEDURE P1 BEGIN DBMS_OUTPUT. END PACK1. BEGIN . C OUT NUMBER).PUT_LINE(Z). PROCEDURE P2(X NUMBER. CREATE OR REPLACE PACKAGE BODY PACK1 IS PROCEDURE P1(A NUMBER. END PACK1. BEGIN Z:=X-Y. B NUMBER.PROCEDURE P1(A NUMBER. Y NUMBER) IS Z NUMBER(5). B NUMBER. DBMS_OUTPUT. SET SERVEROUTPUT ON. Y NUMBER). END P1. PROCEDURE P2(X NUMBER. END P2. DECLARE C NUMBER(5). END. C OUT NUMBER) IS BEGIN C:=A+B. Function) and implement with in the program only. exec PACK1.20.PUT_LINE(C). function f1(a number) return number. . Package Specification: Eg: Create or replace package pack1 is g number(5):=500.P2(20. END. SET SERVEROUTPUT ON.10). procedure p1. end.PACK1.P1(10.C). DBMS_OUTPUT. --> Global Variables & Local Variables: --------------------------------------GLOBAL VARIABLE: --> It is one of the variable which is used to define in package Specification and implement in Package body that variables are called as Global Variable. LOCAL VARIABLE: --> It is one of the variable which is used to define in programs (Procedures. . --> PROCEDURE OVERLOADING: ---------------------------> Overloading refers to same name can be used for different purpose. -->Those Procedures which have same name but different types of Arguments are called as function Overloading.Package Body: Ex: create or replace package body pack1 is procedure p1 is z number(5). z:=g/2. // z is local variable of procedure p1 end p1. end f1.put_line(z). function f1(a number ) return number is begin return a*g. -->We are implementing overloading procedures through packages only. end. // g is Global variable dbms_output. B NUMBER). Y NUMBER). CREATE OR REPLACE PACKAGE BODY PACK4 IS PROCEDURE P1(A NUMBER. BEGIN Z:=X*Y. DBMS_OUTPUT. BEGIN C:=A+B. END PACK4. B NUMBER) IS C NUMBER(5).EX: CREATE OR REPLACE PACKAGE PACK4 IS PROCEDURE P1(A NUMBER. END P1. END. . PROCEDURE P2(X NUMBER. END P1. DBMS_OUTPUT.PUT_LINE(C). Y NUMBER) IS Z NUMBER(5).PUT_LINE(Z). PROCEDURE P1(X NUMBER. PROCEDURE P1. //This is Local PROCEDURE called inside global procedure so declaring before the call & implementation.P1(A=>10. //Local proc called END P1.B=>20). CREATE OR REPLACE PACKAGE BODY PACK5 IS PROCEDURE P2. END.P1(X=>10. . O/P=30 EXEC PACK4. CREATE OR REPLACE PACKAGE PACK5 IS PROCEDURE P1. --> That means.EXECUTING: EXEC PACK4. O/P=200 -->Forward Declaration: -------------------------> Whenever we are calling procedures into another procedure then only we are using forward declaration. IS BEGIN P2.Y=>20). when we are calling local procedures into global procedure first we must implement local procedures before calling otherwise use a forward declaration in package body. Trigger Body is executed only once for DML statements. ************************************************************************************* ************************************************************************************* ************************************************************************************* ******************* -------TRIGGERS ---------> Triggers are also same as Stored Procedures. END. Triggers are automatically invoked whenever DML operations are performed against table or a view. Row Level Trigger ** In Row Level Trigger. Statement Level Trigger: ** In Statement Level Trigger .PUT_LINE('lOCAL procedure'). Trigger body is executed for each and every DML statements. . 2. --> There are Two Types of Triggers Supported by PL/SQL 1.PROCEDURE P2 //Implementing local proc IS BEGIN DBMS_OUTPUT. END P2. . --> Thats why generally statement level triggers used to define type based condition and also used to implement auditing reports.Syntax: CREATE {OR REPLACE} TRIGGER TRIGGER_NAME BEFORE/AFTER TRIGGER_EVENT INSERT or UPDATE or DELETE ON TABLE_NAME {for each row} {where condition} {DECLARE} variable declarations. After Row Level 4. After Statement Level 1. cursors BEGIN -----END EXECUTION ORDER IN TRIGGER: 1. Before Row Level 3. --> These triggers does not contain new. Trigger body is executed only once for each DML statement. Before Statement Level 2. Statement Level Trigger: -----------------------------> In Statement Level Trigger. old qualifiers. END.'SUN') THEN RAISE_APPLICATION_ERROR(-20123. . END IF. END IF. END.Q: Write a PL/SQL statement Level Trigger on EMPLOYEE table not to perform DML operations in saturday and sunday ? CREATE OR REPLACE TRIGGER TR1 BEFORE INSERT OR UPDATE OR DELETE ON EMPLOYEE BEGIN IF TO_CHAR(SYSDATE. 'WE CANNOT PERFORM DML OPERATIONS ON SAT AND SUN').').'DY') IN ('SAT'. 'WE CANNOT PERFORM DML OPERATIONS ON END OF THE MONTH. Q: Write a PL/SQL statement Level Trigger on EMPLOYEE table not to perform DML operations on Last day of Month? CREATE OR REPLACE TRIGGER TR2 BEFORE INSERT OR UPDATE OR DELETE ON EMPLOYEE BEGIN IF SYSDATE=LAST_DATE(SYSDATE) THEN RAISE_APPLICATION_ERROR(-20111. elseif deleting then statements. --> These ate Inserting . Updating . deleting clauses. --> These clauses are used in either row level or statement level triggers. Syntax: if inserting then statements. end if. elseif updating then statements. Q: Write a PL/SQL Statement Level Trigger on EMPLOYEE table not to perform any DML Operations in Any days using trigger event? CREATE OR REPLACE TRIGGER TR3 BEFORE UPDATE OR INSERT OR DELETE ON EMPLOYEE IS .--> Trigger Event (OR) Trigger Predicate Clauses: ----------------------------------------------> If you want to define Multiple conditions on Multiple tables then all database systems uses trigger events. CREATE OR REPLACE TRIGGER TR4 AFTER INSERT OR UPDATE OR DELETE ON TT DECLARE A VARCHAR2(50).'YOU ARE NOT SUPPOSED TO UPDATE THIS TABLE'). ELSIF DELETING THEN RAISE_APPLICATION_ERROR(20002. END IF.'YOU ARE NOT SUPPOSED TO INSERT INTO THIS TABLE'). BEGIN IF INSERTING THEN A:='ROWS INSERTED'. ELSIF UPDATING THEN RAISE_APPLICATION_ERROR(20001. Example for AFTER TRIGGER: ------------------------- CREATE TABLE TEST(MSG VARCHAR2(100)).IF INSERTING THEN RAISE_APPLICATION_ERROR(20000. .'YOU ARE NOT SUPPOSED TO DELETRE FROM THIS TABLE'). ELSIF DELETING THEN A:='ROW DELETED'. ELSIF UPDATING THEN A:='ROWS UPDATED'. -->when we are using these Modifiers in Trigger Body We must use Colon Prefix in the Qualifers. BEFORE VS AFTER TRIGGER:---------------------- . INSERT INTO TEST VALUES (A). -->Also data internally is stored in 2 Rollback segment qualifiers OLD & NEW -->These Qualifers are used in either Trigger specification or in Trigger Body.column_name -->When We are Using These Qualifiers in when clause we are not allowed to use colon in front of the Qualifers. Row Level Trigger: --------------------- --> In Row Level Trigger. -->That's why we are using for each row Clause in Trigger Specification. Syntax: --> :old. END.column_name (or) :new. Trigger Body is executed for each row of DML Statement. 2.END IF. END IF. --> Generally if we want to restrict invalid data entry always we are using before triggers. --> CREATE OR REPLACE TRIGGER T90 BEFORE INSERT ON EMP FOR EACH ROW BEGIN IF :NEW. Trigger body is executed after DML statements are effected into database. Those records also will be deleted if ON DELETE CASCASE is set ON. Q: Write a PL/SQL Row Level Trigger on EMP Table whenever user inserting data into a emp table salary should be more than 5000. Trigger body is executed before DML statements are effected into database. --> Whenever we are Inserting values into new Qualifiers we must use before Trigger otherwise Oracle Server returns an error.SAL<5000 THEN RAISE_APPLICATION_ERROR(-20123. where as if we are performing operation on the one table those operations are effected in another table then we are using after Trigger. .'SALARY SHOULD BE MORE THAN 5000').--> In Before Trigger . ON DELETE CASCADE: ------------------While deleting a record. END. --> In After Triggers. if there is dependency of that record in any other table. CREATE OR REPLACE TRIGGER T91 AFTER DELETE ON DEPT FOR EACH ROW BEGIN DELETE FROM EMP WHERE DEPTNO=:OLD. Q: Write a PL/SQL Row Level Trigger on DEPT table whenever updating deptno's in DEPT table automatically those deptno's modified into emp table.Q: Write a PL/SQL Row Level Trigger on EMP.DEPTNO WHERE DEPTNO=:OLD.DEPTNO. DEPT Tables for implementing on delete cascade concept. END. without using On DELETE cascade Clause. CREATE OR REPLACE TRIGGER T20 . CREATE OR REPLACE TRIGGER T19 AFTER UPDATE ON DEPT FOR EACH ROW BEGIN UPDATE EMP SET DEPTNO=:NEW.DEPTNO. Q: Write a PL/SQL Row Level Trigger Whenever user inserting data into ename column after inserting data must be converted into uppercase. END. END. 2.ename) values(:new. Whenever user Deleting data those values stored in another table? create table employee as EMP.ename) values(:old.:old. elseif updating then insert into employee(empno.empno.ENAME).empno. Whenever user Inserting data those values stored in another table. 3. //1st create one similar table create or replace trigger t1 after insert or delete or update on emp for each row begin if inserting then insert into employee(empno.:new.ENAME=UPPER(:NEW.BEFORE INSERT ON EMPLOYEE FOR EACH ROW BEGIN :NEW. Whenever user Updating data those values stored in another table.ename). Q: Write a PL/SQL Row Level Trigger on EMP table by using below Condition? 1. elseif deleting then .ename). ename) values(:old. whenever a record is deleted display the number of records available in the Table after the delete.ename). end if.insert into employee(empno.:old. CREATE OR REPLACE TRIGGER T1 AFTER DELETE ON EMP FOR EACH ROW DECLARE CNT INT. end.empno. Q: Write a PL/SQL Row Level Trigger on EMP table. BEGIN SELECT COUNT(*) INTO CNT FROM EMP.PUT_LINE("No of records now available in EMP table : "||CNT). END. DBMS_OUTPUT. MUTATING TRIGGER: ----------------- . ************************************************************************************* ************************************************************************************* ************************************************************************************* ******************* VVIP -----------COLLECTIONS ------------ 1. .e Value field is Stored in Actual Data and Key field Stored in Indexes. --> Basically These Table Contains Key Value Pairs. i. Basically this is an Non-constraint table. Varrays 5. --> Generally these tables are used to improve performance of applications because these tables are stored in Memory area thats why These tables are also called as Memory Tables. Index by Table (or) PL/SQL table (or) Associative Arrays 3. Ref Cursors -->INDEX BY TABLE: ---------------> This is an User defined type which is used to store Multiple data items to a Single Unit. Nested Tables 4. PL/SQL Record (or) Record Type 2. --> Key Field Values are either Integer or Character and also these values are either +ve or -ve. --> These Indexes key behaves like primary key, i.e does not accept duplicate and null values, basically this key datatype is binary_integer. --> Index by Table Having following COLLECTIONS Mrthods. 1. EXISTS 2. FIRST 3. LAST 4. PRIOR 5. NEXT 6. COUNT 7. DELETE(range of indexes) ////INDEX OF TABLE for NUMBER. Eg1: DECLARE TYPE T1 IS TABLE OF NUMBER(10) INDEX BY BINARY_INTEGER; V_T T1; BEGIN V_T(1):=10; V_T(2):=20; V_T(3):=30; V_T(4):=40; V_T(5):=50; DBMS_OUTPUT.PUT_LINE(V_T(3)); DBMS_OUTPUT.PUT_LINE(V_T.first); DBMS_OUTPUT.PUT_LINE(V_T.last); DBMS_OUTPUT.PUT_LINE(V_T.prior(3)); DBMS_OUTPUT.PUT_LINE(V_T.next(4)); DBMS_OUTPUT.PUT_LINE(V_T.count); DBMS_OUTPUT.PUT_LINE(V_T(5)); END; Eg2: DECLARE TYPE T1 IS TABLE OF NUMBER(10) INDEX BY BINARY_INTEGER; V_T T1; BEGIN V_T(1):=10; V_T(2):=20; V_T(3):=30; V_T(4):=40; V_T(5):=50; DBMS_OUTPUT.PUT_LINE(V_T.count); V_T.DELETE(2,3); //Will Delete 2nd to 3rd Record. DBMS_OUTPUT.PUT_LINE(V_T.count); V_T.DELETE; //Will Delete all records, if index is not specified. DBMS_OUTPUT.PUT_LINE(V_T.count); V_T.DELETE(1); //Will Delete 1st record DBMS_OUTPUT.PUT_LINE(V_T.count); V_T.DELETE(1,3); //Will Delete 1st to third record END; //INDEX OF TABLE for VARCHAR. WRITE A PL/SQL PROGRAM TO GET ALL EMPLOYEE NAMES FROM EMP TABLE AND STORE IT INTO INDEX BY TABLE AND DISPLAY DATA FROM INDEX BY TABLE? SOLUTION: DECLARE TYPE T1 IS TABLE OF VARCHAR2(10) INDEX BY BINARY_INTEGER; V_T T1; BEGIN FOR I IN 1..10 LOOP FIRST. END LOOP. EXIT WHEN C1%NOTFOUND. DECLARE TYPE T1 IS TABLE OF VARCHAR2(10) INDEX BY BINARY_INTEGER.V_T.LAST LOOP DBMS_OUTPUT.PUT_LINE(V1(I)). V_T T1. END.!! We Use FOR LOOP because in FOR LOOP. END LOOP.. close Cursor or Initialise variable. END LOOP. we dont have to Open Cursor. END.. FOR I IN V1. CLOSE C1. //Above same Programm can be Implemented Using FOR LOOP.LAST LOOP DBMS_OUTPUT.V1. FOR I IN V_T. N:=N+1.FETCH C1 INTO V_T(N). .PUT_LINE(V_T(1)).. BEGIN SELECT ENAME BULK COLLECT INTO V1 FROM EMP.FIRST. BEGIN SELECT HIREDATE BULK COLLECT INTO V1 FROM EMP.. . V_T T1.V_T. FOR I IN V_T. END LOOP.FIRST. DECLARE TYPE T1 IS TABLE OF DATE INDEX BY BINARY_INTEGER. END. BEGIN FOR I IN 1.LAST LOOP DBMS_OUTPUT.//INDEX OF TABLE for DATE.PUT_LINE(V_T(I)). V_T T1. END LOOP. DECLARE TYPE T1 IS TABLE OF DATE INDEX BY BINARY_INTEGER..10 LOOP V_T(I):=SYSDATE+1. V_T. //INDEX BY VARCHAR2 .LAST LOOP DBMS_OUTPUT.FIRST..PUT_LINE(V_T(I)). END.FOR I IN V_T. END LOOP.
Copyright © 2024 DOKUMEN.SITE Inc.