我是oracle sqldevelop的新手。 我在这样的更新表中遇到了麻烦。
table1
+----+-----------+------------+
| id | acoount | date |
+----+-----------+------------+
| | John | 2/6/2016 |
| | John | 2/6/2016 |
我有一个名为table1的表。我想更新id只更新一行的地方。 示例:
+----+-----------+------------+
| id | acoount | date |
+----+-----------+------------+
| 1 | John | 2/6/2016 |
| 2 | John | 2/6/2016 |
解决方案如何。感谢
答案 0 :(得分:0)
Oracle安装程序:
CREATE TABLE table1 ( id, account, "date" ) AS
SELECT CAST( NULL AS INT ), 'John', DATE '2016-06-02' FROM DUAL UNION ALL
SELECT CAST( NULL AS INT ), 'John', DATE '2016-06-02' FROM DUAL;
<强>更新强>:
MERGE INTO TABLE1 d
USING ( SELECT ROWNUM AS id, ROWID AS rid FROM Table1 ) s
ON ( d.ROWID = s.RID )
WHEN MATCHED THEN
UPDATE SET d.id = s.id;
<强>结果强>:
SELECT * FROM table1;
ID ACCOUNT date
---------- ------- -------------------
1 John 2016-06-02 00:00:00
2 John 2016-06-02 00:00:00