SlideShare a Scribd company logo
DBMS_SQL Revisited


       The DBMS_SQL package supplied by Oracle Corporation is a powerful tool to
evaluate and execute dynamic SQL expressions. The single most important component
of the dbms_sql package is the dbms_sql.parse procedure. In previous releases of the
RDBMS, the parse procedure was limited to 2000 characters. In the latest release of the
RDBMS, this procedure has been overloaded to a table of varchar2, thus setting no limit
on the size of the dynamic SQL. This article will demonstrate the use of this packaged
procedure and in addition will explain a method for executing anonymous PL/SQL blocks
and extracting the result from the block to the calling program.


New Overloaded Procedure dbms_sql.parse:

Description of dbms_sql.parse from Oracle RDBMS 7.3.3.3.0

SQL> desc dbms_sql.parse
PROCEDURE dbms_sql.parse
Argument                             NameType            In/Out Default?
------------------------------ -----------------------   ---------------
C                                   NUMBER(38)                    IN
STATEMENT                           VARCHAR2                      IN
LANGUAGE_FLAG                       NUMBER(38)                    IN
PROCEDURE dbms_sql.parse
Argument Name                     Type                            In/Out Default?
------------------------------ -----------------------            ------ --------
C                                   NUMBER(38)                    IN
STATEMENT                           TABLE OF VARCHAR2(256)        IN
LB                                  NUMBER(38)                    IN
UB                                  NUMBER(38)                    IN
LFFLG                               BOOLEAN                       IN
LANGUAGE_FLAG                      NUMBER(38)                     IN




Fig1: Description of dbms_sql.parse
Note that the table of varchar2 is actually a type of dbms_sql.varchar2s which is
defined in dbmssql.sql in $ORACLE_HOME/rdbms/admin as follows:
type varchar2s is table of varchar2(256) index by binary integer;
c is an integer and holds the familiar cursor handle.
LB denotes the lower bound of the PL/SQL table and UB denotes the upper bound of the
PL/SQL table. That is, a PL/SQL table of varchar2(256) could hold many lines of code,
but they can be selectively parsed and executed using these variables. That is one could
specify LB as 3 and UB as 7 and the SQL code in the PL/SQL table from 3 to 7 will be
parsed and executed. Conceptually, the SQL string is put together as follows:
string:=statement(lb) || statement (lb+1) ||…||statement(ub); .
If LFFLG which is a Boolean variable is set to true, then a new line is inserted after each
piece. This is strongly recommended due to the following reason. When building large
chunks of code, a line of PL/SQL code cannot exceed 2000 characters and the PL/SQL
compiler wraps it to accomplish it. The reason this happens is that all database source
code is stored in dba_source view and its underlying table and in the text column of that
table and is limited to 2000 characters.


       Now users can build a PL/SQL table and specify the upper and lower boundary of
the table as input arguments to dbms_sql.parse instead of the previous varchar2 thus
surpassing the 2000 characters limitation. This is particularly useful when evaluating
complicated business rules and expressions.


Use of the New version of dbms_sql.parse:


       The code that follows demonstrates the usage of the dbms_sql.parse procedure.
Before we demonstrate use of this procedure, we will create a packaged variable and a
function to retrieve that variable. This will be used to demonstrate the use of extracting
the value from an anonymous PL/SQL block using dbms_sql.
Create or Replace package myvar as
Pragma restrict_references(myvar,WNDS,WNPS,RNDS, RNPS);
result number;
end myvar;

Fig 2: Source Code for myvar package


       A discerning user will notice that the package has been subjected to a Pragma
restrict_reference restriction. This is due to the following reason. A function which
retrieves the value of the variable will otherwise return the familiar ORA-06571 error
which is, “Function %s does not guarantee not to update database”.


       Now we will demonstrate the function which will retrieve the value of the
packaged variable.


Create or replace function check_calc
return number is
begin
return myvar.result;
end;

Fig 3: Source Code for the check_calc package.


       Note that the function merely reads the myvar.result package variable and returns
it back to the calling program.


       In this example we will create a table of varchar2, and create an anonymous
