473,499 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DB2 SQL Procedural Language Outside Procedure

Is it possible to execute procedural language outside of a procedure
in DB2 Command Center? For instance I need the ability to declare
some variables and do some conditional processing similar to the
sample below. We are on DB2 UDB 8.1.6.

BEGIN SAMPLE
DECLARE SYSTEM_NAME CHAR(10);
SET SYSTEM_NAME = 'IWT'
IF SYSTEM_NAME = 'IWP' THEN
CREATE UNIQUE INDEX TEST1 ON STG.TABS(NUMBER);
END IF;
END SAMPLE

When I try to run I get the following error returned.

DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "BEGIN SAMPLE" was found following
"BEGIN-OF-STATEMENT". Expected tokens may include: "<create_proc>".
SQLSTATE=42601

Spencer
sp*****@tabbert.net
Nov 12 '05 #1
10 6517
Spencer,

DB2 UDB for LUW supports the dynamic compound statement.
However dynamic compound can only do inline SQL PL. Not teh full blown
SQL PL.
In your case that means no DDL.

Often people use shell-scripts or perl instead.

Cheers
Serge
Nov 12 '05 #2
Yes, a shell script could be used however because of security purposes
I would like to be able to do this directly in SQL. Would it be
possible to develop a stored procedure or UDF that I could call or
execute from a sql prompt that would do the drop index or create
index? Essentially what I am looking for is a way to disable the
index but since that does not exist in DB2 I would like to drop and
recreate the index.

Ideally...I would like to have a sql procedure built that would take
as input two parameters. A table name and operation(DropIndex or
CreateIndex). On a call specifying a DropIndex the procedure would
then dynamically determine the indexes on the table it needs to drop
but before doing so record the syntax in a working table such that on
a call specifying CreateIndex the procedure would be able to recreate
all table indexes and as they existed previous to dropping the index
and then perform a runstats. This would be very handy and ensure that
indexes are created in the proper fashion by non DBA's. It would also
ensure that if indexes are renamed or removed by DBA's and Data
Modelers that our processes are not incorrectly creating indexes or
attempting to drop indexes no longer existing.
Spencer
Serge Rielau <sr*****@ca.eye-bee-em.com> wrote in message news:<41********@news3.prserv.net>...
Spencer,

DB2 UDB for LUW supports the dynamic compound statement.
However dynamic compound can only do inline SQL PL. Not teh full blown
SQL PL.
In your case that means no DDL.

Often people use shell-scripts or perl instead.

Cheers
Serge

Nov 12 '05 #3
Spencer,

Absolutely. There is a limited set of DDL such for example CREATE and
DROP TABLE which SQL PL supports "natively".
For all other SQL you can use: EXECUTE IMMEDIATE <sql statement>
Using EXECUTE IMMEDIATE is also popular because it allows users to "glue
together" the DDL statement in order to add variable keywords. Such as
choosing the tablespace...
Cheers
Serghe
Nov 12 '05 #4
Spencer,

Absolutely. There is a limited set of DDL such for example CREATE and
DROP TABLE which SQL PL supports "natively".
For all other SQL you can use: EXECUTE IMMEDIATE <sql statement>
Using EXECUTE IMMEDIATE is also popular because it allows users to "glue
together" the DDL statement in order to add variable keywords. Such as
choosing the tablespace...
Cheers
Serge
Nov 12 '05 #5
Thanks Serge. Just what I was looking for. Can you recommend some
good reference material(Books, Whitepapers, Articles) on the SQL PL
language and it's capabilities and in some cases limitations
specifically in relation to 8.1.x.
Spencer
Serge Rielau <sr*****@ca.eye-bee-em.com> wrote in message news:<C_******************@news04.bloor.is.net.cab le.rogers.com>...
Spencer,

Absolutely. There is a limited set of DDL such for example CREATE and
DROP TABLE which SQL PL supports "natively".
For all other SQL you can use: EXECUTE IMMEDIATE <sql statement>
Using EXECUTE IMMEDIATE is also popular because it allows users to "glue
together" the DDL statement in order to add variable keywords. Such as
choosing the tablespace...
Cheers
Serge

