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

查看:23
本文介绍了如何在 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 文档 EXECUTE 和 PREPARErel="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天全站免登陆