473,508 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

writing compound/complex sql

hello,

is it possible to write compound sql without stored procedure or
trigger.
can i just run in command center of db2.

regards,
jagdip singh

Mar 12 '07 #1
11 7372
db2admin wrote:
hello,

is it possible to write compound sql without stored procedure or
trigger.
can i just run in command center of db2.
Yes, you can.

--
Knut Stolze
DB2 z/OS Admin Enablement
IBM Germany
Mar 12 '07 #2
On Mar 12, 1:52 pm, "db2admin" <jag...@gmail.comwrote:
hello,

is it possible to write compound sql without stored procedure or
trigger.
can i just run in command center of db2.

regards,
jagdip singh
You can use the command editor or right click on database and pick
query tab.
You can write complex sql in either place.

Mar 12 '07 #3
On Mar 12, 11:05 am, "dunleav1" <j...@dunleavyenterprises.comwrote:
On Mar 12, 1:52 pm, "db2admin" <jag...@gmail.comwrote:
hello,
is it possible to write compound sql without stored procedure or
trigger.
can i just run in command center of db2.
regards,
jagdip singh

You can use the command editor or right click on database and pick
query tab.
You can write complex sql in either place.
Hi, Jagdip.

I think that what you might be asking about is ultimately the BEGIN
ATOMIC block, which is a bit analogous to an anonymous block in
Oracle, if that's helpful to you. In DB2 such constructs are known as
inline SQL PL.

Here's a trivial example (inserts 10000 random integers into a table):

BEGIN ATOMIC
DECLARE C_CNTR INTEGER DEFAULT 0;--
WHILE C_CNTR < 10000 DO
INSERT INTO IX_TEST (C1) VALUES (CAST((RAND()*100) AS INTEGER));--
SET C_CNTR = C_CNTR + 1;--
END WHILE;--
END;

You can do lots of things in inline SQL PL that you can do in SPs,
such as declare variables, loops, and cursor FOR LOOPs, but there are
several things you can't do, such as declare exception handlers, DDL,
and COMMIT/ROLLBACK.

HTH,

--Jeff

Mar 12 '07 #4
On Mar 12, 5:36 pm, "jefftyzzer" <jefftyz...@sbcglobal.netwrote:
On Mar 12, 11:05 am, "dunleav1" <j...@dunleavyenterprises.comwrote:
On Mar 12, 1:52 pm, "db2admin" <jag...@gmail.comwrote:
hello,
is it possible to write compound sql without stored procedure or
trigger.
can i just run in command center of db2.
regards,
jagdip singh
You can use the command editor or right click on database and pick
query tab.
You can write complex sql in either place.

Hi, Jagdip.

I think that what you might be asking about is ultimately the BEGIN
ATOMIC block, which is a bit analogous to an anonymous block in
Oracle, if that's helpful to you. In DB2 such constructs are known as
inline SQL PL.

Here's a trivial example (inserts 10000 random integers into a table):

BEGIN ATOMIC
DECLARE C_CNTR INTEGER DEFAULT 0;--
WHILE C_CNTR < 10000 DO
INSERT INTO IX_TEST (C1) VALUES (CAST((RAND()*100) AS INTEGER));--
SET C_CNTR = C_CNTR + 1;--
END WHILE;--
END;

You can do lots of things in inline SQL PL that you can do in SPs,
such as declare variables, loops, and cursor FOR LOOPs, but there are
several things you can't do, such as declare exception handlers, DDL,
and COMMIT/ROLLBACK.

HTH,

--Jeff
thanks a lot for help
i really appreciate help
can i declare global temporary tables in inline SQL PL

Mar 12 '07 #5
On Mar 12, 3:05 pm, "db2admin" <jag...@gmail.comwrote:
On Mar 12, 5:36 pm, "jefftyzzer" <jefftyz...@sbcglobal.netwrote:


On Mar 12, 11:05 am, "dunleav1" <j...@dunleavyenterprises.comwrote:
On Mar 12, 1:52 pm, "db2admin" <jag...@gmail.comwrote:
hello,
is it possible to write compound sql without stored procedure or
trigger.
can i just run in command center of db2.
regards,
jagdip singh
You can use the command editor or right click on database and pick
query tab.
You can write complex sql in either place.
Hi, Jagdip.
I think that what you might be asking about is ultimately the BEGIN
ATOMIC block, which is a bit analogous to an anonymous block in
Oracle, if that's helpful to you. In DB2 such constructs are known as
inline SQL PL.
Here's a trivial example (inserts 10000 random integers into a table):
BEGIN ATOMIC
DECLARE C_CNTR INTEGER DEFAULT 0;--
WHILE C_CNTR < 10000 DO
INSERT INTO IX_TEST (C1) VALUES (CAST((RAND()*100) AS INTEGER));--
SET C_CNTR = C_CNTR + 1;--
END WHILE;--
END;
You can do lots of things in inline SQL PL that you can do in SPs,
such as declare variables, loops, and cursor FOR LOOPs, but there are
several things you can't do, such as declare exception handlers, DDL,
and COMMIT/ROLLBACK.
HTH,
--Jeff

