我如何在db2中声明和增加局部变量? [英] How do i declare and increment local variables in db2?
本文介绍了我如何在db2中声明和增加局部变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为每个结果集行显示行号,我在mySQL中有这个查询
I want to show row number for each of result set row, I have this query in mySQL
SELECT @rownum := @rownum + 1 row, e.* FROM Employee e, (SELECT @rownum := 0) r
这里@rownum是局部变量,并会为每个结果行增加其值。
我如何在db2(ibm的dashdb)中写这个查询?
Here @rownum is local variable and would increment its value for each result row. How do i write this query in db2 ( ibm's dashdb ) ?
推荐答案
如果您要设置变量并设置值:
If you are looking to set a variable and set a value:
db2 -td@ "begin declare test integer; set test = 1; end @"
或
begin
declare test integer;
set test = 1;
set test = test + 1;
end @
这篇关于我如何在db2中声明和增加局部变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文