oracle如何更新如下的数据,在线等结果(200分)

  • 主题发起人 主题发起人 boy2002cn
  • 开始时间 开始时间
B

boy2002cn

Unregistered / Unconfirmed
GUEST, unregistred user!
已经有的数据
pcode xh areacode
2005-00001 1 0001
2005-00001 2 0001
2005-00001 3 0001
2005-00001 1 0002//这一行是错误数据,我要把它更新成
          //2005-00001 4 0001
我用的oracle,急
 
先del 在insert
 
直接update也可以的啊.
 
可以直接在数据库中改数据,不用写SQL,如果用SQL的话只能先删掉,然后再插入数据!~
 
zzz20005:
  数据不能删除的,太多了。

maxubodelphi:
  我给的这3个都是主键没有办法更新的,如果只是pcode=2005-00001还好说,关键是可能有几万个pcode每个pcode对应不同的序号,怎么更新,我找不到要更新的数据呀,还有序号如果实现递增。
pcode xh areacode  sj
2005-00001 1 0001 2006-1-1
2005-00001 2 0001 2006-1-2
2005-00001 3 0001 2006-1-4
2005-00001 1 0002 2006-1-3
要更新成
2005-00001 1 0001 2006-1-1
2005-00001 2 0001 2006-1-2
2005-00001 4 0001 2006-1-4
2005-00001 3 0002 2006-1-3
也就是说前面的序号也不能用,只能从时间这一列得到新的序号
 
如果你意思是序号用SJ字段的日期值的话可以这样:
update mytable set xh=to_number(to_char(sj, 'dd'))

如果你XH字段也是主键之一的话可能会产生冲突

实现递增的方法是用"序列"
 
toad for oracle version 8.5.3的Authorization Key是多少呀,我怎么找不到呢,我的数据库现在过期啦,不能用啦,请各位帮一下忙.
 
没有办法,那个XH不是由时间产生的,只是一个递增的序号,我没法用序列,
那个序号只是相当明细中的一个内部编号,我现在想办法看能不能不要那个序号就可以更新了,可是要是不要序号这一列, 那程序里可要改不少东东了
 
用分析函数row_number

SQL> insert into test values ('2005-00001',1,'0001',to_date('2006-1-1','YYYY-MM-DD'));

1 row inserted

SQL> insert into test values ('2005-00001',2,'0001',to_date('2006-1-2','YYYY-MM-DD'));

1 row inserted

SQL> insert into test values ('2005-00001',3,'0001',to_date('2006-1-4','YYYY-MM-DD'));

1 row inserted

SQL> insert into test values ('2005-00001',4,'0002',to_date('2006-1-3','YYYY-MM-DD'));

1 row inserted

SQL> insert into test values ('2005-00002',1,'0001',to_date('2006-1-1','YYYY-MM-DD'));

1 row inserted

SQL> insert into test values ('2005-00002',2,'0001',to_date('2006-1-2','YYYY-MM-DD'));

1 row inserted

SQL> insert into test values ('2005-00002',3,'0001',to_date('2006-1-4','YYYY-MM-DD'));

1 row inserted

SQL> insert into test values ('2005-00002',4,'0002',to_date('2006-1-3','YYYY-MM-DD'));

1 row inserted

SQL> commit;

Commit complete

SQL>
SQL> update test t set t.xh=(
2 select tt.num from (select row_number() over (partition by pcode order by sj) as num,
3 t1.* from test t1)tt where tt.pcode=t.pcode and tt.areacode=t.areacode and tt.sj=t.sj)
4 ;

8 rows updated

SQL> commit;

Commit complete

SQL> select * from test;

PCODE XH AREACODE SJ
---------- ---------- -------- -----------
2005-00001 1 0001 2006-1-1
2005-00001 2 0001 2006-1-2
2005-00001 4 0001 2006-1-4
2005-00001 3 0002 2006-1-3
2005-00002 1 0001 2006-1-1
2005-00002 2 0001 2006-1-2
2005-00002 4 0001 2006-1-4
2005-00002 3 0002 2006-1-3

8 rows selected
 
谢谢大家,终于完成了
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
751
SUNSTONE的Delphi笔记
S
S
回复
0
查看
758
SUNSTONE的Delphi笔记
S
后退
顶部