正在看的db2教程是:db2编程序技巧 (三)。 另一种为
pcursor1: for loopcs1 as cousor1 cursor as
select market_code as market_code
from tb_market_code
for update
do
end for;
这种方式的优点是比较简单,不用(也不允许)使用open,fetch,close。
但不能使用with hold 选项。如果在游标循环内要使用commit,rollback则不能使用这种方式。如果没有commit或rollback的要求,推荐使用这种方式(看来for这种方式有问题)。
修改游标的当前记录的方法
update tb_market_code set market_code='0' where current of cursor1;
不过要注意将cursor1定义为可修改的游标
declare cursor1 cursor for select market_code from tb_market_code
for update;
for update 不能和group by、 distinct、 order by、 for read only及union, except, or intersect但 union all除外)一起使用。
1.5 类似decode的转码操作
oracle中有一个函数 select decode(a1,'1','n1','2','n2','n3') aa1 from
db2没有该函数,但可以用变通的方法
select case a1
when '1' then 'n1'
when '2' then 'n2'
else 'n3'
end as aa1 from
1.6 类似charindex查找字符在字串中的位置
locate(‘y','dfdasfay')
查找'y' 在'dfdasfay'中的位置。
1.7 类似datedif计算两个日期的相差天数
days(date(‘2001-06-05')) – days(date(‘2001-04-01'))
days 返回的是从 0001-01-01 开始计算的天数
1.8 写udf的例子
c写见sqllib\samples\cli\udfsrv.c
1.9 创建含identity值(即自动生成的id)的表
建这样的表的写法
create table test
(t1 smallint not null
generated always as identity
(start with 500, increment by 1),
t2 char(1));
在一个表中只允许有一个identity的column.
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
-
-
Mariadb数据库的安装过程
大家都知道甲骨文公司收购了mysql后,有将mysql闭源的潜在风险,而mariadb的目的是完全兼容mysql,包括api和命令行,使之能轻松成为mysql...
[阅读全文]
-
-
-
-
-
-
网友评论