0% found this document useful (0 votes)
38 views10 pages

PL/SQL PPT2

Variables can be used for temporary storage, data manipulation, reusability, and ease of maintenance in PL/SQL. There are scalar, composite, and reference variables as well as LOB variables. Bind variables allow passing runtime values into or out of PL/SQL programs from a host environment like SQL*Plus. Comments can be single-line with two dashes or multiple-line between /* and */ to document code. Functions and operators are available in PL/SQL for calculations.

Uploaded by

Pravesh Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views10 pages

PL/SQL PPT2

Variables can be used for temporary storage, data manipulation, reusability, and ease of maintenance in PL/SQL. There are scalar, composite, and reference variables as well as LOB variables. Bind variables allow passing runtime values into or out of PL/SQL programs from a host environment like SQL*Plus. Comments can be single-line with two dashes or multiple-line between /* and */ to document code. Functions and operators are available in PL/SQL for calculations.

Uploaded by

Pravesh Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

USE OF VARIABLES

Variables can be used for:

1- Temporary storage of data. 2- Manipulation of stored data. 3- Reusability. 4- Ease of maintenance.

1- PL/SQL Variables : - Scalar - Composite - Reference - LOB(large objects) 2- Non-PL/SQL variables : Bind and Host variables

Declaring PL/SQL variables


SYNTAX : identifier [constant] datatype [NOT NULL] [:= | DEFAULT expression]; EXAMPLE : DECLARE v_hiredate date; v_deptno number(2) not null :=10; v_location varchar2(13):=Atlants;

BIND VARIABLES
A bind variable is a variable that you declare in a host environment. Bind variable can be used to pass run-time values, either number or character , into or out of one or more PL/SQL program.

Creating BIND VARIABLES


To declare bind variable in the ISQL*Plus environment, use the command VARIABLE. For example, you declare a variable of type number and varchar2 as follows : VARIABLE return_code NUMBER VARIABLE return_msg VARCHAR2

Using Bind Variable


To reference a bind variable in PL/SQL , you must prefix its name colon(:). EXAMPLE :
VARIABLE
BEGIN SELECT INTO FROM WHERE END; /

g_salary NUMBER
salary :g_salary employees employee_id=178;

DBMS_OUTPUT.PUT_LINE
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
SET SERVEROUTPUT ON DEFINE 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; /

IDENTIFIERS
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 column name. Should not be reserved words

COMMENTING CODE
Prefix single-line comments with two dashes (--) Place multiple-line comments between the symbols /* and */
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.

SQL Functions in PL/SQL


Available in procedural statements -- Single-row number -- Single-row character -- Data type conversion -- Date -- Timestamp Not available in procedural statements -- DECODE -- Group Functions

OPERATORS IN PL/SQL
LOGICAL ARITHMETIC CONCATENATION PARENTHESES TO CONTROL ORDER OF OPERATIONS EXPONENTIAL OPERATOR (**)

You might also like