thanks a lot for help
i really appreciate help
can i declare global temporary tables in inline SQL PL- Hide quoted text -

- Show quoted text -
I'm afraid you can't.

--Jeff

Mar 12 '07 #6
On 12 Mar 2007 15:49:42 -0700, "jefftyzzer" <je********@sbcglobal.net>
wrote:
>On Mar 12, 3:05 pm, "db2admin" <jag...@gmail.comwrote:
>On Mar 12, 5:36 pm, "jefftyzzer" <jefftyz...@sbcglobal.netwrote:


On Mar 12, 11:05 am, "dunleav1" <j...@dunleavyenterprises.comwrote:
On Mar 12, 1:52 pm, "db2admin" <jag...@gmail.comwrote:
hello,
is it possible to write compound sql without stored procedure or
trigger.
can i just run in command center of db2.
regards,
jagdip singh
You can use the command editor or right click on database and pick
query tab.
You can write complex sql in either place.
Hi, Jagdip.
I think that what you might be asking about is ultimately the BEGIN
ATOMIC block, which is a bit analogous to an anonymous block in
Oracle, if that's helpful to you. In DB2 such constructs are known as
inline SQL PL.
Here's a trivial example (inserts 10000 random integers into a table):
BEGIN ATOMIC
DECLARE C_CNTR INTEGER DEFAULT 0;--
WHILE C_CNTR < 10000 DO
INSERT INTO IX_TEST (C1) VALUES (CAST((RAND()*100) AS INTEGER));--
SET C_CNTR = C_CNTR + 1;--
END WHILE;--
END;
You can do lots of things in inline SQL PL that you can do in SPs,
such as declare variables, loops, and cursor FOR LOOPs, but there are
several things you can't do, such as declare exception handlers, DDL,
and COMMIT/ROLLBACK.
HTH,
--Jeff

thanks a lot for help
i really appreciate help
can i declare global temporary tables in inline SQL PL- Hide quoted text -

- Show quoted text -

I'm afraid you can't.

--Jeff
But they can be DECLAREd beforehand for use within it.

B.
Mar 13 '07 #7
On Mar 13, 7:56 am, Brian Tkatch <N/Awrote:
On 12 Mar 2007 15:49:42 -0700, "jefftyzzer" <jefftyz...@sbcglobal.net>
wrote:


On Mar 12, 3:05 pm, "db2admin" <jag...@gmail.comwrote:
On Mar 12, 5:36 pm, "jefftyzzer" <jefftyz...@sbcglobal.netwrote:
On Mar 12, 11:05 am, "dunleav1" <j...@dunleavyenterprises.comwrote:
On Mar 12, 1:52 pm, "db2admin" <jag...@gmail.comwrote:
hello,
is it possible to write compound sql without stored procedure or
trigger.
can i just run in command center of db2.
regards,
jagdip singh
You can use the command editor or right click on database and pick
query tab.
You can write complex sql in either place.
Hi, Jagdip.
I think that what you might be asking about is ultimately the BEGIN
ATOMIC block, which is a bit analogous to an anonymous block in
Oracle, if that's helpful to you. In DB2 such constructs are known as
inline SQL PL.
Here's a trivial example (inserts 10000 random integers into a table):
BEGIN ATOMIC
DECLARE C_CNTR INTEGER DEFAULT 0;--
WHILE C_CNTR < 10000 DO
INSERT INTO IX_TEST (C1) VALUES (CAST((RAND()*100) AS INTEGER));--
SET C_CNTR = C_CNTR + 1;--
END WHILE;--
END;
You can do lots of things in inline SQL PL that you can do in SPs,
such as declare variables, loops, and cursor FOR LOOPs, but there are
several things you can't do, such as declare exception handlers, DDL,
and COMMIT/ROLLBACK.
HTH,
--Jeff
thanks a lot for help
i really appreciate help
can i declare global temporary tables in inline SQL PL- Hide quoted text -
- Show quoted text -
I'm afraid you can't.
--Jeff

But they can be DECLAREd beforehand for use within it.

