473,385 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to for dummies

In an SQL procedure which I'm going to use for a model for several
others, I tried:

DECLARE v_schema character(8) default 'is2';
SELECT bhid INTO v_tmp_bhid FROM v_schema.animals
WHERE prefix=v_tmp_prefix
AND regnum=v_tmp_regnum;

so that I didn't have to change the schema in every SQL statement in the
procedure.

It failed, as I really expected, pointing to v_schema.animals as an
unknown name. The question is: how do I achieve the substitution for the
schema, the table name, or both together throughout an SQL procedure?

Nov 12 '05 #1
6 5142
IF your schema is fixed you do this:

-- Set the default schema fro table resolution
SET SCHEMA = IS2
@
-- Set the default PATH for function resolution
SET PATH = CURRENT PATH, I2
@
-- Create procedure using CURRENT SCHEMA and CURRENT PATH
CREATE PROCEDURE
BEGIN
....
SELECT bhid INTO v_tmo_bhid FROM animals WHERE ...
END
@

If your schema is provided by the caller of the procedure
You will need to use dyamic SQL. Check out
PREPARE/EXECUTE or EXECUTE IMMEDIATE

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
IF your schema is fixed you do this:

-- Set the default schema fro table resolution
SET SCHEMA = IS2
@
-- Set the default PATH for function resolution
SET PATH = CURRENT PATH, I2
@
-- Create procedure using CURRENT SCHEMA and CURRENT PATH
CREATE PROCEDURE
BEGIN
....
SELECT bhid INTO v_tmo_bhid FROM animals WHERE ...
END
@

If your schema is provided by the caller of the procedure
You will need to use dyamic SQL. Check out
PREPARE/EXECUTE or EXECUTE IMMEDIATE

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3
Serge Rielau wrote:
IF your schema is fixed you do this:

-- Set the default schema fro table resolution
SET SCHEMA = IS2
@
-- Set the default PATH for function resolution
SET PATH = CURRENT PATH, I2
@
-- Create procedure using CURRENT SCHEMA and CURRENT PATH
CREATE PROCEDURE
BEGIN
...
SELECT bhid INTO v_tmo_bhid FROM animals WHERE ...
END
@

If your schema is provided by the caller of the procedure
You will need to use dyamic SQL. Check out
PREPARE/EXECUTE or EXECUTE IMMEDIATE

Cheers
Serge


Thank you; I forgot about SET SCHEMA = IS2. It's effect on the following
is static, correct? In this case, it makes no difference, but I want to
be sure I understand.

Nov 12 '05 #4
Serge Rielau wrote:
IF your schema is fixed you do this:

-- Set the default schema fro table resolution
SET SCHEMA = IS2
@
-- Set the default PATH for function resolution
SET PATH = CURRENT PATH, I2
@
-- Create procedure using CURRENT SCHEMA and CURRENT PATH
CREATE PROCEDURE
BEGIN
...
SELECT bhid INTO v_tmo_bhid FROM animals WHERE ...
END
@

If your schema is provided by the caller of the procedure
You will need to use dyamic SQL. Check out
PREPARE/EXECUTE or EXECUTE IMMEDIATE

Cheers
Serge


Thank you; I forgot about SET SCHEMA = IS2. It's effect on the following
is static, correct? In this case, it makes no difference, but I want to
be sure I understand.

Nov 12 '05 #5
Correct, the effect is static for the static queries. It's dynamic for
the dynamic queries.
All your static queries will use teh schema as in effect at CREATE
PROCEDUER time. All dynamic queries will use the schema as set by the
caller (inherited) or within the procedural flow.

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #6
Correct, the effect is static for the static queries. It's dynamic for
the dynamic queries.
All your static queries will use teh schema as in effect at CREATE
PROCEDUER time. All dynamic queries will use the schema as set by the
caller (inherited) or within the procedural flow.

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #7

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

Similar topics

60
by: K. G. Suarez | last post by:
Hello everyone. I am new to programming and my uncle gave me a copy of "C For Dummies 2nd Edition". I am up to chapter 9 right now. He probably saw me struggling with "The C Programming...
10
by: Roy Lawson | last post by:
Can anyone explain the difference between RowStateFilter and RowFilter properties of the DataView objects in simple terms? I am going through a Transcender practice exam and just when I think I...
3
by: maigork | last post by:
C All-In-One Desk Reference For Dummies.pdf if it exist can anyone tell me where i can dovnload it? Thank you verry much!!!!
2
by: Carlo Stonebanks | last post by:
I have the infamous GoF Design Patterns boo - it's been sittin gon my shelf for years. I have a huge reading list and find this book a rather dry read and am always putting it off. I have...
2
by: Shelly | last post by:
I know C, C++ and Java. I have been using "procedural" PHP. I get the list of classes for PHP, but I need a "PHP OOP for Dummies" on how to implement these. Any pointers to a tutotial? Shelly
0
by: Spam Catcher | last post by:
Is there a "For Dummies" guide to the Component UI Application Blocks (CAB)? CAB seems to do what I need for a new application I'm building... but the documentation provided with the Quickstart...
0
by: paul james | last post by:
Hello There Im in the asp.net 2.0 for dummies by Bill Hatfield. Its harder than i thought but I wont quit till i get it . But on page161 chapter 11 listing 11-6 I type it in but can not get it to...
5
by: salmobytes | last post by:
I'm working on a mini-micro CMS that amounts to a semi-automatic page-generation system that allows authorized users to manipulate an administrative menu. Once installed, the system is...
0
by: Daryl | last post by:
New to programming C++? How to learn it good and fast? See this : http://freebooks2007.blogspot.com Have C++ books for dummies, and even more like expert, can see it too.. Check it out! ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.