gpt4 book ai didi

sql - 使用表的当前值更新语句

转载 作者:行者123 更新时间:2023-12-04 16:25:12 24 4
gpt4 key购买 nike

我想通过将字段之一的整数值增加 1 来更新表中的一行。

电流不工作,为什么?

Update htmIndex SET numObs = numObs+1 where ...

最佳答案

简单案例,更新一行:

SQL> select name
2 , age
3 from t23
4 where id = 2
5 /

NAME AGE
------------ ----------
MR KNOX 47

SQL> update t23
2 set age = age + 6
3 where id = 2
4 /

1 row updated.

SQL> select name
2 , age
3 from t23
4 where id = 2
5 /

NAME AGE
------------ ----------
MR KNOX 53

SQL>

当列具有空值时更新行:
SQL> select name
2 , age
3 from t23
4 where id = 6
5 /

NAME AGE
------------ ----------
SALLY

SQL> update t23
2 set age=age+5
3 where id = 6
4 /

1 row updated.

SQL> select name
2 , age
3 from t23
4 where id = 6
5 /

NAME AGE
------------ ----------
SALLY

SQL> update t23
2 set age = nvl(age,0) +5
3 where id = 6
4 /

1 row updated.

SQL> select name
2 , age
3 from t23
4 where id = 6
5 /

NAME AGE
------------ ----------
SALLY 5

SQL>

更新多行时同样简单:
 SQL> select name
2 , age
3 from t23
4 where age > 20
5 /

NAME AGE
------------ ----------
MR KNOX 53
FOX IN SOCKS 37
CAT 23
LORAX 443

SQL> update t23
2 set age = age + 1
3 where age > 20
4 /

4 rows updated.

SQL> select name
2 , age
3 from t23
4 where age > 20
5 /

NAME AGE
------------ ----------
MR KNOX 54
FOX IN SOCKS 38
CAT 24
LORAX 444

SQL>

关于sql - 使用表的当前值更新语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3178743/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com