PL/SQL block and declare two variables A and B. We will assign them some arbitrary
values and then pass an expression as an argument to the procedure. This expression
could be any valid PL/SQL expression not exceeding 256 characters.             The task of
evaluating expressions greater than 256 characters is left as an exercise to the discerning
reader and just reduces to breaking up a character string greater than 256 characters into
multiple pieces of 256 characters and then appending it to the PL/SQL table.
Note that A and B could be assigned values by any valid SQL function which can
be user defined and hence A and B can be assigned dynamically too. This is not done
here for the sake of simplicity. For example, A and B could well be the age and gender of
an individual stored in a database and very well could be as follows:
a:=getage(855855855);
b:=getgender(855855855);
where 855855855 uniquely identifies an individual in a database table.


        In fact, even the above two statements could be generated dynamically if the
information is stored in a table. It should also be noted that is these attributes are stored
in a database, once could potentially generate the statements in the anonymous PL/SQL
block. The following piece of code demonstrates the use of the new overloaded version
of dbms_sql.parse.


        Note that the anonymous PL/SQL block updates a package variable, which is
available throughout the session. Examples of dbms_sql.parse with the three arguments
abound in Oracle literature and accessing data through define_column procedure and
column_value procedure.       The limitation of dbms_sql.parse with three arguments is
already know. Define_column and column_value is fine when one has to access database
data and cursor data respectively. The packaged variable method does not require use of
these procedures and their limitations if any.


        Note that even though sqlstring is a table of varchar2(256), it should be casted as
dbms_sql.varchar2s.     The following section of code demonstrates the use of the new
dbms_sql.parse and the use of the packaged variable and its associated function which
retrieves it.


        The good thing about anonymous PL/SQL blocks is that, they don‟t need to be
wrapped in procedures/functions/packages thus causing DDL issues.
create or replace procedure democalc
(
calc_text in varchar2, //* The calculation string for example: “result:=A*B;”
return_result in out number,
retval in out number
)
IS


sqlstring dbms_sql.varchar2s; /* Created to hold the PL/SQL Block */
cursor1 integer;
i, j integer;
new_line_flag BOOLEAN:=TRUE;

BEGIN

sqlstring(1):='declare ';
sqlstring(2):='result number(38,2):=0.0;';
sqlstring(3):='a number(38,2):=2;';
sqlstring(4):='b number(38,2):=3;';
sqlstring(5):='begin';
sqlstring(6):=calc_text;
sqlstring(7):='myvar.result:=result;';
sqlstring(8):='end;';
 i=1;
j=8;

cursor1:=dbms_sql.open_cursor;
dbms_sql.parse(cursor1,sqlstring,i,j,new_line_flag,DBMS_SQL.V7);
retval:=dbms_sql.execute(cursor1);
dbms_sql.close_cursor(cursor1);
return_result:=check_calc;


END;
/
The following section demonstrates the execution of the democalc procedure.


 SQL> set serveroutput on
 SQL> declare
       temp1 number; temp2 number;
       begin
        democalc(„result:=A*P;‟, temp1,temp2);
        dbms_output.put_line(„The result is „||temp1);
       end;
       /
 The result is 6
 SQL>



Conclusions:
               The new overloaded version of dbms_sql.parse obviates the previous limit
of the dbms_sql and provides even more flexibility to the developer.   A system which
provides a framework to evaluate simple, dynamic PL/SQL expressions and which uses
the above version of dbms_sql.parse is in development at an Oracle client site by Oracle
consulting and is expected to go live soon.


Acknowledgements:
               The brilliant idea of using packaged variables to exchange values from
anonymous PL/SQL blocks was suggested by an Oracle Technical manager, Roger Raj.


About the Author:
               Mahesh Vallampati is a senior consultant with the Oracle National
Telecom practice, Oracle Corporation. Though he is a DBA by profession, occasionally
he is called on by Oracle customers for his PL/SQL expertise which he dabbles in. He
can be reached at his convenience at mvallamp@us.oracle.com.

More Related Content

What's hot

Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
Srinimf-Slides
 
ORACLE PL SQL
ORACLE PL SQLORACLE PL SQL
ORACLE PL SQL
Srinath Maharana
 
Mainframe refresher-part-1
Mainframe refresher-part-1Mainframe refresher-part-1
Mainframe refresher-part-1vishwas17
 
