• Skip to primary navigation
  • Skip to main content

Tech Honey

The #1 Website for Oracle PL/SQL, OA Framework and HTML

  • Home
  • HTML
    • Tags in HTML
    • HTML Attributes
  • OA Framework
    • Item in OAF
    • Regions in OAF
    • General OAF Topics
  • Oracle
    • statement
    • function
    • clause
    • plsql
    • sql

plsql

Declaring Variables in Oracle PLSQL

November 22, 2012 by techhoneyadmin

A variable, by definition, is a name given to a memory space.

In Oracle PLSQL a variable allows a programmer to store the needed data / values in variables while the program is being executed.

The Syntax for declaring a variable in Oracle PLSQL is:
variable_name [CONSTANT] data_type [NOT NULL] [:= DEFAULT initial value]

For example we can create a variable named ‘websitename’ in Oracle PLSQL as:

view source
print?
1websitename VARCHAR2(100);

In the above statement we have just created a variable but the variable doesn’t have anything stored in it. We can assign a value to the above created ‘websitename’ variable as:

view source
print?
1websitename := 'Website Name Is techhoney.com';

We can merge the two steps above and can create a variable along with assigning some value to it in a single statement as:

view source
print?
1websitename VARCHAR2(100) := 'Website Name Is techhoney.com';

Later we can change the value of ‘websitename’ variable to something else e.g.

view source
print?
1websitename := 'This is just a test';

Here we should understand that we have created a variable and not a constant; in case of constant the value assigned to it cannot be changed.

Below is an example is to create a constant in Oracle PLSQL:

view source
print?
1grandTotal CONSTANT NUMERIC(10,1) := 123.456;

Note: Once assigned, the value of a constant cannot be changed.


Filed Under: plsql Tagged With: Declaring Variables and Constants in oracle database query, Declaring Variables and Constants in oracle plsql, Declaring Variables and Constants in oracle sql, DECLARINGVARIABLESPLSQL, how to Declare Variables and Constants in oracle database query, how to Declare Variables and Constants in oracle plsql, how to Declare Variables and Constants in oracle sql, syntax and example of Declaring Variables and Constants in oracle database query, syntax and example of Declaring Variables and Constants in oracle plsql, syntax and example of Declaring Variables and Constants in oracle sql

Literals in Oracle PLSQL

November 22, 2012 by techhoneyadmin

Basically in Oracle SQL / PLSQL a literal is same as constant.

Let’s see few types of literals.

  1. Text Literals
  2. Integer Literals
  3. Number Literals

Text Literals:-
Text literals in oracle plsql are always surrounded by single quotes (‘) e.g.
‘tech honey’
‘oracle’
‘plsql’
‘January 1, 2012’

Integer Literals:
Integer Literals in oracle plsql can be up to 38 digits long, they can be either positive or negative numbers. If no sign is specified then oracle plsql assume the literal to be positive. Some examples of Integer literals are:
20
+20
-20

Number Literals:
Number Literals in oracle plsql can be up to 38 digits long, they can be either positive or negative numbers. If no sign is specified then oracle plsql assume the literal to be positive. Some examples of Number literals are:
20
+20
-20
20e-4
20.0020


Filed Under: plsql Tagged With: how to use Literals in oracle database query, how to use Literals in oracle plsql, how to use Literals in oracle sql, Literals in oracle plsql, Literals in oracle sql, LITERALSPLSQL, syntax and example of Literals in oracle database query, syntax and example of Literals in oracle plsql, syntax and example of Literals in oracle sql, using Literals in oracle database query, using Literals in oracle plsql, using Literals in oracle sql

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 3
  • Page 4
  • Page 5

Copyright © 2025 · Parallax Pro on Genesis Framework · WordPress · Log in