PL/SQL “constant”

By Brian Fitzgerald

The procedure-scoped PL/SQL “constant” can have a different value each call. The documentation says as much: “Constants are initialized every time a block or subprogram is entered.”

[oracle@stormking db12201 plsql]$ cat runtime.constant.sql
create or replace procedure pr
(
 p in number,
 o out number
)
is
 c constant number := p;
begin
 o := c;
end pr;
/

variable o number

exec pr ( 1, :o )
print :o

exec pr ( 2, :o )
print :o
quit
[oracle@stormking db12201 plsql]$ sqlplus u/u @ runtime.constant.sql
SQL*Plus: Release 12.2.0.1.0 Production on Tue Feb 6 23:28:32 2018
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Last Successful login time: Tue Feb 06 2018 23:27:25 -05:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Procedure created.
PL/SQL procedure successfully completed.
O
----------
 1
PL/SQL procedure successfully completed.
O
----------
 2
Disconnected from Oracle Database 12c Enterprise Edition 
Release 12.2.0.1.0 - 64bit Production

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s