[20170728]oracle保留字.txt

--//oracle有许多保留字,我印象最深的就是使用rman备份表空间test,test就是rman里面的保留字.
--//还有rman也是rman里面的保留字.如果在应用中尽量规避不要使用这些保留字.

--//探究一下,oracle内部是否也会不小心这些关键字.

1.环境:
[email protected]> @ ver1
PORT_STRING                    VERSION        BANNER                                                                               CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0           12.1.0.1.0     Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

[email protected]> @ desc v$reserved_words ;
Name       Null?    Type
---------- -------- ----------------------------
KEYWORD             VARCHAR2(30)
LENGTH              NUMBER
RESERVED            VARCHAR2(1)
RES_TYPE            VARCHAR2(1)
RES_ATTR            VARCHAR2(1)
RES_SEMI            VARCHAR2(1)
DUPLICATE           VARCHAR2(1)
CON_ID              NUMBER

[email protected]> select * from v$reserved_words where KEYWORD=‘TEST‘ or keyword=‘RMAN‘;
KEYWORD                            LENGTH R R R R D     CON_ID
------------------------------ ---------- - - - - - ----------
TEST                                    4 N N N N N          0

2.查询看看:
SELECT distinct owner,table_name
  FROM dba_tab_columns
 WHERE column_name IN (SELECT KEYWORD FROM v$reserved_words);

--//输出太多,忽略.没有想到如此之多,还是我查询有问题.找其中一个视图V$RECOVER_FILE.

SELECT  owner,table_name,column_name
  FROM dba_tab_columns
 WHERE column_name IN (SELECT KEYWORD FROM v$reserved_words) and table_name =‘V_$RECOVER_FILE‘;

OWNER TABLE_NAME      COLUMN_NAME
----- --------------- --------------------
SYS   V_$RECOVER_FILE ONLINE
SYS   V_$RECOVER_FILE ERROR
SYS   V_$RECOVER_FILE TIME
SYS   V_$RECOVER_FILE CON_ID
--//有4个字段.

--//官方链接:http://docs.oracle.com/cd/B28359_01/server.111/b28320/dynviews_2126.htm#REFRN30204
V$RESERVED_WORDS

V$RESERVED_WORDS displays a list of all SQL keywords. To determine whether a particular keyword is reserved in any way,
check the RESERVED, RES_TYPE, RES_ATTR, and RES_SEMI columns.

Column     Datatype        Description
KEYWORD    VARCHAR2(30)    Name of the keyword
LENGTH     NUMBER          Length of the keyword
RESERVED   VARCHAR2(1)     Indicates whether the keyword cannot be used as an identifier (Y) or whether the keyword is
                           not reserved (N)
RES_TYPE   VARCHAR2(1)     Indicates whether the keyword cannot be used as a type name (Y) or whether the keyword is not
                           reserved (N)
RES_ATTR   VARCHAR2(1)     Indicates whether the keyword cannot be used as an attribute name (Y) or whether the keyword
                           is not reserved (N)
RES_SEMI   VARCHAR2(1)     Indicates whether the keyword is not allowed as an identifier in certain situations, such as
                           in DML (Y) or whether the keyword is not reserved (N)
DUPLICATE  VARCHAR2(1)     Indicates whether the keyword is a duplicate of another keyword (Y) or whether the keyword is
                           not a duplicate (N)

SELECT *
  FROM v$reserved_words
 WHERE keyword IN (‘ONLINE‘, ‘ERROR‘, ‘TIME‘, ‘CON_ID‘);

KEYWORD LENGTH R R R R D     CON_ID
------- ------- - - - - - ----------
CON_ID       6 N N N N N          0
ERROR        5 N N N N N          0
TIME         4 N N N N N          0
ONLINE       6 N N N Y N          0

[email protected]> select * from V$RECOVER_FILE;
no rows selected

[email protected]> select file#,ONLINE,ERROR, TIME,CON_ID from V$RECOVER_FILE;
select file#,ONLINE,ERROR, TIME,CON_ID from V$RECOVER_FILE
             *
ERROR at line 1:
ORA-00936: missing expression

D:\tools\rlwrap>oerr ora 00936
00936, 00000, "missing expression"
// *Cause:
// *Action:

--//出现这个提示非常具有迷惑性,不过要特别注意下面的星号的位置,指向ONLINE.
--//规避它使用双引号,并且注意要大写:

[email protected]> select file#,"ONLINE",ERROR, TIME,CON_ID from V$RECOVER_FILE;
no rows selected
--//其他字段没问题,除了ONLINE字段.

[email protected]> select file#,"online",ERROR, TIME,CON_ID from V$RECOVER_FILE;
select file#,"online",ERROR, TIME,CON_ID from V$RECOVER_FILE
             *
ERROR at line 1:
ORA-00904: "online": invalid identifier

[email protected]> alter database datafile 9 offline;
Database altered.

[email protected]> select file#,"online",ERROR, TIME,CON_ID from V$RECOVER_FILE;
select file#,"online",ERROR, TIME,CON_ID from V$RECOVER_FILE
             *
ERROR at line 1:
ORA-00904: "online": invalid identifier

[email protected]> select file#,"ONLINE",ERROR, TIME,CON_ID from V$RECOVER_FILE;
     FILE# ONLINE  ERROR   TIME                    CON_ID
---------- ------- ------- ------------------- ----------
         9 OFFLINE         2017-07-27 21:01:22          3

[email protected]> recover datafile 9;
Media recovery complete.

[email protected]> alter database datafile 9 online;
Database altered.

