Question

I had a doubt regarding DB2. I created a script for example.

BEGIN
SELECT * FROM ABC;
END

Now I want to run it in a report generator where I already have some select queries with joins and everything. The script has a purpose of reading input and parsing that string and store details in a temporary table (this part is done). Now my other select queries will work on this table.

But how do I put both these things in one file or should I create separate files (a procedure from script and execute it in sql report). But I want to know if there is a way of doing it in same file.

Was it helpful?

Solution

In DB2 there is no way to deal with standard input when using scripts in db2clp. This console is only to send commands to DB2, but the commands should already be prepared.

In order to deal with user input, you use shell scripts, like .bat in Windows or bash/korn shell scripts. With these scripts you take the user input, and then construct the commands to send to DB2.

read id
db2 "select * from emp where id = ${id}"

For the previous approach, you need to create scripts for each platform (windows and *NIX-bash or korn)

However, there is another way to deal with user input in DB2 but you need to use CLPPlus. This is like SQL*Plus, and you can get the input from the user into a variable, and then query the database with that value.

OTHER TIPS

What you wrote is an anonymous block. When you call the script, it is executed, but it does not return any output. You need a stored procedure in order to retrieve a result set.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top