先选出符合条件的记录,再将表中的一列日期(本来是空)update为birthday+18*12个月。
下面一直报错说 文字与格式字符串不匹配,为何declare--游标
CURSOR test_cur IS
SELECT id ,birthday FROM tablename;begin
for rec in test_cur loop
--更新
update tablename set engtheenbir = add_months(to_char(rec.birthday,'yyyymm'),18*12) where id = rec.id;
end loop;
--提交
commit;end;
下面一直报错说 文字与格式字符串不匹配,为何declare--游标
CURSOR test_cur IS
SELECT id ,birthday FROM tablename;begin
for rec in test_cur loop
--更新
update tablename set engtheenbir = add_months(to_char(rec.birthday,'yyyymm'),18*12) where id = rec.id;
end loop;
--提交
commit;end;
解决方案 »
- 新手求问!!
- 用SQL语句实现如下格式的统计
- 用sum 和case when 实现分别统计遇到的问题
- ORACLE 10G中有关闪回问题
- 用dblink有哪些坏处?100分
- Help!如何获得销量前5的产品id
- 请问如何在用户登录后只显示自有表和视图,而不显示其他视图
- 问一下装个oracle 9i机器的最低配置是怎么样
- 请问如何将oracle中的几个表的定义(即字段,数据类型,是否为空等内容)保存到txt中?
- 客户端监听程序不能运行!用Net8 Configuration Assistant配置监听程序时提示:为TCP协议提供的信息当前正由其他监听程序使用
- 求实现这样一个功能——简历:
- 存储过程真的比一般的SQL高效吗?
update tablename set engtheenbir = to_char(add_months(rec.birthday,18*12),'yyyymm')
where id = rec.id;
add_months函数第一个参数变成了字符串,它需要的是日期参数如果只是想取生日的月份,可以这样
update tablename set engtheenbir = add_months(to_date(to_char(rec.birthday,'yyyymm'),'yyyymm'),18*12) where id = rec.id;如果只是简单加月份:
update tablename set engtheenbir = add_month(rec.birthday,18*12) where id = rec.id;
功能
返回比日期d大n个月的日期,参数n可以是任意整数。如果d是该月份的最后一天,或者返回值月份的天数比日期d的天数少,则返回值是应返回月份的最后一天;否则返回值与d的日期中的天(day)是一致的。update tablename set engtheenbir = add_months(to_date(to_char(rec.birthday,'yyyymm'),'yyyymm'),18*12) where id = rec.id;如果只是简单加月份:
update tablename set engtheenbir = add_month(rec.birthday,18*12) where id = rec.id;
update tablename set engtheenbir=add_months(birthday,18*12);