Db2 Global Variable Insert Example

   

  Asked by Anonymous - Db2 Global Variable Insert Example :
Can anyone show example of inserting using a db2 global variable or similar example to show how this works? Thx

Anonymous Says:
What have you tried so far?

Anonymous Says:
Here is a simple example with insert. First off I assume you have create the global variable because thats the first step.

Then you set the value of the variable
Set test.my_value = 'This is my text'

Then you use that global variable in your sql insert

insert into test.my_table
(field1, field2, field3)
Values ('testing','testing',test.myvalue)

I didnt test this but I dont see a syntax error, but get the idea.

Anonymous Says:
whoops type thats test.my_value on the variable

Anonymous Says:
great, thx

Anonymous Says:
Why would I use this as I could just set a host variable without global variable?

Anonymous Says:
You are right that you could just use host var but you are assuming its a program.  There are times where maybe you setup a JCL job that is just doing many db2 inserts so there is no cobol code, this would allow you to set the global var at the top so its the same across all inserts below it, and you dont have to make changes all over the place, just change at the top etc.

Add your reply below ...


Your Nickname:

Your Reply:

Type the code: