?
Solved

Fenced procedure

Posted on 2008-10-21
5
Medium Priority
?
1,360 Views
Last Modified: 2008-11-11
How do I create a fenced stored procedure. I tried adding FEnced just below create procedure. But it is giving me in valid syntax error. I am using SQL Stored procedure
0
Comment
Question by:pr_r
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 22766525
Hi pr_r,

Fenced SQL procedures were phased out a while back.  (Other fenced functions still exist though.)

With version 8 (and 9), when an SQL procedure is compiled it generates thread-safe code as to not be dangerous to DB2.  Fenced procedures are intended to keep DB2 safe from bad or malicious code.  Since SQL can not generate malicious code, running in fenced mode is an unnecessary performance degradation.

Fenced mode procedures for objects written in other languages, like C still exist.


Good Luck,
Kent
0
 
LVL 2

Author Comment

by:pr_r
ID: 22819697
HI Kent,
I have a procedure which is used extensively. So when the DBA monitored the system , this procedure takes lot of memory. What should I do? one option I thought was fenced. But you are saying that is phaased out. Note. That procedure returns a resultset to the calling program
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 22821224
Making the procedure Fenced will actually hurt performance even more.  In fenced mode, the procedure runs as it's own task and exchanges input and output with DB2.  In non-fenced mode, the procedure runs as part of DB2 and the data is exchanged between the procedure and DB2 by memory address.

It might be that you try to improve the procedure.  Can you post it here?

Kent
0
 
LVL 2

Author Comment

by:pr_r
ID: 22828703
REATE PROCEDURE proc
(IN wher VARCHAR(5000),OUT msgtxt CHAR(100))
    DYNAMIC RESULT SETS 1

BEGIN
    DECLARE stmt VARCHAR(5000);
    DECLARE cur1 CURSOR with return FOR PreparedStatement;
         DECLARE EXIT HANDLER FOR SQLEXCEPTION
                                GET DIAGNOSTICS EXCEPTION 1
                                msgtxt=MESSAGE_TEXT;
    SET stmt = ' SELECT * FROM tab ' || wher;
    PREPARE PreparedStatement FROM stmt;
    --cursor open for Client application
    open cur1;
END
0
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 540 total points
ID: 22830228
Hi pr_r,

I'm not sure what you want from that code.

IBM has a "decent" write up of FENCE / NOT FENCED here:

  http://publib.boulder.ibm.com/infocenter/db2v7luw/index.jsp?topic=/com.ibm.db2v7.doc/db2a0/db2a050.htm


One thing that the article doesn't mention is that at DB2 versions 8 and 9, all SQL procedures run in trusted mode.  For SQL procedures, there is no such thing as FENCED or NOT FENCED.  Since you tagged the original question with DB2 9.1 I'm assuming that your question refers to that version of DB2.  


Kent
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question