Home > Database > Mysql Tutorial > oracle关键字作为字段名使用方法

oracle关键字作为字段名使用方法

WBOY
Release: 2016-06-07 17:55:51
Original
1267 people have browsed it

有时我们在定义字段名及别名时所用名与oracle关键字同名,这时该如何处理呢,本文将详细介绍,需要了解的朋友可以参考下

有时我们在定义字段名及别名时所用名与oracle关键字同名,这时该如何处理呢?
其实很简单,只要在此关键字加上"",如"group"
看下面的例子:
代码如下:
SQL> DROP TABLE k;
Table dropped
-- 建立表K,字段名为UID(oracle关键字)
SQL> CREATE TABLE k(UID INT);
CREATE TABLE k(UID INT)
ORA-00904: : invalid IDENTIFIER
-- 字段名加""表创建成功
SQL> CREATE TABLE k("UID" INT);
Table created
--插入一些数据
SQL> INSERT INTO k VALUES(1);
1 row inserted
SQL> INSERT INTO k VALUES(2);
1 row inserted
SQL> INSERT INTO k VALUES(3);
1 row inserted
-- 查询时加不加""都正常(似乎不太符合规范)
SQL> SELECT UID FROM k;
UID
----------
5
5
5
SQL> SELECT "UID" FROM k;
UID
---------------------------------------
1
2
3

-- update时必须加上""
SQL> UPDATE k SET UID=5 WHERE UID=3;
UPDATE k SET UID=5 WHERE UID=3
ORA-01747: invalid user.table.column, table.column, or column specification
SQL> UPDATE k SET "UID"=5 WHERE "UID"=3;

1 row UPDATED
总结:oracle可以在"关键字"的形式引用关键字作为字段名与查询语句的别名。如果不是特殊情况最好不要使用,以免引起代码编写过程中的错误。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template