Nov 12 '05 #6
In regards to what is/isn't supported in inline SQL PL will
8.2/Stinger support the ability to use EXECUTE IMMEDIATE or CALL such
that I would be able to perform DDL operations inline SQL PL?
Spencer
Serge Rielau <sr*****@ca.eye-bee-em.com> wrote in message news:<C_******************@news04.bloor.is.net.cab le.rogers.com>...
Spencer,

Absolutely. There is a limited set of DDL such for example CREATE and
DROP TABLE which SQL PL supports "natively".
For all other SQL you can use: EXECUTE IMMEDIATE <sql statement>
Using EXECUTE IMMEDIATE is also popular because it allows users to "glue
together" the DDL statement in order to add variable keywords. Such as
choosing the tablespace...
Cheers
Serge

Nov 12 '05 #7
DB2 V8.2 (FP7) indeed supports CALL in inline SQL PL.
At present I don't see any further improvements to inline SQL PL. w.r.t
specific SQL PL capabilities.
What I do see happen in the future is the ability to create functions
(and trigger) which use native SQL PL as an option. (and no I won't say
when that may happen)

W.r.t. literature here si teh "standard" book:
http://www.informit.com/bookstore/pr...007726&redir=1
It's due to be refreshed for V8.2 later this year.

Cheers
Serge
Nov 12 '05 #8
Serge Rielau wrote:

Using EXECUTE IMMEDIATE is also popular because it allows users to "glue
together" the DDL statement in order to add variable keywords.


Use this approach wisely. Many, many SQL Injection attacks are directly
attributable to the use of EXECUTE IMMEDIATE (or other forms of dynamic
SQL)

Nov 12 '05 #9
Agreed. I encourage those using dynamic SQL in routines to read up on
the DYNAMICRULES bindoption in the BIND command.

Cheers
Serge

Nov 12 '05 #10
I would agree but it also allows for a tremendous amount of
flexibility in certain situations.
Mark Townsend <ma***********@comcast.net> wrote in message news:<67iXc.48358$9d6.22499@attbi_s54>...
Serge Rielau wrote:

Using EXECUTE IMMEDIATE is also popular because it allows users to "glue
together" the DDL statement in order to add variable keywords.
>


Use this approach wisely. Many, many SQL Injection attacks are directly
attributable to the use of EXECUTE IMMEDIATE (or other forms of dynamic
SQL)

Nov 12 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3444
by: selowan | last post by:
Hi, In VB6 Pro SP5, I have a form that contains an MSFlexGrid and a few other textboxes and comboboxes. I am using the technique from MSDN article Q241355, which describes how to tab and edit in...
4
4435
by: Mark Mikulec | last post by:
Hi there, I wonder if anyone can shed some light on a very frustrating problem. I'm running a debian linux 3.0 "woody" server, nothing special, with the latest version of postres that apt-get...
16
4368
by: Manuel | last post by:
Please, excuse me for starting this discussion. I'm not a troll, and I love the OOP architecture. However I'm a C++ newbie, and sometimes it's hard for me to fully understand the improvement of...
669
25378
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
7
1620
by: oracle newbie | last post by:
Is there a line of coding that will record down the number of login Within and Outside the Campus? I'm not sure how to make it Withina and Outside SQL> SQL> SQL> create table audit_info 2 ...
4
2751
by: Mohitz | last post by:
Any pointers as to how one should go about porting procedural type code into object oriented code?? --- Mohit
0
1029
by: heatlamp | last post by:
Is it possible to define transaction boundaries within the body of a database procedure (using SQL Procedural Language)? I use this approach in other databases to minimize locking impact of long...
4
2364
by: Erwin Moller | last post by:
Hi, I was surprised to see that my fav. database offers PHP as a scripting language Procedural language (eg stored procedures). Untill now I always used PgPL/SQL for that. Offered by command...
14
1617
by: mesut | last post by:
hi colleagues, I don't know if this is the right group for but it's in C# so I try. I have a #3 procedural function called GetInfo.. and those are 3 overloaded methods. I would like to use the...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.