总之:
--//在应用中尽量规避这些保留字,避免不必要的麻烦!!
--//在11g下再补充一些例子:

[email protected]> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

[email protected]> alter tablespace tea rename to test;
Tablespace altered.

RMAN> backup tablespace test ;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "test": expecting one of: "double-quoted-string, identifier, single-quoted-string"
RMAN-01007: at line 1 column 19 file: standard input

[email protected]> alter tablespace test rename to rman;
Tablespace altered.

RMAN> backup tablespace rman ;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "rman": expecting one of: "double-quoted-string, identifier, single-quoted-string"
RMAN-01007: at line 1 column 19 file: standard input

[email protected]> alter tablespace rman rename to tea;
Tablespace altered.

RMAN> backup tablespace tea;
Starting backup at 2017-07-28 08:42:12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=94 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=106 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=119 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf
channel ORA_DISK_1: starting piece 1 at 2017-07-28 08:42:14
channel ORA_DISK_1: finished piece 1 at 2017-07-28 08:42:15
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/backupset/2017_07_28/o1_mf_nnndf_TAG20170728T084214_dqo2364j_.bkp tag=TAG20170728T084214 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2017-07-28 08:42:15
Starting Control File and SPFILE Autobackup at 2017-07-28 08:42:15
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/autobackup/2017_07_28/o1_mf_s_950517735_dqo23786_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2017-07-28 08:42:16

--//在sqlplus的命令中不是的关键字的test,rman,到了rman命令变成了关键字.

时间: 2024-08-28 15:08:41

[20170728]oracle保留字.txt的相关文章

Oracle导出txt文本文件

转自: http://blog.csdn.net/ahngzw77/article/details/8652722 对于SPOOL数据的SQL,最好要自己定义格式,以方便程序直接导入,SQL语句如:  select taskindex||'|'||commonindex||'|'||tasktype||'|'||to_number(to_char(sysdate,'YYYYMMDD')) from ssrv_sendsms_task; spool常用的设置 set colsep' '; //域输

oracle 导入txt

没有Oraclehoume的情况下,执行下环境变量文件 sqlldr userid= DM/DM control = /home/oracle/libc/load.ctl load data infile '/home/oracle/libc/data.txt' insert into table tmp_dm_user_total_month fields terminated by '\t' (acct_date ,provincecode ,citycode ,product_id ,to

oracle保留字

Oracle 关键字(保留字) 大全   转载记录 其实这个东西可以在oracle 上输入一个sql语句就可以得到: select * from v$reserved_words order by keyword asc;   //order 后边不是必须的,那只是个排序,使结果不至于杂乱无章,如果用的是PL/SQL的话的SQL window的话,在获得结果后,可以点击   按钮,使得查询结果不分页,然后可以 右击结果区空白处--->Export results--->Html file(推荐

使用sqlldr向Oracle导入大的文本(txt)文件

我们有多种方法可以向Oracle数据库里导入文本文件,但如果导入的文本文件过大,例如5G,10G的文本文件,有些方法就不尽如意了,例如PLSQL Developer中的导入文本功能,如果文本文件过大,不仅导入速度太慢,中间还容易出错.这时Sqlldr就能大显身手了,Sqlldr可以每秒向Oracle插入5W条数据,可以自定义控制文件,进行导入控制,而且导入过程不易出错,下面简易记录导入过程. 1.Sqlldr导入控制文件说明 1 load data 2 infile '/home/oracle/

sqlldr 向oracle导入csv、txt文件

1.创建控制文件 文件名.ctl 内容 load data   --文件头部 infile '/home/oracle/42.txt'  --要导入文件的绝对路径 truncate  --清表用 into table  用户名.表名 --必须为空表 --append into table  --原表追加 fields terminated by ','   --文件中个列之间的分割字符 Optionally enclosed by '"'  --每个字段都是用""包围 tra

Oracle基础之保留字和关键字

在Oracle之中,有分为保留字和关键字,所谓关键字就是Oracle中有实际意义的,而保留字(比如DESC.ORDER等等)是Oracle中不能随便使用的,比如不能随便用来做表的列名,当然关键字(比如KEY等等)也是不推荐的,不过使用的话是不会报错的,而保留字被使用不当的话是会报错的 然后如何区分保留字和关键字?Oracle中可以通过查询v$reserved_words表得知 查询Oracle保留字SQL: SELECT * FROM v$reserved_words m WHERE m.RES

监控oracle数据库 以及oracle监听 shell脚本

文本格式: #!/bin/bash #Author:wangergui Email:[email protected] Date:2016-10-10 #Release 1.0 #Function: check oracle online declare -a INSTANCE=(PROD EMREP) [[ -f /home/oracle/.bash_profile ]] && . /home/oracle/.bash_profile || exit 3 function check_l

oracle sql语句

##########基本操作##########启动数据库:su - oraclesqlplus / as sysdbaSQL> startup 对scott用户解锁:SQL> conn / as sysdbaSQL> alter user scott identified by tiger account unlock; 连接到指定的数据库用户:SQL> conn scott/tiger 实现操作系统开机数据库自动open:vi /etc/oratab--------------

HP-UX oracle RAC 双机实践 (转载)

一.软硬件配置检查 1.检查内存#/usr/contrib/bin/machinfoCPU info:  4 Intel(R) Itanium 2 9100 series processors (1.59 GHz, 18 MB)          532 MT/s bus, CPU version A1          8 logical processors (2 per socket) Memory: 32737 MB (31.97 GB) Firmware info:   Firmwar