B.- Hide quoted text -

- Show quoted text -
Brian brings up an excellent point, so let me clarify:

While you can't DECLARE a DGTT in a BEGIN ATOMIC block, you could
certainly DECLARE one outside of such a block in, say, Command Center,
and then refer to it in your BEGIN ATOMIC block, as long as the DGTT
and BEGIN ATOMIC block are executed within the same session.

DECLARE GLOBAL TEMPORARY TABLE SESSION.IX_TEST ( C1 INTEGER ) ON
COMMIT PRESERVE ROWS NOT LOGGED ON ROLLBACK DELETE ROWS WITH REPLACE
DB20000I The SQL command completed successfully.

BEGIN ATOMIC
DECLARE C_CNTR INTEGER DEFAULT 0;--
WHILE C_CNTR < 10000 DO
INSERT INTO SESSION.IX_TEST (C1) VALUES (CAST((RAND()*100) AS
INTEGER));--
SET C_CNTR = C_CNTR + 1;--
END WHILE;--
END
DB20000I The SQL command completed successfully.

SELECT COUNT(*) FROM SESSION.IX_TEST

1
-----------
10000

1 record(s) selected.

--Jeff

Mar 13 '07 #8
On 13 Mar 2007 12:12:20 -0700, "jefftyzzer" <je********@sbcglobal.net>
wrote:
>On Mar 13, 7:56 am, Brian Tkatch <N/Awrote:
>On 12 Mar 2007 15:49:42 -0700, "jefftyzzer" <jefftyz...@sbcglobal.net>
wrote:


>On Mar 12, 3:05 pm, "db2admin" <jag...@gmail.comwrote:
On Mar 12, 5:36 pm, "jefftyzzer" <jefftyz...@sbcglobal.netwrote:
On Mar 12, 11:05 am, "dunleav1" <j...@dunleavyenterprises.comwrote:
On Mar 12, 1:52 pm, "db2admin" <jag...@gmail.comwrote:
hello,
is it possible to write compound sql without stored procedure or
trigger.
can i just run in command center of db2.
regards,
jagdip singh
You can use the command editor or right click on database and pick
query tab.
You can write complex sql in either place.
Hi, Jagdip.
I think that what you might be asking about is ultimately the BEGIN
ATOMIC block, which is a bit analogous to an anonymous block in
Oracle, if that's helpful to you. In DB2 such constructs are known as
inline SQL PL.
Here's a trivial example (inserts 10000 random integers into a table):
BEGIN ATOMIC
DECLARE C_CNTR INTEGER DEFAULT 0;--
WHILE C_CNTR < 10000 DO
INSERT INTO IX_TEST (C1) VALUES (CAST((RAND()*100) AS INTEGER));--
SET C_CNTR = C_CNTR + 1;--
END WHILE;--
END;
You can do lots of things in inline SQL PL that you can do in SPs,
such as declare variables, loops, and cursor FOR LOOPs, but there are
several things you can't do, such as declare exception handlers, DDL,
and COMMIT/ROLLBACK.
HTH,
--Jeff
>thanks a lot for help
i really appreciate help
can i declare global temporary tables in inline SQL PL- Hide quoted text -
>- Show quoted text -
>I'm afraid you can't.
>--Jeff

But they can be DECLAREd beforehand for use within it.

B.- Hide quoted text -

- Show quoted text -

Brian brings up an excellent point, so let me clarify:

While you can't DECLARE a DGTT in a BEGIN ATOMIC block, you could
certainly DECLARE one outside of such a block in, say, Command Center,
and then refer to it in your BEGIN ATOMIC block, as long as the DGTT
and BEGIN ATOMIC block are executed within the same session.

DECLARE GLOBAL TEMPORARY TABLE SESSION.IX_TEST ( C1 INTEGER ) ON
COMMIT PRESERVE ROWS NOT LOGGED ON ROLLBACK DELETE ROWS WITH REPLACE
DB20000I The SQL command completed successfully.

BEGIN ATOMIC
DECLARE C_CNTR INTEGER DEFAULT 0;--
WHILE C_CNTR < 10000 DO
INSERT INTO SESSION.IX_TEST (C1) VALUES (CAST((RAND()*100) AS
INTEGER));--
SET C_CNTR = C_CNTR + 1;--
END WHILE;--
END
DB20000I The SQL command completed successfully.

SELECT COUNT(*) FROM SESSION.IX_TEST

1
-----------
10000

1 record(s) selected.

--Jeff
Thanx for the clarification. :)