Oracle PL/SQL online training | PL/SQL online Training
Oracle PL/SQL online training | PL/SQL online TrainingOracle PL/SQL online training | PL/SQL online Training
Oracle PL/SQL online training | PL/SQL online Training
suresh
 
10g plsql slide
10g plsql slide10g plsql slide
10g plsql slideTanu_Manu
 
PLSQL
PLSQLPLSQL
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
Pooja Dixit
 
Pl sql content
Pl sql contentPl sql content
Pl sql content
MargaretMaryT
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
Nick Buytaert
 
PLSQL Tutorial
PLSQL TutorialPLSQL Tutorial
PLSQL Tutorial
Quang Minh Đoàn
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
Bharat Kalia
 
4. plsql
4. plsql4. plsql
4. plsql
Amrit Kaur
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
Ñirmal Tatiwal
 
SQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update featureSQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update feature
Frans Jongma
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management System
sweetysweety8
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-onlyAshwin Kumar
 
Advanced plsql mock_assessment
Advanced plsql mock_assessmentAdvanced plsql mock_assessment
Advanced plsql mock_assessment
Saurabh K. Gupta
 
Oracle db subprograms
Oracle db subprogramsOracle db subprograms
Oracle db subprogramsSimon Huang
 

What's hot (20)

Oracle etl openworld
Oracle etl openworldOracle etl openworld
Oracle etl openworld
 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
 
ORACLE PL SQL
ORACLE PL SQLORACLE PL SQL
ORACLE PL SQL
 
Mainframe refresher-part-1
Mainframe refresher-part-1Mainframe refresher-part-1
Mainframe refresher-part-1
 
Oracle PL/SQL online training | PL/SQL online Training
Oracle PL/SQL online training | PL/SQL online TrainingOracle PL/SQL online training | PL/SQL online Training
Oracle PL/SQL online training | PL/SQL online Training
 
10g plsql slide
10g plsql slide10g plsql slide
10g plsql slide
 
PLSQL
PLSQLPLSQL
PLSQL
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
 
Pl sql content
Pl sql contentPl sql content
Pl sql content
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
 
PLSQL Tutorial
PLSQL TutorialPLSQL Tutorial
PLSQL Tutorial
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
4. plsql
4. plsql4. plsql
4. plsql
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
 
SQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update featureSQL/MX 3.6 Select for update feature
SQL/MX 3.6 Select for update feature
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management System
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
 
Advanced plsql mock_assessment
Advanced plsql mock_assessmentAdvanced plsql mock_assessment
Advanced plsql mock_assessment
 
Oracle db subprograms
Oracle db subprogramsOracle db subprograms
Oracle db subprograms
 

Viewers also liked

Sql
SqlSql
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
Raji Ghawi
 
PL/SQL
PL/SQLPL/SQL
PL/SQL
Vaibhav0
 
Jena Programming
Jena ProgrammingJena Programming
Jena Programming
Myungjin Lee
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
Introduction to Business Statistics
Introduction to Business StatisticsIntroduction to Business Statistics
Introduction to Business Statistics
Atiq Rehman
 
Introduction to Business Statistics
Introduction to Business StatisticsIntroduction to Business Statistics
Introduction to Business StatisticsMegha Mishra
 
Business Statistics
Business StatisticsBusiness Statistics
Business Statistics
shorab
 
Dynamic SQL in doobie
Dynamic SQL in doobieDynamic SQL in doobie
Dynamic SQL in doobie
chibochibo
 
Selecting best NoSQL
Selecting best NoSQL Selecting best NoSQL
Selecting best NoSQL
Mohammed Fazuluddin
 
Passivhus nordvest
Passivhus nordvestPassivhus nordvest
Passivhus nordvest
Bertel Bolt-Jørgensen
 
Seniorforsker Uffe Jørgensen; Aarhus Universitet
Seniorforsker Uffe Jørgensen; Aarhus UniversitetSeniorforsker Uffe Jørgensen; Aarhus Universitet
Seniorforsker Uffe Jørgensen; Aarhus Universitet
Bertel Bolt-Jørgensen
 
Roll Over Power Point Advanced Edu Safety Gew 6 10 09
Roll Over Power Point Advanced Edu Safety Gew 6 10 09Roll Over Power Point Advanced Edu Safety Gew 6 10 09
Roll Over Power Point Advanced Edu Safety Gew 6 10 09
George Wendleton
 
