额···,你看我之前发过了一个帖子就知道咯,我问过同一个问题的,上次是一个merge的方法,但是没看懂--a为中间表,b为传入数据的表 merge into tab1 a using tab2 b on (a.aid=b.aid and a.bid=b.bid) when not matched then insert values (b.aid,b.bid); 这个是当时他们给我的sql,但是,tab2表是什么啊?不懂
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Connected as studySQL> select * from subs; MSID MS_TYPE AREACODE ---------- ------- -------- 905310001 0 531 905320001 1 532 905330001 2 533SQL> select * from acct; MSID BILL_MONTH AREACODE FEE ---------- ---------- -------- ----------SQL> SQL> merge into acct a 2 using subs b on (a.msid=b.msid) 3 when MATCHED then 4 update set a.areacode=b.areacode 5 when NOT MATCHED then 6 insert(msid,bill_month,areacode) 7 values(b.msid,'200702',b.areacode);DoneSQL> select * from acct; MSID BILL_MONTH AREACODE FEE ---------- ---------- -------- ---------- 905320001 200702 532 0.00 905330001 200702 533 0.00 905310001 200702 531 0.00SQL> insert into subs values(905340001,3,534);1 row insertedSQL> select * from subs; MSID MS_TYPE AREACODE ---------- ------- -------- 905340001 3 534 905310001 0 531 905320001 1 532 905330001 2 533SQL> SQL> merge into acct a 2 using subs b on (a.msid=b.msid) 3 when NOT MATCHED then 4 insert(msid,bill_month,areacode) 5 values(b.msid,'200702',b.areacode);DoneSQL> select * from acct; MSID BILL_MONTH AREACODE FEE ---------- ---------- -------- ---------- 905320001 200702 532 0.00 905330001 200702 533 0.00 905310001 200702 531 0.00 905340001 200702 534 0.00SQL> update subs set areacode=999;4 rows updatedSQL> select * from subs; MSID MS_TYPE AREACODE ---------- ------- -------- 905340001 3 999 905310001 0 999 905320001 1 999 905330001 2 999SQL> select * from acct; MSID BILL_MONTH AREACODE FEE ---------- ---------- -------- ---------- 905320001 200702 532 0.00 905330001 200702 533 0.00 905310001 200702 531 0.00 905340001 200702 534 0.00SQL> SQL> merge into acct a 2 using subs b on (a.msid=b.msid) 3 when MATCHED then 4 update set a.areacode=b.areacode;DoneSQL> select * from acct; MSID BILL_MONTH AREACODE FEE ---------- ---------- -------- ---------- 905320001 200702 999 0.00 905330001 200702 999 0.00 905310001 200702 999 0.00 905340001 200702 999 0.00SQL> 看看,能看明白不
这是我之前做的
OP操作员
序号 列名 数据类型 长度 空? 说明
1 OP_ID numeric 20 否 PK
2 GROUP_ID numeric 20 是 FK
3 ROLE_ID numeric 20 是 FK
4 OP_NAME varchar 20 是
5 PWD varchar 20 是 登录密码
6 ADD_TIME datetime 8 是 发生时间
7 ISDELETE Bit 1 否 是否删除
OP_GROUP部门表
序号 列名 数据类型 长度 空? 说明
1 GROUP_ID numeric 20 否 PK
2 GROUP_NAME varchar 50 是
3 ADD_TIME datetime 8 是 发生时间
4 ISDELETE Bit 1 否 是否删除
OP_ROLE操作角色对应表
序号 列名 数据类型 长度 空? 说明
1 ID numeric 20 否 PK
2 OP_ID numeric 9 是 FK
3 ROLE_ID numeric 9 是 FK
4 STATUS int 1 是
5 ISDELETE Bit 1 否 是否删除
ROLE角色
序号 列名 数据类型 长度 空? 说明
1 ROLE_ID numeric 20 否 PK
2 GROUP_ID numeric 20 是 部门ID
3 ROLE_NAME varchar 50 是 访问权限: admin/guest
4 ADD_DATE datetime 8 是
5 ISDELETE Bit 1 否 是否删除
ROLE_PERMISSION角色权限
序号 列名 数据类型 长度 空? 说明
1 ID numeric 20 否 PK
2 ROLE_ID numeric 20 是 FK
3 RES_ID numeric 20 是 FK
4 PERMISSION varchar 20 是 权限(admin:超级权限, guest:只读)
5 STATUS int 1 是 状态(0:没有权限; 1:有权限)
7 ISDELETE Bit 1 否 是否删除
RES_ALLOC资源分配表
序号 列名 数据类型 长度 空? 说明
1 ID numeric 20 否 PK
2 RES_ID numeric 20 是 FK
3 GROUP_ID numeric 20 是 FK
4 STATUS int 1 是 状态(0:不可用; 1:可用)
5 ISDELETE Bit 1 否 是否删除
RESOURCE资源
序号 列名 数据类型 长度 空? 说明
1 RES_ID numeric 20 否 PK
2 PARENT_ID numeric 20 是 父级ID
3 RES_NAME varchar 50 是
4 RES_URL varchar 200 是
5 CONTENT varchar 500 是
6 ADD_TIME datetime 8 是 发生时间
7 ISDELETE Bit 1 否 是否删除
merge into tab1 a
using tab2 b
on (a.aid=b.aid and a.bid=b.bid)
when not matched then
insert values (b.aid,b.bid);
这个是当时他们给我的sql,但是,tab2表是什么啊?不懂
Connected as studySQL> select * from subs; MSID MS_TYPE AREACODE
---------- ------- --------
905310001 0 531
905320001 1 532
905330001 2 533SQL> select * from acct; MSID BILL_MONTH AREACODE FEE
---------- ---------- -------- ----------SQL>
SQL> merge into acct a
2 using subs b on (a.msid=b.msid)
3 when MATCHED then
4 update set a.areacode=b.areacode
5 when NOT MATCHED then
6 insert(msid,bill_month,areacode)
7 values(b.msid,'200702',b.areacode);DoneSQL> select * from acct; MSID BILL_MONTH AREACODE FEE
---------- ---------- -------- ----------
905320001 200702 532 0.00
905330001 200702 533 0.00
905310001 200702 531 0.00SQL> insert into subs values(905340001,3,534);1 row insertedSQL> select * from subs; MSID MS_TYPE AREACODE
---------- ------- --------
905340001 3 534
905310001 0 531
905320001 1 532
905330001 2 533SQL>
SQL> merge into acct a
2 using subs b on (a.msid=b.msid)
3 when NOT MATCHED then
4 insert(msid,bill_month,areacode)
5 values(b.msid,'200702',b.areacode);DoneSQL> select * from acct; MSID BILL_MONTH AREACODE FEE
---------- ---------- -------- ----------
905320001 200702 532 0.00
905330001 200702 533 0.00
905310001 200702 531 0.00
905340001 200702 534 0.00SQL> update subs set areacode=999;4 rows updatedSQL> select * from subs; MSID MS_TYPE AREACODE
---------- ------- --------
905340001 3 999
905310001 0 999
905320001 1 999
905330001 2 999SQL> select * from acct; MSID BILL_MONTH AREACODE FEE
---------- ---------- -------- ----------
905320001 200702 532 0.00
905330001 200702 533 0.00
905310001 200702 531 0.00
905340001 200702 534 0.00SQL>
SQL> merge into acct a
2 using subs b on (a.msid=b.msid)
3 when MATCHED then
4 update set a.areacode=b.areacode;DoneSQL> select * from acct; MSID BILL_MONTH AREACODE FEE
---------- ---------- -------- ----------
905320001 200702 999 0.00
905330001 200702 999 0.00
905310001 200702 999 0.00
905340001 200702 999 0.00SQL>
看看,能看明白不
差不多了,但是,这个merge方法可以执行前台传来的东西里没有,而数据库里有的删除吗?