检测和使用 DB2 v8 中的当前模式

发布于 2024-11-30 23:48:53 字数 1391 浏览 1 评论 0原文

我在 iSeries DB2 v8 中有一个非常大的存储过程,它执行以下操作:

  • 调用同一模式内的其他存储过程
  • 从字符串准备动态 sql 语句并运行它们
  • 从同一模式调用其他函数
  • 使用同一模式中的各种表

我的问题是该存储过程和附带的函数可能会从该模式更改为另一个模式(即从“superlib”更改为“restorelib”),并且整个代码当前已硬编码为与指定模式一起运行。

我想要的是能够执行以下两项操作之一:要么通过参数将所有内容所在的模式名称传递给存储过程,要么让存储过程检测模式名称并使用它来运行自身。

这是我当前代码的示例:

SELECT COUNT(*) INTO TotalNotDone FROM superlib.PROCESSTABLES WHERE PROCESS_FLAG < 1; 
WHILE TotalNotDone > 0 DO 
SET SQLLOOPSTMT = 'select name_to_proces from ' CONCAT SOURCELIBRARY CONCAT '.processtables where process_flag = 0' ; 

PREPARE LOOPSTMT FROM SQLLOOPSTMT ; 
OPEN LOOPCUR ; 
FETCH LOOPCUR INTO TABLETOPROCESS ; 

CALL superlib.SP_RESTORE_INSERTS ( SOURCELIBRARY , DESTLIBRARY , TABLETOPROCESS, P_STARTTIME ) ;

CLOSE LOOPCUR;
SELECT COUNT(*) INTO TotalNotDone FROM superlib.PROCESSTABLES WHERE PROCESS_FLAG < 1;  
END WHILE ;

我想要的是 NOT 必须在存储过程中编写 superlib 来调用或引用我正在使用的表,并且只需让存储过程识别它当前位于模式 superlib 中。

我尝试过 SET CURRENT SCHEMA = 'SUPERLIB';SET SCHEMA = 'SUPERLIB'; 但在调用 TABLES 时都不起作用。

我还在创建存储过程时将路径从:更改

SET PATH "QSYS","QSYS2","SYSPROC","SYSIBMADM","PROGUSER1" ; 

SET PATH "QSYS","QSYS2","SYSPROC","SYSIBMADM","SUPERLIB" ; 

,但这显然没有任何作用。

I have a very big Stored Procedure in iSeries DB2 v8 which does the following:

  • Calls other stored procedures inside the same schema
  • Prepares dynamic sql statments from strings and runs them
  • Calls other functions from the same schema
  • Uses various tables from the same schema

My problem is that this Stored Procedure and the accompanying functions may change from that schema into another (ie. from 'superlib' to 'restorelib') and the whole code is currently hardcoded to run with the named schema.

What I want is to be able to do one of the two: either pass the name of the schema where everything is located via a parameter to the stored procedure, or have the stored procedure detect the name of the schema and use it to run itself.

This is a sample of my current code:

SELECT COUNT(*) INTO TotalNotDone FROM superlib.PROCESSTABLES WHERE PROCESS_FLAG < 1; 
WHILE TotalNotDone > 0 DO 
SET SQLLOOPSTMT = 'select name_to_proces from ' CONCAT SOURCELIBRARY CONCAT '.processtables where process_flag = 0' ; 

PREPARE LOOPSTMT FROM SQLLOOPSTMT ; 
OPEN LOOPCUR ; 
FETCH LOOPCUR INTO TABLETOPROCESS ; 

CALL superlib.SP_RESTORE_INSERTS ( SOURCELIBRARY , DESTLIBRARY , TABLETOPROCESS, P_STARTTIME ) ;

CLOSE LOOPCUR;
SELECT COUNT(*) INTO TotalNotDone FROM superlib.PROCESSTABLES WHERE PROCESS_FLAG < 1;  
END WHILE ;

What I want is for NOT to have to write superlib inside the stored procedure to call or reference the tables i'm using and just have the Stored Procedure recognize it currently IS living in the schema superlib.

I've tried SET CURRENT SCHEMA = 'SUPERLIB'; and SET SCHEMA = 'SUPERLIB'; but neither works when calling the TABLES.

I've also changed the path when creating the Stored Procedure from:

SET PATH "QSYS","QSYS2","SYSPROC","SYSIBMADM","PROGUSER1" ; 

to

SET PATH "QSYS","QSYS2","SYSPROC","SYSIBMADM","SUPERLIB" ; 

but that apparently does nothing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

≈。彩虹 2024-12-07 23:48:53

我相信您需要在调用存储过程的连接上设置当前路径,而不仅仅是在创建它时。

请参阅:Weblogic:调用不带架构名称的 DB2 存储过程(属性 currentSchema)

当前路径 文档在这里:http://publib.boulder.ibm.com/infocenter/db2luw/v8//topic/com.ibm.db2.udb.doc/admin/r0005877.htm

i believe you'll need to set the current path on the connection that calls the stored proc, not just when creating it.

see this: Weblogic: Call DB2 stored procedure without schema name (property currentSchema)

current path documentation here: http://publib.boulder.ibm.com/infocenter/db2luw/v8//topic/com.ibm.db2.udb.doc/admin/r0005877.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文