Presentacio Ciutats
Presentacio CiutatsPresentacio Ciutats
Presentacio Ciutats
Reckonerr
 
Buscadores (Fodehum)
Buscadores (Fodehum)Buscadores (Fodehum)
Buscadores (Fodehum)grupo3fodehum
 
RSC & RIRG
RSC & RIRGRSC & RIRG
RSC & RIRG
rockspot
 
Recovery Act Slides
Recovery Act SlidesRecovery Act Slides
Recovery Act Slides
charlesbuisseret
 
House Hunting fun
House Hunting funHouse Hunting fun
House Hunting fun
Sarah Halstead
 

Viewers also liked (20)

Sql
SqlSql
Sql
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
 
PL/SQL
PL/SQLPL/SQL
PL/SQL
 
Jena Programming
Jena ProgrammingJena Programming
Jena Programming
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
 
Introduction to Business Statistics
Introduction to Business StatisticsIntroduction to Business Statistics
Introduction to Business Statistics
 
Introduction to Business Statistics
Introduction to Business StatisticsIntroduction to Business Statistics
Introduction to Business Statistics
 
Business Statistics
Business StatisticsBusiness Statistics
Business Statistics
 
Dynamic SQL in doobie
Dynamic SQL in doobieDynamic SQL in doobie
Dynamic SQL in doobie
 
Selecting best NoSQL
Selecting best NoSQL Selecting best NoSQL
Selecting best NoSQL
 
Seismic Waves
Seismic WavesSeismic Waves
Seismic Waves
 
Passivhus nordvest
Passivhus nordvestPassivhus nordvest
Passivhus nordvest
 
Seniorforsker Uffe Jørgensen; Aarhus Universitet
Seniorforsker Uffe Jørgensen; Aarhus UniversitetSeniorforsker Uffe Jørgensen; Aarhus Universitet
Seniorforsker Uffe Jørgensen; Aarhus Universitet
 
Roll Over Power Point Advanced Edu Safety Gew 6 10 09
Roll Over Power Point Advanced Edu Safety Gew 6 10 09Roll Over Power Point Advanced Edu Safety Gew 6 10 09
Roll Over Power Point Advanced Edu Safety Gew 6 10 09
 
Presentacio Ciutats
Presentacio CiutatsPresentacio Ciutats
Presentacio Ciutats
 
Buscadores (Fodehum)
Buscadores (Fodehum)Buscadores (Fodehum)
Buscadores (Fodehum)
 
RSC & RIRG
RSC & RIRGRSC & RIRG
RSC & RIRG
 
Lets Think
Lets ThinkLets Think
Lets Think
 
Recovery Act Slides
Recovery Act SlidesRecovery Act Slides
Recovery Act Slides
 
House Hunting fun
House Hunting funHouse Hunting fun
House Hunting fun
 

Similar to DBMS_SQL

Deep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
Deep Dive of ADBMS Migration to Apache Spark—Use Cases SharingDeep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
Deep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
Databricks
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programmingRushdi Shams
 
plsql.ppt
plsql.pptplsql.ppt
plsql.ppt
faizan992426
 
02 Writing Executable Statments
02 Writing Executable Statments02 Writing Executable Statments
02 Writing Executable Statments
rehaniltifat
 
Plsql
PlsqlPlsql
Plsql
Nst Tnagar
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Alex Zaballa
 
pl_sql.ppt
pl_sql.pptpl_sql.ppt
pl_sql.ppt
Prabhat106214
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
MySQL Day Roma - MySQL Shell and Visual Studio Code Extension
MySQL Day Roma - MySQL Shell and Visual Studio Code ExtensionMySQL Day Roma - MySQL Shell and Visual Studio Code Extension
MySQL Day Roma - MySQL Shell and Visual Studio Code Extension
Frederic Descamps
 
Anything SQL: Lightning Talks
Anything SQL: Lightning TalksAnything SQL: Lightning Talks
Anything SQL: Lightning Talks
SQL Server Sri Lanka User Group
 
Securefile LOBs
Securefile LOBsSecurefile LOBs
Securefile LOBs
Martin Berger
 