B.
Mar 14 '07 #9
>>On 3/13/2007 at 1:12 PM, in message
<11*********************@n33g2000cwc.googlegroups. com>,
jefftyzzer<je********@sbcglobal.netwrote:
BEGIN ATOMIC
DECLARE C_CNTR INTEGER DEFAULT 0;--
WHILE C_CNTR < 10000 DO
INSERT INTO SESSION.IX_TEST (C1) VALUES (CAST((RAND()*100) AS
INTEGER));--
SET C_CNTR = C_CNTR + 1;--
END WHILE;--
END
Can someone explain the use of '--' in dynamic compound SQL statements? It
appears to be necessary, in that it doesn't work without them, but I can't
find reference to what they are and when they need to be used.

Frank

Mar 14 '07 #10
Frank Swarbrick wrote:
>On 3/13/2007 at 1:12 PM, in message
<11*********************@n33g2000cwc.googlegroups. com>,
jefftyzzer<je********@sbcglobal.netwrote:
BEGIN ATOMIC
DECLARE C_CNTR INTEGER DEFAULT 0;--
WHILE C_CNTR < 10000 DO
INSERT INTO SESSION.IX_TEST (C1) VALUES (CAST((RAND()*100) AS
INTEGER));--
SET C_CNTR = C_CNTR + 1;--
END WHILE;--
END

Can someone explain the use of '--' in dynamic compound SQL
statements? It appears to be necessary, in that it doesn't work
without them, but I can't find reference to what they are and when
they need to be used.
Just guessing, but I'm assuming when the statement terminator is a
newline (as it is by default), the trailing '--' prevents the parser
from thinking that the statement has ended prematurely (by making the
newline part of a comment).

I typically use dynamic compound SQL in the CLP with a specific
alternate statement terminator (e.g. -td! or -td@ on the command line).
Under these circumstances, the trailing '--' is not required.

--
Dave.
Mar 15 '07 #11
Frank Swarbrick wrote:
>>>On 3/13/2007 at 1:12 PM, in message
<11*********************@n33g2000cwc.googlegroups. com>,
jefftyzzer<je********@sbcglobal.netwrote:
>BEGIN ATOMIC
DECLARE C_CNTR INTEGER DEFAULT 0;--
WHILE C_CNTR < 10000 DO
INSERT INTO SESSION.IX_TEST (C1) VALUES (CAST((RAND()*100) AS
INTEGER));--
SET C_CNTR = C_CNTR + 1;--
END WHILE;--
END

Can someone explain the use of '--' in dynamic compound SQL statements? It
appears to be necessary, in that it doesn't work without them, but I can't
find reference to what they are and when they need to be used.
Serge gave an explanation for this in this thread:

http://groups.google.com/group/comp....a5698391281eee

/Lennart

Mar 15 '07 #12

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

Similar topics

4
4425
by: Sonia | last post by:
I have been looking for a definition of a compound class but cannot find it anywhere ? What exactly is a compound class ? Thanks
6
3731
by: David W. Fenton | last post by:
I'm generally against using compound keys, except in join tables, but I'm currently mapping out a schema where the join table has child records. The application is for fund-raising and I have four...
6
2645
by: William Ahern | last post by:
So, GCC 4.01 is giving errors that GCC 3.3 did not, and I'm thinking they've gone overboard with their new type checking infrastructure. Here's the supposedly offending code (no laughing or...
7
1917
by: Eric Laberge | last post by:
Aloha! This question is meant to be about C99 and unnamed compound objects. As I read, if such a construct as int *p = (int){0}; is used within a function, then it has "automatic storage...
1
1712
by: Tristan | last post by:
Hi, In my application I need to store pen objects in a file so they can be read in at a latter stage from the file to recreate the pen objects in memory. I'm currently doing this by hand,...
8
3511
by: wespvp | last post by:
I am using PostgreSQL 7.4.1 on RedHat 7.2. The query I am executing is something like (I replaced all the return values with 'count'): db=> explain select count(*) from messages m join (select...
7
5433
by: Timo Haberkern | last post by:
Hi there, i have some troubles with my TSearch2 Installation. I have done this installation as described in http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_compound_words...
27
2491
by: Nate Eldredge | last post by:
Consider the following pseudo-code: #include <opaque.h> struct foo { int a; opaque_t op; int b; };
0
961
by: Fred | last post by:
I am trying to move an example from Access to VB and in the example they describe a complex table key as 'compound' as if made of values from more than one field How do you do that for SQL...
0
7225
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,...
0
7123
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
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5627
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 project—planning, coding, testing,...
0
3194
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
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1557
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
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
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...

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.