Upload
pravesh-kumar
View
220
Download
0
Embed Size (px)
Citation preview
7/27/2019 PL/SQL PPT2
http://slidepdf.com/reader/full/plsql-ppt2 1/10
Variables can be used for:
1- Temporary storage of data.
2- Manipulation of stored data.
3- Reusability.
4- Ease of maintenance.
USE OF VARIABLES
7/27/2019 PL/SQL PPT2
http://slidepdf.com/reader/full/plsql-ppt2 2/10
1- PL/SQL Variables :
- Scalar- Composite
- Reference
- LOB(large objects)2- Non-PL/SQL variables :
Bind and Host variables
7/27/2019 PL/SQL PPT2
http://slidepdf.com/reader/full/plsql-ppt2 3/10
SYNTAX :identifier [constant] datatype [NOT NULL] [:= |
DEFAULT expression];
EXAMPLE :
DECLAREv_hiredate date;v_deptno number(2) not null :=10;v_location varchar2(13):=‘Atlants’;
Declaring PL/SQL variables
7/27/2019 PL/SQL PPT2
http://slidepdf.com/reader/full/plsql-ppt2 4/10
A bind variable is a variable that you declare in ahost environment. Bind variable can be used to passrun-time values, either number or character , into orout of one or more PL/SQL program.
Creating BIND VARIABLESTo declare bind variable in the ISQL*Plus
environment, use the command VARIABLE. Forexample, you declare a variable of type number andvarchar2 as follows :
VARIABLE return_code NUMBER
VARIABLE return_msg VARCHAR2
BIND VARIABLES
7/27/2019 PL/SQL PPT2
http://slidepdf.com/reader/full/plsql-ppt2 5/10
To reference a bind variable in PL/SQL , you must prefixits name colon(:).
EXAMPLE :
Using Bind Variable
VARIABLE g_salary NUMBER
BEGINSELECT salaryINTO :g_salaryFROM employeesWHERE employee_id=178;
END;/
7/27/2019 PL/SQL PPT2
http://slidepdf.com/reader/full/plsql-ppt2 6/10
► A Oracle-supplied packaged procedure
► An alternative for displaying data from a PL/SQL block
► Must be enabled in ISQL*Plus with: set serveroutput on
DBMS_OUTPUT.PUT_LINE
SET SERVEROUTPUT ONDEFINE p_annual_sal =60000
DECLARE
v_sal NUMBER(9,2) :=&p_annual_sal;BEGIN
v_sal:=v_sal/12;DBMS_OUTPUT.PUT_LINE(‘The monthly salary is’||TO_CHAR(V_sal));
END;/
7/27/2019 PL/SQL PPT2
http://slidepdf.com/reader/full/plsql-ppt2 7/10
Identifiers are used to name PL/SQL program items and units ,which includes constant , variables , exceptions , cursor variable ,subprograms and packages.
Can contain up to 30 characters
Must begin with an alphabetic character
Can contain numerals , dollar sign , underscores , and number
sign.Cannot contain characters such as hyphens , slashes , and spaces.
Should not have the same name as a database table columnname.
Should not be reserved words
IDENTIFIERS
7/27/2019 PL/SQL PPT2
http://slidepdf.com/reader/full/plsql-ppt2 8/10
► Prefix single-line comments with two dashes (--)
► Place multiple-line comments between the symbols
/* and */
COMMENTING CODE
EXAMPLE :-DECLARE……………..
v_sal NUMBER(9,2);BEGIN/* Compute the annual salary based on the monthly salary
input from the user*/v_sal := :g_monthly_sal*12;
END; -- This is the end of the block.
7/27/2019 PL/SQL PPT2
http://slidepdf.com/reader/full/plsql-ppt2 9/10
Available in procedural statements
-- Single-row number-- Single-row character
-- Data type conversion
-- Date
-- TimestampNot available in procedural statements
-- DECODE
-- Group Functions
SQL Functions in PL/SQL
7/27/2019 PL/SQL PPT2
http://slidepdf.com/reader/full/plsql-ppt2 10/10
■ LOGICAL
■ ARITHMETIC
■ CONCATENATION
■ PARENTHESES TO CONTROL ORDEROF OPERATIONS
■ EXPONENTIAL OPERATOR (**)
OPERATORS IN PL/SQL