Dbms ii mca-ch7-sql-2013
Dbms ii mca-ch7-sql-2013Dbms ii mca-ch7-sql-2013
Dbms ii mca-ch7-sql-2013
Prosanta Ghosh
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Ontico
 
Rails DB migrations
Rails DB migrationsRails DB migrations
Rails DB migrations
Denys Kurets
 

Similar to DBMS_SQL (20)

Deep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
Deep Dive of ADBMS Migration to Apache Spark—Use Cases SharingDeep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
Deep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programming
 
plsql.ppt
plsql.pptplsql.ppt
plsql.ppt
 
02 Writing Executable Statments
02 Writing Executable Statments02 Writing Executable Statments
02 Writing Executable Statments
 
Plsql
PlsqlPlsql
Plsql
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
 
pl_sql.ppt
pl_sql.pptpl_sql.ppt
pl_sql.ppt
 
Awr report error
Awr report errorAwr report error
Awr report error
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
MySQL Day Roma - MySQL Shell and Visual Studio Code Extension
MySQL Day Roma - MySQL Shell and Visual Studio Code ExtensionMySQL Day Roma - MySQL Shell and Visual Studio Code Extension
MySQL Day Roma - MySQL Shell and Visual Studio Code Extension
 
Anything SQL: Lightning Talks
Anything SQL: Lightning TalksAnything SQL: Lightning Talks
Anything SQL: Lightning Talks
 
Securefile LOBs
Securefile LOBsSecurefile LOBs
Securefile LOBs
 
Dbms ii mca-ch7-sql-2013
Dbms ii mca-ch7-sql-2013Dbms ii mca-ch7-sql-2013
Dbms ii mca-ch7-sql-2013
 
PL/SQL 3 DML
PL/SQL 3 DMLPL/SQL 3 DML
PL/SQL 3 DML
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
 
Rails DB migrations
Rails DB migrationsRails DB migrations
Rails DB migrations
 

More from Mahesh Vallampati

Operating a payables shared service organization in oracle cloud oow 2019_v4
Operating a payables shared service organization in oracle cloud oow 2019_v4Operating a payables shared service organization in oracle cloud oow 2019_v4
Operating a payables shared service organization in oracle cloud oow 2019_v4
Mahesh Vallampati
 
Oracle BI Publisher to Transform Cloud ERP Reports
Oracle BI Publisher to Transform Cloud ERP ReportsOracle BI Publisher to Transform Cloud ERP Reports
Oracle BI Publisher to Transform Cloud ERP Reports
Mahesh Vallampati
 
Cloudy with a chance of 1099
Cloudy with a chance of 1099Cloudy with a chance of 1099
Cloudy with a chance of 1099
Mahesh Vallampati
 
Banking on the Cloud
Banking on the CloudBanking on the Cloud
Banking on the Cloud
Mahesh Vallampati
 
Statistical Accounts and Data in Oracle Cloud General Ledger
Statistical Accounts and Data in Oracle Cloud General LedgerStatistical Accounts and Data in Oracle Cloud General Ledger
Statistical Accounts and Data in Oracle Cloud General Ledger
Mahesh Vallampati
 
Sparse Matrix Manipulation Made easy in an Oracle RDBMS
Sparse Matrix Manipulation Made easy in an Oracle RDBMSSparse Matrix Manipulation Made easy in an Oracle RDBMS
Sparse Matrix Manipulation Made easy in an Oracle RDBMS
Mahesh Vallampati
 
The Data Architect Manifesto
The Data Architect ManifestoThe Data Architect Manifesto
The Data Architect Manifesto
Mahesh Vallampati
 
Five pillars of competency
Five pillars of competencyFive pillars of competency
Five pillars of competency
Mahesh Vallampati
 
Oracle EBS Change Projects Process Flows
Oracle EBS Change Projects Process FlowsOracle EBS Change Projects Process Flows
Oracle EBS Change Projects Process FlowsMahesh Vallampati
 
Cutover plan template Tool
Cutover plan template ToolCutover plan template Tool
Cutover plan template Tool
Mahesh Vallampati
 
Enough Blame for System Performance Issues
Enough Blame for System Performance IssuesEnough Blame for System Performance Issues
Enough Blame for System Performance IssuesMahesh Vallampati
 
