If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Stored Procedure Question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-19-09, 05:04
redwolf redwolf is offline
Registered User
 
Join Date: Apr 2004
Posts: 179
Stored Procedure Question

I have a stored procedure which references a view. A column was dropped by the underlying table and the view was changed so it didn't reference the column anymore. The stored procedure still referenced the view and dropped column. My question is how is the stored procedure not invalid, since it references a column that has been dropped and is not inthe view any longer? We did not get an error until we tried to execute the stored procedure.

Thanks
Reply With Quote
  #2 (permalink)  
Old 04-19-09, 07:29
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
When a dependent object is dropped, all the related packages (or plans if on z/OS and using plans) are marked as invalid (not the stored procedure itself). Upon first execution of the invalid package, an automatic rebind is attempted to see if the problem has been corrected, and if it has not, then the package is marked as inoperative and no further automatic rebinds take place (and execution error is returned).

So next time, check for invalid packages, not invalid SP's.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 04-19-09, 10:03
redwolf redwolf is offline
Registered User
 
Join Date: Apr 2004
Posts: 179
I should have said package. I did a rebind on all packages and all were valid. Shouldn't the package in this case have been invalid ?
Reply With Quote
  #4 (permalink)  
Old 04-19-09, 10:25
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Are you sure that the column is actually referenced in a Select, Insert, Update, or Delete statement of the SP? If the column no longer existed you should get an error.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #5 (permalink)  
Old 04-19-09, 11:46
redwolf redwolf is offline
Registered User
 
Join Date: Apr 2004
Posts: 179
Yes, the SP references the column. We get an error message at runtime complaining about the missing column.
Reply With Quote
  #6 (permalink)  
Old 04-19-09, 12:19
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
If the package associated with the SP is still valid, I would guess that the SP is using dynamic SQL. Is this an SQL SP, or Java, C, etc SP?

Even if it is a SQL SP, is any of the SQL dynamically prepared?
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #7 (permalink)  
Old 04-19-09, 14:00
redwolf redwolf is offline
Registered User
 
Join Date: Apr 2004
Posts: 179
Its a SQL SP. Its declaring a global temp table and then inserting into the temp table. The select statement in the within the insert.

declare global temp table:

insert into temp table
(
select ..... (the column that got dropped is in this select statement)
)
Reply With Quote
  #8 (permalink)  
Old 04-19-09, 18:16
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by redwolf
Its a SQL SP. Its declaring a global temp table and then inserting into the temp table. The select statement in the within the insert.

declare global temp table:

insert into temp table
(
select ..... (the column that got dropped is in this select statement)
)
I think you answered your own question.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On