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 > SQL stored procedures

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-07-04, 01:38
Dipanjan Dipanjan is offline
Registered User
 
Join Date: Sep 2003
Posts: 84
SQL stored procedures

I had posted this question earlier but did not get any reply - may be I was not very clear with my query.

We are on UDB V8.1 ( on AIX)
Is it possible for me to create a stored proc (A) in schema X and access
tables/views in schema Y ? How do I do this ? Because currently I am building the SP from within the development center where I can only specify the schema to which the SP should belong.

I am not doing the bind step explicitly.

Can someone tell me what are the steps to be followed in such a case ?
Also if there is a way to specify the function path while building the SQL stored proc.

Any help is greatly appreciated.
Reply With Quote
  #2 (permalink)  
Old 02-23-04, 13:26
dmmac dmmac is offline
Registered User
 
Join Date: Aug 2003
Location: Massachusetts, USA
Posts: 106
Re: SQL stored procedures

All you need to do is place the schema as the prefix to the table or view you are calling in the stored proc. ie. TEST.table_a.

You can also create synonyms (called aliases) for the tables under the schema for which the stored proc is associated.

Quote:
Originally posted by Dipanjan
I had posted this question earlier but did not get any reply - may be I was not very clear with my query.

We are on UDB V8.1 ( on AIX)
Is it possible for me to create a stored proc (A) in schema X and access
tables/views in schema Y ? How do I do this ? Because currently I am building the SP from within the development center where I can only specify the schema to which the SP should belong.

I am not doing the bind step explicitly.

Can someone tell me what are the steps to be followed in such a case ?
Also if there is a way to specify the function path while building the SQL stored proc.

Any help is greatly appreciated.
Reply With Quote
  #3 (permalink)  
Old 02-26-04, 07:29
Dipanjan Dipanjan is offline
Registered User
 
Join Date: Sep 2003
Posts: 84
Thanks for your suggestion.

I think I was not very clear with my query.
My objective was to keep the code independent of the schema and then to bind the code against objects in the schema by specifying the schema name as we can do while binding C/COBOL programs.

So is it possible not to explicitly code the schema but specifying it while building the SQL stored procedures ?
Reply With Quote
  #4 (permalink)  
Old 02-27-04, 11:25
jsander jsander is offline
Registered User
 
Join Date: Apr 2003
Posts: 191
Hi,

I don't think you can do that.

But if you script your STPs in SQL and use unqualified object names you can deploy them with an initial SET CURRENT SCHEMA <whatever>, which would do the binding to that schema behind the scenes.

Johann

Quote:
Originally posted by Dipanjan
Thanks for your suggestion.

I think I was not very clear with my query.
My objective was to keep the code independent of the schema and then to bind the code against objects in the schema by specifying the schema name as we can do while binding C/COBOL programs.

So is it possible not to explicitly code the schema but specifying it while building the SQL stored procedures ?
Reply With Quote
  #5 (permalink)  
Old 02-29-04, 22:15
kraman_usa kraman_usa is offline
Registered User
 
Join Date: Feb 2004
Posts: 7
Re: SQL stored procedures

Hello

To me, rather than exploring how to access tables/views defined in another schema, I would explore how you can possibly execute SP from another schema, being in a particular schema.

I don't think inter-schema execution of SP is possible. When you try do a CALL to an SP in schema Y, being in a SP in schema X, I don't think the runtime would automatically attach schema Y.

To my knowledge, an SP call within an SP can only inherit SCHEMA with which the calling SP is executed.

If my understanding of your problem is not correct, let me know





------------------------------------------------------------------------------
Quote:
Originally posted by Dipanjan
I had posted this question earlier but did not get any reply - may be I was not very clear with my query.

We are on UDB V8.1 ( on AIX)
Is it possible for me to create a stored proc (A) in schema X and access
tables/views in schema Y ? How do I do this ? Because currently I am building the SP from within the development center where I can only specify the schema to which the SP should belong.

I am not doing the bind step explicitly.

Can someone tell me what are the steps to be followed in such a case ?
Also if there is a way to specify the function path while building the SQL stored proc.

Any help is greatly appreciated.
Reply With Quote
  #6 (permalink)  
Old 03-01-04, 09:11
Dipanjan Dipanjan is offline
Registered User
 
Join Date: Sep 2003
Posts: 84
thanks jsander. I have not yet found a solution to my problem and it would seem that it is not possible to bind SQL procs explicitly to objects belonging to a different schema.

As to the solution suggested - if I do a SET CURRENT schema this will mean that the SP will be placed in the schema specified in the SET CURRENT SCHEMA and it will access objects belonging to the same schema.

For k raman -
I was referring to a scenario where I want my SQL stored proc to be in schema X and access objects ( views/tables) belonging to schema Y without explicitly qualifying these with the schema name within the code.
For C/Cobol pgms we can do this where in the bind step we can give the qualifier explicitly.
Reply With Quote
  #7 (permalink)  
Old 03-01-04, 18:12
kraman_usa kraman_usa is offline
Registered User
 
Join Date: Feb 2004
Posts: 7
I agree with the our friend who suggested to use SET CURRENT SCHEMA.. I think it is doable in that way....

-------------------------------------------------------------------------

Quote:
Originally posted by Dipanjan
thanks jsander. I have not yet found a solution to my problem and it would seem that it is not possible to bind SQL procs explicitly to objects belonging to a different schema.

As to the solution suggested - if I do a SET CURRENT schema this will mean that the SP will be placed in the schema specified in the SET CURRENT SCHEMA and it will access objects belonging to the same schema.

For k raman -
I was referring to a scenario where I want my SQL stored proc to be in schema X and access objects ( views/tables) belonging to schema Y without explicitly qualifying these with the schema name within the code.
For C/Cobol pgms we can do this where in the bind step we can give the qualifier explicitly.
Reply With Quote
  #8 (permalink)  
Old 03-01-04, 22:51
Dipanjan Dipanjan is offline
Registered User
 
Join Date: Sep 2003
Posts: 84
But obviously if you do a SET CURRENT SCHEMA X. Then the SP and the objects accessed will all belong to schema X. That is , it will not serve the original purpose of having the SP in one schema and the objects referenced within it ( tables/views etc.) in a different schema
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