473,563 Members | 2,916 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 6520
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(DropI ndex 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.e ye-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.e ye-bee-em.com> wrote in message news:<C_******* ***********@new s04.bloor.is.ne t.cable.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.e ye-bee-em.com> wrote in message news:<C_******* ***********@new s04.bloor.is.ne t.cable.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

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

Similar topics

0
3447
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 a flexgrid. Briefly, the technique is to overlay the cell to be edited with "floating" textbox; data is edited in the floating textbox and moved...
4
4444
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 will allow me, which I *think* it;s 7.1 something, I don't know how to figure out the postgres version. Anywho - I'm trying to backup my databases,...
16
4377
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 OOP. Please excuse my poor english too. I hope it's sufficient to explain my question. Generally OOP is better than procedural, but in a case I'm...
669
25640
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 paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990....
7
1625
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 ( 3 usr varchar2(50), 4 log_time timestamp(6) 5 );
4
2762
by: Mohitz | last post by:
Any pointers as to how one should go about porting procedural type code into object oriented code?? --- Mohit
0
1033
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 running operations. thx, jim
4
2369
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 prompt: http://www.commandprompt.com/community/plphp/ Did anybody in here use it?
14
1626
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 OOP approach to refactor this. The functions are working fine but I would like to have a OOP approach can someone help me refactoring this??????
0
7664
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6250
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3642
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
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 we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.