Oracle R12 12.1.3 Legal Entity Data Gathering Template
Oracle R12 12.1.3 Legal Entity Data Gathering TemplateOracle R12 12.1.3 Legal Entity Data Gathering Template
Oracle R12 12.1.3 Legal Entity Data Gathering Template
Mahesh Vallampati
 
ERP Manager meets SDLC and CMMI
ERP Manager meets SDLC and CMMIERP Manager meets SDLC and CMMI
ERP Manager meets SDLC and CMMI
Mahesh Vallampati
 
Oracle 11i OID AD Integration
Oracle 11i OID AD IntegrationOracle 11i OID AD Integration
Oracle 11i OID AD IntegrationMahesh Vallampati
 
Generic Backup and Restore Process
Generic Backup and Restore ProcessGeneric Backup and Restore Process
Generic Backup and Restore Process
Mahesh Vallampati
 
OIC Process Flow V7
OIC Process Flow V7OIC Process Flow V7
OIC Process Flow V7
Mahesh Vallampati
 
XBRL in Oracle 11i and R12
XBRL in Oracle 11i and R12XBRL in Oracle 11i and R12
XBRL in Oracle 11i and R12
Mahesh Vallampati
 
Sales Process Flow V4
Sales Process Flow V4Sales Process Flow V4
Sales Process Flow V4
Mahesh Vallampati
 
ITP Instance Management Process V2
ITP Instance Management Process V2ITP Instance Management Process V2
ITP Instance Management Process V2
Mahesh Vallampati
 

More from Mahesh Vallampati (20)

Operating a payables shared service organization in oracle cloud oow 2019_v4
Operating a payables shared service organization in oracle cloud oow 2019_v4Operating a payables shared service organization in oracle cloud oow 2019_v4
Operating a payables shared service organization in oracle cloud oow 2019_v4
 
Oracle BI Publisher to Transform Cloud ERP Reports
Oracle BI Publisher to Transform Cloud ERP ReportsOracle BI Publisher to Transform Cloud ERP Reports
Oracle BI Publisher to Transform Cloud ERP Reports
 
Cloudy with a chance of 1099
Cloudy with a chance of 1099Cloudy with a chance of 1099
Cloudy with a chance of 1099
 
Banking on the Cloud
Banking on the CloudBanking on the Cloud
Banking on the Cloud
 
Statistical Accounts and Data in Oracle Cloud General Ledger
Statistical Accounts and Data in Oracle Cloud General LedgerStatistical Accounts and Data in Oracle Cloud General Ledger
Statistical Accounts and Data in Oracle Cloud General Ledger
 
Sparse Matrix Manipulation Made easy in an Oracle RDBMS
Sparse Matrix Manipulation Made easy in an Oracle RDBMSSparse Matrix Manipulation Made easy in an Oracle RDBMS
Sparse Matrix Manipulation Made easy in an Oracle RDBMS
 
The Data Architect Manifesto
The Data Architect ManifestoThe Data Architect Manifesto
The Data Architect Manifesto
 
Five pillars of competency
Five pillars of competencyFive pillars of competency
Five pillars of competency
 
Oracle EBS Change Projects Process Flows
Oracle EBS Change Projects Process FlowsOracle EBS Change Projects Process Flows
Oracle EBS Change Projects Process Flows
 
Cutover plan template Tool
Cutover plan template ToolCutover plan template Tool
Cutover plan template Tool
 
CRM Lead Lifecycle Process
CRM Lead Lifecycle ProcessCRM Lead Lifecycle Process
CRM Lead Lifecycle Process
 
Enough Blame for System Performance Issues
Enough Blame for System Performance IssuesEnough Blame for System Performance Issues
Enough Blame for System Performance Issues
 
Oracle R12 12.1.3 Legal Entity Data Gathering Template
Oracle R12 12.1.3 Legal Entity Data Gathering TemplateOracle R12 12.1.3 Legal Entity Data Gathering Template
Oracle R12 12.1.3 Legal Entity Data Gathering Template
 
ERP Manager meets SDLC and CMMI
ERP Manager meets SDLC and CMMIERP Manager meets SDLC and CMMI
ERP Manager meets SDLC and CMMI
 
