# 查询
SELECT * from "user_info" where "id" = 2; SELECT * from "user_info" where "user_info"."id" = 2;
# 更新
/* 下面sql执行会报错 > ORA-00942: table or view does not exist */ /* 原因就是oracle数据库是区分大小写的,而且oracle的默认为大写的,也就是说在sql脚本上面写的sql语句,oracle运行的时候,它会自动转化为大写,参考 https://www.cnblogs.com/javJoker/p/7069321.html*/ update user_info set password = "666" where id = 3; /* 把表名和字段名都加上双引号来区分大小写 */ /* 加上双引号后执行报错 > ORA-00904: "666": invalid identifier */ /* 解决方法就是把666这个值改为单引号,原因是 password字段的类型为VARCHAR2,只能用单引号 */ update "user_info" set "password" = "666" where "id" = 3; /* 正常sql */ update "user_info" set "password" = '777' where "id" = 3;
# 插入
/* > ORA-00984: column not allowed here 原因是 username和password字段的类型为VARCHAR2,只能用单引号把值包起来 */ INSERT INTO "user_info" ("id","username","password") VALUES (4,"ccc",'111111'); /* 正常sql */ INSERT INTO "user_info" ("id","username","password") VALUES (4,'ccc','111111');
# 删除
/* as 别名问题,执行报错 > ORA-00933: SQL command not properly ended ,原因就是oracle里不需要as关键词,直接空格+别名即可 */ DELETE from "user_info" as ui where ui."id" = 4; /* 正常sql */ delete from "user_info" where "id" = 4; DELETE from "user_info" ui where ui."id" = 4;
原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/5191.html