In this section, we will talk about constants and literals in PL/SQL. A consistent holds a worth that once announced, doesn't change in the program. A steady revelation determines its name, information type, and esteem, and distributes stockpiling for it. The affirmation can likewise force the NOT NULL limitation.
Declaring a Constant
A consistent is pronounced utilizing the CONSTANT watchword. It requires an underlying worth and doesn't permit that incentive to be changed. For instance −
PI CONSTANT NUMBER := 3.141592654;
DECLARE
-- constant declaration
pi constant number := 3.141592654;
-- other declarations
radius number(5,2);
dia number(5,2);
circumference number(7, 2);
area number (10, 2);
BEGIN
-- processing
radius := 9.5;
dia := radius * 2;
circumference := 2.0 * pi * radius;
area := pi * radius * radius;
-- output
dbms_output.put_line('Radius: ' || radius);
dbms_output.put_line('Diameter: ' || dia);
dbms_output.put_line('Circumference: ' || circumference);
dbms_output.put_line('Area: ' || area);
END;
/
At the point when the above code is executed at the SQL brief, it delivers the accompanying outcome −
Radius: 9.5
Diameter: 19
Circumference: 59.69
Area: 283.53
Pl/SQL procedure successfully completed.
The PL/SQL Literals
An exacting is an express numeric, character, string, or Boolean worth not addressed by an identifier. For instance, TRUE, 786, NULL, 'tutorialspoint' are generally literals of type Boolean, number, or string. PL/SQL, literals are case-delicate. PL/SQL underpins the accompanying sorts of literals −
- Numeric Literals
- Character Literals
- String Literals
- BOOLEAN Literals
- Date and Time Literals
The accompanying table gives models from every one of these classifications of strict qualities.
S.No | Literal Type & Example |
---|---|
1 |
Numeric Literals 050 78 -14 0 +32767 6.6667 0.0 -12.0 3.14159 +7800.00 6E5 1.0E-8 3.14159e0 -1E38 -9.5e-3 |
2 |
Character Literals 'A' '%' '9' ' ' 'z' '(' |
3 |
String Literals 'Hello, world!' 'Tutorials Point' '19-NOV-12' |
4 |
BOOLEAN Literals TRUE, FALSE, and NULL. |
5 |
Date and Time Literals DATE '1978-12-25'; TIMESTAMP '2012-10-29 12:01:01'; |
To insert single statements inside a string strict, place two single statements close to one another as demonstrated in the accompanying system −
DECLARE
message varchar2(30):= 'That''s tutorialspoint.com!';
BEGIN
dbms_output.put_line(message);
END;
/
At the point when the above code is executed at the SQL brief, it delivers the accompanying outcome −
That's tutorialspoint.com!
PL/SQL procedure successfully completed.