Oracle 11i OID AD Integration
Oracle 11i OID AD IntegrationOracle 11i OID AD Integration
Oracle 11i OID AD Integration
 
Generic Backup and Restore Process
Generic Backup and Restore ProcessGeneric Backup and Restore Process
Generic Backup and Restore Process
 
OIC Process Flow V7
OIC Process Flow V7OIC Process Flow V7
OIC Process Flow V7
 
XBRL in Oracle 11i and R12
XBRL in Oracle 11i and R12XBRL in Oracle 11i and R12
XBRL in Oracle 11i and R12
 
Sales Process Flow V4
Sales Process Flow V4Sales Process Flow V4
Sales Process Flow V4
 
ITP Instance Management Process V2
ITP Instance Management Process V2ITP Instance Management Process V2
ITP Instance Management Process V2
 

Recently uploaded

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 

Recently uploaded (20)

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 

DBMS_SQL

  • 1. DBMS_SQL Revisited The DBMS_SQL package supplied by Oracle Corporation is a powerful tool to evaluate and execute dynamic SQL expressions. The single most important component of the dbms_sql package is the dbms_sql.parse procedure. In previous releases of the RDBMS, the parse procedure was limited to 2000 characters. In the latest release of the RDBMS, this procedure has been overloaded to a table of varchar2, thus setting no limit on the size of the dynamic SQL. This article will demonstrate the use of this packaged procedure and in addition will explain a method for executing anonymous PL/SQL blocks and extracting the result from the block to the calling program. New Overloaded Procedure dbms_sql.parse: Description of dbms_sql.parse from Oracle RDBMS 7.3.3.3.0 SQL> desc dbms_sql.parse PROCEDURE dbms_sql.parse Argument NameType In/Out Default? ------------------------------ ----------------------- --------------- C NUMBER(38) IN STATEMENT VARCHAR2 IN LANGUAGE_FLAG NUMBER(38) IN PROCEDURE dbms_sql.parse Argument Name Type In/Out Default? ------------------------------ ----------------------- ------ -------- C NUMBER(38) IN STATEMENT TABLE OF VARCHAR2(256) IN LB NUMBER(38) IN UB NUMBER(38) IN LFFLG BOOLEAN IN LANGUAGE_FLAG NUMBER(38) IN Fig1: Description of dbms_sql.parse
  • 2. Note that the table of varchar2 is actually a type of dbms_sql.varchar2s which is defined in dbmssql.sql in $ORACLE_HOME/rdbms/admin as follows: type varchar2s is table of varchar2(256) index by binary integer; c is an integer and holds the familiar cursor handle. LB denotes the lower bound of the PL/SQL table and UB denotes the upper bound of the PL/SQL table. That is, a PL/SQL table of varchar2(256) could hold many lines of code, but they can be selectively parsed and executed using these variables. That is one could specify LB as 3 and UB as 7 and the SQL code in the PL/SQL table from 3 to 7 will be parsed and executed. Conceptually, the SQL string is put together as follows: string:=statement(lb) || statement (lb+1) ||…||statement(ub); . If LFFLG which is a Boolean variable is set to true, then a new line is inserted after each piece. This is strongly recommended due to the following reason. When building large chunks of code, a line of PL/SQL code cannot exceed 2000 characters and the PL/SQL compiler wraps it to accomplish it. The reason this happens is that all database source code is stored in dba_source view and its underlying table and in the text column of that table and is limited to 2000 characters. Now users can build a PL/SQL table and specify the upper and lower boundary of the table as input arguments to dbms_sql.parse instead of the previous varchar2 thus surpassing the 2000 characters limitation. This is particularly useful when evaluating complicated business rules and expressions. Use of the New version of dbms_sql.parse: The code that follows demonstrates the usage of the dbms_sql.parse procedure. Before we demonstrate use of this procedure, we will create a packaged variable and a function to retrieve that variable. This will be used to demonstrate the use of extracting the value from an anonymous PL/SQL block using dbms_sql.
  • 3. Create or Replace package myvar as Pragma restrict_references(myvar,WNDS,WNPS,RNDS, RNPS); result number; end myvar; Fig 2: Source Code for myvar package A discerning user will notice that the package has been subjected to a Pragma restrict_reference restriction. This is due to the following reason. A function which retrieves the value of the variable will otherwise return the familiar ORA-06571 error which is, “Function %s does not guarantee not to update database”. Now we will demonstrate the function which will retrieve the value of the packaged variable. Create or replace function check_calc return number is begin return myvar.result; end; Fig 3: Source Code for the check_calc package. Note that the function merely reads the myvar.result package variable and returns it back to the calling program. In this example we will create a table of varchar2, and create an anonymous PL/SQL block and declare two variables A and B. We will assign them some arbitrary values and then pass an expression as an argument to the procedure. This expression could be any valid PL/SQL expression not exceeding 256 characters. The task of evaluating expressions greater than 256 characters is left as an exercise to the discerning reader and just reduces to breaking up a character string greater than 256 characters into multiple pieces of 256 characters and then appending it to the PL/SQL table.
  • 4. Note that A and B could be assigned values by any valid SQL function which can be user defined and hence A and B can be assigned dynamically too. This is not done here for the sake of simplicity. For example, A and B could well be the age and gender of an individual stored in a database and very well could be as follows: a:=getage(855855855); b:=getgender(855855855); where 855855855 uniquely identifies an individual in a database table. In fact, even the above two statements could be generated dynamically if the information is stored in a table. It should also be noted that is these attributes are stored in a database, once could potentially generate the statements in the anonymous PL/SQL block. The following piece of code demonstrates the use of the new overloaded version of dbms_sql.parse. Note that the anonymous PL/SQL block updates a package variable, which is available throughout the session. Examples of dbms_sql.parse with the three arguments abound in Oracle literature and accessing data through define_column procedure and column_value procedure. The limitation of dbms_sql.parse with three arguments is already know. Define_column and column_value is fine when one has to access database data and cursor data respectively. The packaged variable method does not require use of these procedures and their limitations if any. Note that even though sqlstring is a table of varchar2(256), it should be casted as dbms_sql.varchar2s. The following section of code demonstrates the use of the new dbms_sql.parse and the use of the packaged variable and its associated function which retrieves it. The good thing about anonymous PL/SQL blocks is that, they don‟t need to be wrapped in procedures/functions/packages thus causing DDL issues.
  • 5. create or replace procedure democalc ( calc_text in varchar2, //* The calculation string for example: “result:=A*B;” return_result in out number, retval in out number ) IS sqlstring dbms_sql.varchar2s; /* Created to hold the PL/SQL Block */ cursor1 integer; i, j integer; new_line_flag BOOLEAN:=TRUE; BEGIN sqlstring(1):='declare '; sqlstring(2):='result number(38,2):=0.0;'; sqlstring(3):='a number(38,2):=2;'; sqlstring(4):='b number(38,2):=3;'; sqlstring(5):='begin'; sqlstring(6):=calc_text; sqlstring(7):='myvar.result:=result;'; sqlstring(8):='end;'; i=1; j=8; cursor1:=dbms_sql.open_cursor; dbms_sql.parse(cursor1,sqlstring,i,j,new_line_flag,DBMS_SQL.V7); retval:=dbms_sql.execute(cursor1); dbms_sql.close_cursor(cursor1); return_result:=check_calc; END; /
  • 6. The following section demonstrates the execution of the democalc procedure. SQL> set serveroutput on SQL> declare temp1 number; temp2 number; begin democalc(„result:=A*P;‟, temp1,temp2); dbms_output.put_line(„The result is „||temp1); end; / The result is 6 SQL> Conclusions: The new overloaded version of dbms_sql.parse obviates the previous limit of the dbms_sql and provides even more flexibility to the developer. A system which provides a framework to evaluate simple, dynamic PL/SQL expressions and which uses the above version of dbms_sql.parse is in development at an Oracle client site by Oracle consulting and is expected to go live soon. Acknowledgements: The brilliant idea of using packaged variables to exchange values from anonymous PL/SQL blocks was suggested by an Oracle Technical manager, Roger Raj. About the Author: Mahesh Vallampati is a senior consultant with the Oracle National Telecom practice, Oracle Corporation. Though he is a DBA by profession, occasionally he is called on by Oracle customers for his PL/SQL expertise which he dabbles in. He can be reached at his convenience at mvallamp@us.oracle.com.