如何在DB2中执行SQL字符串 [英] How to execute an SQL string in DB2

查看:157
本文介绍了如何在DB2中执行SQL字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在DB2中执行SQL字符串语句?我正在使用IBM Data Studio。

How do I execute an SQL string statement in DB2? I'm using IBM Data Studio.

推荐答案

您是说要执行动态SQL字符串?

Do you mean executing a dynamic SQL string? Something like:

DECLARE stmt VARCHAR(1000);
DECLARE my_table VARCHAR(50);
SET my_table = 'DEPT_'||deptNumber;
SET stmt = 'SELECT * FROM '||my_table;
PREPARE s1 FROM stmt;
EXECUTE s1;

尽管如此,您只能在存储过程中执行此操作。在此示例中,一个定义为 CREATE PROCEDURE GetDeptInfo(deptNumber VARCHAR(5))的示例。在db2文档执行和 PREPARE 的信息。 com / infocenter / db2luw / v9r5 / index.jsp rel = noreferrer> http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/index.jsp

You can only do that in a stored proc though. One defined as CREATE PROCEDURE GetDeptInfo (deptNumber VARCHAR(5)) for this example. Read about EXECUTE and PREPARE in the db2 docs http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/index.jsp

这篇关于如何在DB2中执行SQL字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