求助,同时修改多张表的一个字段

今夕是何夕123 2017-10-21 11:06:17
数据库有多张表有这个字段LOANS_CODE,现在想让这个字段从00000000001开始自动递增。请问是怎么修改呢?有这个字段的表都有关联。
...全文
724 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
今夕是何夕123 2017-10-23
  • 打赏
  • 举报
回复
引用 10 楼 qq646748739 的回复:
[quote=引用 9 楼 weixin_40150211 的回复:]
[quote=引用 8 楼 qq646748739 的回复:]
这就是另外一个问题了,需要你先找到主表

1.首先更新主表的loans_code
update 主表 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;

2.其次更新关联表的loans_code
update 其他关联表 a set a.loans_code = (sbelect b.loans_code from 主表 b where b.关联字段 = a.关联字段 )
where exists((sbelect 1 from 主表 b where b.关联字段 = a.关联字段 ))


引用 8 楼 qq646748739 的回复:
这就是另外一个问题了,需要你先找到主表

1.首先更新主表的loans_code
update 主表 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;

2.其次更新关联表的loans_code
update 其他关联表 a set a.loans_code = (sbelect b.loans_code from 主表 b where b.关联字段 = a.关联字段 )
where exists((sbelect 1 from 主表 b where b.关联字段 = a.关联字段 ))


非常感谢,很完美[/quote]
不客气,有问题可以随时找我。[/quote]

其中GUAR_ADDRESS这个字段 我想在查询时候把最后面的房号替换成xxx,应该怎么写。用REGEXP_REPLACE直接把所有的数字都替换了。应该怎么指定位置
碧水幽幽泉 2017-10-23
  • 打赏
  • 举报
回复
引用 9 楼 weixin_40150211 的回复:
[quote=引用 8 楼 qq646748739 的回复:]
这就是另外一个问题了,需要你先找到主表

1.首先更新主表的loans_code
update 主表 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;

2.其次更新关联表的loans_code
update 其他关联表 a set a.loans_code = (sbelect b.loans_code from 主表 b where b.关联字段 = a.关联字段 )
where exists((sbelect 1 from 主表 b where b.关联字段 = a.关联字段 ))


引用 8 楼 qq646748739 的回复:
这就是另外一个问题了,需要你先找到主表

1.首先更新主表的loans_code
update 主表 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;

2.其次更新关联表的loans_code
update 其他关联表 a set a.loans_code = (sbelect b.loans_code from 主表 b where b.关联字段 = a.关联字段 )
where exists((sbelect 1 from 主表 b where b.关联字段 = a.关联字段 ))


非常感谢,很完美[/quote]
不客气,有问题可以随时找我。
今夕是何夕123 2017-10-23
  • 打赏
  • 举报
回复
引用 8 楼 qq646748739 的回复:
这就是另外一个问题了,需要你先找到主表

1.首先更新主表的loans_code
update 主表 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;

2.其次更新关联表的loans_code
update 其他关联表 a set a.loans_code = (sbelect b.loans_code from 主表 b where b.关联字段 = a.关联字段 )
where exists((sbelect 1 from 主表 b where b.关联字段 = a.关联字段 ))
引用 8 楼 qq646748739 的回复:
这就是另外一个问题了,需要你先找到主表

1.首先更新主表的loans_code
update 主表 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;

2.其次更新关联表的loans_code
update 其他关联表 a set a.loans_code = (sbelect b.loans_code from 主表 b where b.关联字段 = a.关联字段 )
where exists((sbelect 1 from 主表 b where b.关联字段 = a.关联字段 ))
非常感谢,很完美
碧水幽幽泉 2017-10-21
  • 打赏
  • 举报
回复
这就是另外一个问题了,需要你先找到主表

1.首先更新主表的loans_code
update 主表 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;

2.其次更新关联表的loans_code
update 其他关联表 a set a.loans_code = (sbelect b.loans_code from 主表 b where b.关联字段 = a.关联字段 )
where exists((sbelect 1 from 主表 b where b.关联字段 = a.关联字段 ))
今夕是何夕123 2017-10-21
  • 打赏
  • 举报
回复
引用 6 楼 weixin_40150211 的回复:
[quote=引用 4 楼 weixin_40150211 的回复:]
[quote=引用 3 楼 qq646748739 的回复:]

--1.创建序列
create sequence s_loans_code;

--2.修改每张表的loans_code字段
update 表1 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;
update 表2 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;
.....
update 表n set loans_code = lpad(s_loans_code.nextval,11,0);
commit;

谢谢 已经实现我想要的目的[/quote]
我刚就测试下,等周一去公司再改,想到个问题,关联的表中这个字段呢?因为关联表的数据不一样,这样的话就不都是00000000001开始了。[/quote]

比如这两个表中
今夕是何夕123 2017-10-21
  • 打赏
  • 举报
回复
引用 4 楼 weixin_40150211 的回复:
[quote=引用 3 楼 qq646748739 的回复:]

--1.创建序列
create sequence s_loans_code;

--2.修改每张表的loans_code字段
update 表1 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;
update 表2 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;
.....
update 表n set loans_code = lpad(s_loans_code.nextval,11,0);
commit;
谢谢 已经实现我想要的目的[/quote] 我刚就测试下,等周一去公司再改,想到个问题,关联的表中这个字段呢?因为关联表的数据不一样,这样的话就不都是00000000001开始了。
碧水幽幽泉 2017-10-21
  • 打赏
  • 举报
回复
解决了就好,可以结贴了。
今夕是何夕123 2017-10-21
  • 打赏
  • 举报
回复
引用 3 楼 qq646748739 的回复:

--1.创建序列
create sequence s_loans_code;

--2.修改每张表的loans_code字段
update 表1 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;
update 表2 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;
.....
update 表n set loans_code = lpad(s_loans_code.nextval,11,0);
commit;
谢谢 已经实现我想要的目的
碧水幽幽泉 2017-10-21
  • 打赏
  • 举报
回复

--1.创建序列
create sequence s_loans_code;

--2.修改每张表的loans_code字段
update 表1 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;
update 表2 set loans_code = lpad(s_loans_code.nextval,11,0);
commit;
.....
update 表n set loans_code = lpad(s_loans_code.nextval,11,0);
commit;
今夕是何夕123 2017-10-21
  • 打赏
  • 举报
回复
引用 1 楼 weixin_38847048 的回复:
user_tab_columns 查询 LOANS_CODE有这个字段的表 然后在每个表上建触发器 用同一个序列
请问能具体点吗?
花开了叫我 2017-10-21
  • 打赏
  • 举报
回复
user_tab_columns 查询 LOANS_CODE有这个字段的表 然后在每个表上建触发器 用同一个序列

17,089

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