Summary of "PL/SQL tutorial 2 : PL/SQL Variables in Oracle Database By Manish Sharma RebellionRider"
Overview
- The video explains PL/SQL variables: what they are, how to declare them, and different ways to initialize them.
- Key points:
- Variables are named memory placeholders with a data type (and width when applicable).
- Variables must be declared before use (in the
DECLAREsection of a PL/SQL block). - Initialization (assigning a value) can be done in the
DECLAREsection, in the executable (BEGIN) section, or in theEXCEPTIONsection. - Use
DBMS_OUTPUT.PUT_LINEto display a variable’s value; runSET SERVEROUTPUT ONin your client (e.g., SQL Developer) to see output.
Detailed concepts and rules
What a variable is
- A variable is a named placeholder in memory that holds data which can change.
- Each variable requires:
- a valid name,
- a data type,
- a data width/size (where applicable).
- On declaration the compiler validates the signature and allocates memory according to the data type.
Where to declare variables
- Variables must be declared in the
DECLAREsection of a PL/SQL block. - Example PL/SQL block structure:
SET SERVEROUTPUT ON;
DECLARE
-- variable_declarations...
BEGIN
-- executable_statements...
EXCEPTION
-- exception_handlers...
END;
/
Declaration syntax (examples)
- Basic declaration (no initial value):
v_test VARCHAR2(15);
- Declaration with direct initialization:
v_test VARCHAR2(15) := 'RebellionRider';
- Each declaration ends with a semicolon.
Assignment / initialization
- The assignment operator in PL/SQL is
:=(colon equals), not=. - String literals must use single quotes, e.g.
'RebellionRider'. -
Initialization can occur:
- In the
DECLAREsection (direct initialization with:=). -
In the executable (
BEGIN) section:plsql v_test := 'RebellionRider'; -
In the
EXCEPTIONsection (if needed for handling). - You must declare the variable before you initialize or use it.
- In the
Example: initialize and print in the execution section
SET SERVEROUTPUT ON;
DECLARE
v_test VARCHAR2(15);
BEGIN
v_test := 'RebellionRider';
DBMS_OUTPUT.PUT_LINE(v_test);
END;
/
- Run
SET SERVEROUTPUT ONbefore executing this block to see the output in the client console.
Displaying output
- Use
DBMS_OUTPUT.PUT_LINE(<variable_or_text>)to print to the session output. - Ensure your client has server output enabled (e.g.,
SET SERVEROUTPUT ONin SQL*Plus or SQL Developer).
Additional notes
- The video calls assigning a literal value in the
DECLAREsection “direct initialization.” - A future tutorial will show how to fetch values from database tables into variables.
- The demo used Oracle SQL Developer, but any PL/SQL-capable client will work.
Speakers / sources featured
- Presenter: Manish (from RebellionRider / rebellionrider.com)
- Tools and Oracle features referenced:
- Oracle
DBMS_OUTPUTpackage (DBMS_OUTPUT.PUT_LINE) SET SERVEROUTPUT ONcommand- Oracle SQL Developer (demo client)
- Oracle
Category
Educational
Share this summary
Is the summary off?
If you think the summary is inaccurate, you can reprocess it with the latest model.
Preparing reprocess...