开发者

How to print variables and values?

In Sybase, I can use select to print, whic开发者_开发问答h seems to be unavailable in db2.

declare @x int
select "begin"

select 1+1

select @x=1
select @x

select "end"
go

How can I do this in db2?

BEGIN ATOMIC

declare x int;

set x=1;
-- select "begin"
-- select x;
-- select 1+1;
-- select "end"
END


Additional options are VALUES (1) and also selecting from the single-row IBM Dummy Table:

 SELECT 1 FROM SYSIBM.SYSDUMMY1


You can do that if you add a FROM clause to your select (you can even create a TEMP TABLE for this purpose, or use an existing one for which you have the SELECT permission). For example: SELECT 'Hello world' FROM MYTEMPTABLE FETCH FIRST 1 ROW ONLY will produce the expexted result.

From DB2 version 9.7 Oracle PL/SQL syntax can be enabled and "print" statements can be used. Check this article: http://www.ibm.com/developerworks/data/library/techarticle/dm-0908anonymousblocks/index.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