ORACLE常用问题1000问全集(一)

1. Oracle安装完成后的初始口令?                                         internal/oracle                                          
    sys/change_on_install                              
    system/manager                                            
    scott/tiger                                                  
    sysman/oem_temp                                          
  2. ORACLE9IAS WEB CACHE的初始默认用户和密码?        
    administrator/administrator                  
  3. oracle 8.0.5怎么创建数据库?                              
    用orainst。如果有motif界面,可以用orainst /m      
  4. oracle 8.1.7怎么创建数据库?                              
    dbassist                                                        
  5. oracle 9i 怎么创建数据库?                                  
    dbca                                                                
  6. oracle中的裸设备指的是什么?                                    
    裸设备就是绕过文件系统直接访问的储存空间                                
  7. oracle如何区分 64-bit/32bit 版本?                
  $ sqlplus '/ AS SYSDBA'                              
  SQL*Plus: Release 9 .0.1.0.0 - Production on Mon Jul 14 17:01:09 2003
  (c) Copyright 2001 O racle Corporation. All right s reserved。
  Connected to:                                                  
  Oracle9i Enterprise  Edition Release 9.0.1.0.0 -  Production
  With the Partitioning option                    
  JServer Release 9.0.1.0.0 - Production
  SQL> select * from v$version;

  BANNER                                                                
  -------------------------------- --------------------------------
  Oracle9i Enterprise Edition Rele ase 9.0.1.0.0 - Production
  PL/SQL Release 9.0.1.0.0 - Production  
  CORE 9.0.1.0.0 Production                          
  TNS for Solaris: Ve rsion 9.0.1.0.0 - Production 

  NLSRTL Version 9.0.1.0.0 - Production  
  SQL>

  8. SVRMGR什么意思?                                                
  svrmgrl,Server Manager 9i下没有 ,已经改为用SQLPLUS了
  sqlplus /nolog 变为归档日志型的                              
  9. 请问如何分辨某个用户是从哪台机器登陆ORACLE的?                  


  SELECT machine ,ter minal FROM V$SESSION;
  10. 用什么语句查询字段呢?                                              
  desc table_name 可以查询表的结构                            
  select field_name,. .. from ... 可以查询字段的值 

  select * from all_ta bles where table_name like ' %'
  select * from all_tab_columns wh ere table_name='??'
  11. 怎样得到触发器、过程、函数的创建脚本?                              
  desc user_source                                            
  user_triggers                                                  
  12. 怎样计算一个表占用的空间的大小?                                    
  select owner,table_name,NUM_RO
EMPTY_BLOCKS,LAST_ANALYZED  WS,BLOCKS*AAA/1024/1024 "Size M",

  from dba_tables                                              
  where table_name='XXX';                              


  Here: AAA is the va lue of db_block_size;


  XXX is the table nam e you want to check
  13. 如何查看最大会话数?                                                
  SELECT * FROM V$PARAMETER WHERE  NAME LIKE 'proc%';
  SQL>

  SQL> show parameter processes

  NAME TYPE VALUE                                              
  -------------------- ---------------- ------- --- ---------------------------
  aq_tm_processes integer 1                          
  db_writer_processes integer 1                  
  job_queue_processes integer 4                  
  log_archive_max_processes integer 1      
  processes integer 200                                  
  这里为200个用户。                                                        
  Select * from v$license;                            
  其中sessions_highwater纪录曾经到达的最大会话数            
  14. 如何查看系统被锁的事务时间?                                        
  select * from v$locked_object ;              
  15. 如何以archivelog的方式运行oracle?                  
  init.ora                                                            
  log_archive_start = true                            
  RESTART DATABASE                                            
  16. 怎么获取有哪些用户在使用数据库?                                    
  select username from v$session;              
  17. 数据表中的字段最大数是多少?                                        
  表或视图中的最大列数为 1000                                            
  18. 怎样查得数据库的SID ?                                          
  select name from v$d atabase;也可以直接查看 init .ora文件
  19. 如何在Oracle服务器上通过SQLPLUS查看本机IP地址 ?    
  select sys_context('userenv','i p_address') from dual;
  如果是登陆本机数据库,只能返回127.0.0.1                            
  20. UNIX 下怎么调整数据库的时间?                                  
  su -root                                                            
  date -u 08010000                                            
  21. 在ORACLE TABLE中如何抓取MEMO类型栏为空的资料记录?  
  select remark from o ms_flowrec where trim(' ' fr om remark) is not null ;
  22. 如何用BBB表的资料去更新AAA表的数据(有关联的字段)            
  UPDATE AAA SET BNS_SNM=(SELECT B
WHERE BBB.DPT_NO IS NOT NULL;  NS_SNM FROM BBB WHERE AAA.DPT_NO=BBB.DPT_NO)

  23. P4计算机安装方法                                                  
    将SYMCJIT.DLL改为SYSMCJIT.OLD                    
  24. 如何查询SERVER是不是OPS?                                  
    SELECT * FROM V$OPTION;                          
    如果PARALLEL SERVER=TRUE则有OPS能                
  25. 如何查询每个用户的权限?                                            
    SELECT * FROM DBA_SYS_PRIVS;                
  26. 如何将表移动表空间?                                                
    ALTER TABLE TABL E_NAME MOVE TABLESPACE_NAME ;
  27. 如何将索引移动表空间?                                              
    ALTER INDEX INDE X_NAME REBUILD TABLESPACE TA BLESPACE_NAME;
  28. 在LINUX,UNIX下如何启动DBA STUDIO?              
    OEMAPP DBASTUDIO                                        
  29. 查询锁的状况的对象有?                                              
    V$LOCK, V$LOCKED_OBJECT, V $SESSION, V$SQLAREA, V$PROCESS ;
     查询锁的表的方法:                                                    
  SELECT S.SID SESSION
'Row-S (SS)',3,'Row-X
TO_CHAR(LMODE)) MODE_HEL
3,'Row-X (SX)',4,'Sha
CHAR(REQUEST)) MODE_REQU
OBJECT_TYPE||')',S.TYPE
SYS.DBA_OBJECTS O,V$SES _ID,S.USERNAME,DECODE(LMOD
(SX)',4,'Share',5,'S/Row
D,DECODE(REQUEST,0,'None'
re',5,'S/Row-X (SSX)',6,
ESTED,O.OWNER||'.'||O.OBJEC
LOCK_TYPE,L.ID1 LOCK_ID1,
SION S WHERE L.SID = S.SID A E,0,'None',1,'Null',2,
-X (SSX)',6,'Exclusive',
,1,'Null',2,'Row-S (SS)',
'Exclusive',TO_
T_NAME||' ('||O.
L.ID2 LOCK_ID2 FROM V$LOCK L,
ND L.ID1 = O.OBJECT_ID ;
  30. 如何解锁?                                                          
    ALTER SYSTEM KILL SESSION ‘ SID,SERIR#’;
  31. SQLPLUS下如何修改编辑器?                                    
  DEFINE _EDITOR="<编辑器的完整路经>" -- 必须加上双引号来定义新的编辑器,也可以把这个写在$ORACLE_HOME/sqlplus/admin/glogin.sql里面使它永久有效。

  32. ORACLE产生随机数的函数?                                      
    DBMS_RANDOM.RANDOM                                    
  33. LINUX下查询磁盘竞争状况命令?                                  
    sar -d                                                            
  33. LINUX下查询CPU竞争状况命令?                                
    sar -r                                                            
  34. 查询当前用户对象?                                                  
    SELECT * FROM USER_OBJECTS;                  
    SELECT * FROM DBA_SEGMENTS;                  
  35. 如何获取错误信息?                                                  
    SELECT * FROM USER_ERRORS;                    
  36. 如何获取链接状况?                                                  
    SELECT * FROM DBA_DB_LINKS;                  
  37. 查看数据库字符状况?                                                
    SELECT * FROM NLS_DATABASE_P ARAMETERS;
    SELECT * FROM V$NLS_PARAMETERS;          
  38. 查询表空间信息?                                                    
    SELECT * FROM DBA_DATA_FILES;              
  39. ORACLE的INTERAL用户要口令?                            
    修改 SQLNET.ORA                                              
    SQLNET.AUTHENTICATION_SERVICES=(NTS)
  40. 出现JAVA.EXE的解决办法?                                    
    一般是将ORACLEOR AHOMEXIHTTPSERVER改成手工启 动可以的,X是8或9
  41. 如何给表、列加注释?                                                
  SQL>comment on table 表 is '表注释';

  注释已创建。                                                                
  SQL>comment on column 表.列 is '列注释';

  注释已创建。                                                                
  SQL> select * from user_tab_comments where comments is not null;

  42. 如何查看各个表空间占用磁盘情况?                                    
  SQL> col tablespace format a20

  SQL> select

    b.file_id     文件ID号,                                
    b.tablespace_name    表空间名,                    
    b.bytes     字节数,                                        
    (b.bytes-sum(nvl(a.bytes,0)))  已使用,  
        sum(nvl(a.bytes,0))   剩余空间,          
    sum(nvl(a.bytes, 0))/(b.bytes)*100  剩余百分 比
    from dba_free_space a,dba_da ta_files b
    where a.file_id=b.file_id                      
    group by b.tablespace_name,b .file_id,b.bytes
       order by b.file_id                              
  43. 如把ORACLE设置为MTS或专用模式?                            


  #dispatchers="(PROTO COL=TCP) (SERVICE=SIDXD"
  加上就是MTS,注释就是专用模式,SID是指你的实例名。                    
  44. 如何才能得知系统当前的SCN号 ?                                  
  select max(ktuxescnw * power(2,32) + ktuxescnb) from x$ktuxe;
  45. 请问如何在ORACLE中取毫秒?                                    
  9i之前不支持,9i开始有timestamp。                              
  9i可以用select systimestamp from dual;      
  46. 如何在字符串里加回车?                                              
    select 'Welcome  to visit'||chr(10)||'www.CSD N.NET' from dual ;
  47. 中文是如何排序的?                                                  
    Oracle9i之前,中文是按照二进制编码进行排序的。                  
  在oracle9i中新增了按 照拼音、部首、笔画排序功能。 设置NLS_SORT值:
  SCHINESE_RADICAL_M  按照部首(第一顺序)、笔划( 第二顺序)排序
    SCHINESE_STROKE_M 按照笔划( 第一顺序)、部首(第二顺序)排序
    SCHINESE_PINYIN_M 按照拼音排序                        
  48. Oracle8i中对象名可以用中文吗?                              
    可以                                                                    
  49. 如何改变WIN中SQL*Plus启动选项?                          
  SQL*PLUS自身的选项设 置我们可以在$ORACLE_HOME/sql plus/admin/glogin.sql中设置。
  50. 怎样修改oracel数据库的默认日期?                              
    alter session set nls_date_format='yyyymmddhh 24miss';
    或可以在init.ora中加上一行 nl s_date_format='yyyymmddhh24miss'
  51. 如何将小表放入keep池中?                                        


  alter table xxx stor age(buffer_pool keep);
  52. 如何检查是否安装了某个patch?                                  
    check that oraInventory                          
  53. 如何使select语句使查询结果自动生成序号?                      
  select rownum,COL from table;                  
  54. 如何知道数据裤中某个表所在的tablespace?                  
  select tablespace_name from user _tables where table_name='TEST';
  select * from user_t ables中有个字段TABLESPACE_NA ME,(oracle);
  select * from dba_segments where …;      
  55. 怎么可以快速做一个和原表一样的备份表?                              
    create table new _table as (select * from old _table);
  55. 怎么在sqlplus下修改procedure?                      
    select line,trim(text) t fr
;  om user_source where name =’A’ order by line

  56. 怎样解除PROCEDURE被意外锁定?                              
    alter system kil
session id  l session ,把那个session给
 杀掉,不过你要先查出她的

    或把该过程重新改个名字就可以了。                                        
  57. SQL Reference是个什么东西?                            
    是一本sql的使用手册,包括语法
 、函数等等,Oracle官方网站的文档中心提供下载。

  58. 如何查看数据库的状态?                                              
  UNIX下                                                                  
  ps -ef | grep ora                                          
  Windows下                                                            
  看服务是否起来;是否可以连上数据库                                          
  59. 请问如何修改一张表的主键?                                          
  alter table aaa                                              
  drop constraint aaa_key ;                          
  alter table aaa                                              
  add constraint aaa_key primary k ey(a1,b1) ;
  60. 改变数据文件的大小?                                                
  用 ALTER DATABASE .... DATAFILE .... ;  
  手工改变数据文件的大小,对于原来的 数据文件有没有损害。                    
  61. 怎样查看ORACLE中有哪些程序在运行之中?                        
    查看v$sessions表                                              
  62. 怎么可以看到数据库有多少个tablespace?                    
  select * from dba_tablespaces;                
  63. 如何修改oracle数据库的用户连接数?                            
  修改initSID.ora,将process加大,重启数据库。              
  64. 如何查出一条记录的最后更新时间?                                    
    可以用logminer 察看                                            
  65. 如何在PL/SQL中读写文件?                                      
  UTL_FILE包允许用户通过PL/SQL读写操作系统文件。                
  66. 怎样把“&”放入一条记录中?                                        
  insert into a values (translate ('at{&}t','at{} ','at'));
  67. EXP 如何加QUERY参数?                                      
  EXP USER/PASS FILE=A.DMP TABLES( BSEMPMS)
  QUERY='"WHERE EMP_NO=\'S09394\'\"﹔        
  68. 关于oracle8i支持简体和繁体的字符集问题?                    
    ZHS16GBK可以支持                                                
  69. Data Guard是什么软件?                                    
  就是Standby的换代产品                                                
  70. 如何创建SPFILE?                                              
  SQL> connect / as sysdba

  SQL> select * from v$version;

  SQL> create pfile from spfile;

  SQL> CREATE SPFILE FROM PFILE='E:\ora9i\admin\eygle\pfile\init.ora';

  文件已创建。                                                                
  SQL> CREATE SPFILE='E:\ora9i\database\SPFILEEYGLE.ORA' FROM PFILE='E:\ora9i\admin\eygle\pfile\init.ora';

  文件已创建。                                                                
  71. 内核参数的应用?                                                    
  shmmax                                                                
    含义:这个设置并不决定究竟Or
了最多可以使用的内存数目。这个设置也 acle数据库或者操作系统使用多少物理内存,只决定
不影响操作系统的内核资源。
    设置方法:0.5*物理内存                                              
    例子:Set shmsys:shminfo_sh mmax=10485760
    shmmin                                                            
    含义:共享内存的最小大小。                                              
    设置方法:一般都设置成为1。                                            
    例子:Set shmsys:shminfo_shmmin=1:          
    shmmni                                                            
    含义:系统中共享内存段的最大个数。                                      
    例子:Set shmsys:shminfo_shmmni=100        
    shmseg                                                            
    含义:每个用户进程可以使用的最多的共享内存段的数目。                    
    例子:Set shmsys:shminfo_shmseg=20:        
    semmni                                                            
    含义:系统中semaphore identifierer的最大个数。    
    设置方法:把这个变量的值设置
大的那个processes的那个值加10。  为这个系统上的所有Oracle的实例的init.ora中的最

    例子:Set semsys:seminfo_semmni=100        
    semmns                                                            
    含义:系统中emaphores的最大个数。                              
    设置方法:这个值可以通过以下
的processes的值的总和(除去最大的Pro
Oracle实例的个数。  方式计算得到:各个Oracle实例的initSID.ora里边
cesses参数)+最大的那个Processes×2+10×

    例子:Set semsys:seminfo_semmns=200        
    semmsl                                                            
    含义:一个set中semaphore的最大个数。                        
    设置方法:设置成 为10+所有Oracle实例的InitSI D.ora中最大的Processes的值。
    例子:Set semsys:seminfo_semmsl=-200      
  72. 怎样查看哪些用户拥有SYSDBA、SYSOPER权限?              
  SQL>conn sys/change_on_install

  SQL>select * from V_$PWFILE_USERS;

  73. 如何单独备份一个或多个表?                                          
  exp 用户/密码 tables=(表1,…,表2)                        
  74. 如何单独备份一个或多个用户?                                        
    exp system/manag er owner=(用户1,用户2,…, 用户n) file=导出文件
  75. 如何对CLOB字段进行全文检索?                                    
  SELECT * FROM A WHERE dbms_lob.instr(a.a,'K',1,1)>0;

  76. 如何显示当前连接用户?                                              
    SHOW USER                                                      
  77. 如何查看数据文件放置的路径?                                        
  col file_name format a50                            
  SQL> select tablespace_name,file_id,bytes/1024/1024,file_name from dba_data_files order by file_id;

  78. 如何查看现有回滚段及其状态?                                        
  SQL> col segment format a30

  SQL> SELECT SEGMENT_NAME,OWNER,TABLESPACE_NAME,SEGMENT_ID,FILE_ID,STATUS FROM DBA_ROLLBACK_SEGS

  79. 如何改变一个字段初始定义的Check范围?                          
  SQL> alter table xxx drop constraint constraint_name;

  之后再创建新约束:                                                          
  SQL> alter table xxx add constraint constraint_name check();

  80. Oracle常用系统文件有哪些?                                    
  通过以下视图显示这些文件信息:v$
v$parameter;  database,v$datafile,v$logfile v$controlfile

  81. 内连接INNER JOIN?                                        
  select a.* from bsempms a,bsdpt ms b where a.dpt_no=b.dpt_no;
  82. 如何外连接?                                                        
    select a.* from bsempms a,b sdptms b where a.dpt_no=b.dpt_no(+);
    select a.* from bsempms a,b sdptms b wherea.dpt_no(+)=b.dpt_no;
  83. 如何执行脚本SQL文件?                                            
    SQL>@$PATH/filename.sql;

  84. 如何快速清空一个大表?                                              
  SQL>truncate table table_name;

  85. 如何查有多少个数据库实例?                                          
    SQL>SELECT * FROM V$INSTANCE;

  86. 如何查询数据库有多少表?                                            
  SQL>select * from all_tables;

  87. 如何测试SQL语句执行所用的时间?                                  
  SQL>set timing on;

    SQL>select * from tablename;

  88. CHR()的反函数?                                                
    ASCII()                                                          
    SELECT CHAR(65) FROM DUAL;                    
    SELECT ASCII('A') FROM DUAL;                
  89. 字符串的连接                                                        
    SELECT CONCAT(COL1,COL2) FROM TABLE;
    SELECT COL1||COL2 FROM TABLE;              
  90. 怎么把select出来的结果导到一个文本文件中?                    
    SQL>SPOOL C:\ABCD.TXT;

    SQL>select * from table;

    SQL >spool off;

  91. 怎样估算SQL执行的I/O数 ?                                    
    SQL>SET AUTOTRACE ON ;

    SQL>SELECT * FROM TABLE;

    或                                                                      
    SQL>SELECT * FROM v$filestat;可以查看IO数

  92. 如何在sqlplus下改变字段大小?                                
    alter table tabl e_name modify (field_name va rchar2(100));
    改大行,改小不行(除非都是空的)                                        
  93. 如何查询某天的数据?                                                
    select * from table_name whe
'yyyy-mm-dd');  re trunc(日期字段)=to_date('2003-05-02',

  94. sql 语句如何插入全年日期?                                      
  create table BSYEAR (d date);                  
  insert into BSYEAR                                        
  select to_date('20030101','yyyy mmdd')+rownum-1
  from all_objects                                            
  where rownum <= to_char(to_date('20031231','yyyymmdd'),'ddd');

  95. 如果修改表名?                                                      
    alter table old_ table_name rename to new_tab le_name;
  96. 如何取得命令的返回状态值?                                          
  sqlcode=0                                                          
  97. 如何知道用户拥有的权限?                                            
    SELECT * FROM dba_sys_privs ;              
  98. 从网上下载的ORACLE9I与市场上卖的标准版有什么区别?          
      从功能上说没有区别,只不
品不得用于商业用途,否则侵权。  过oracle公司有明文规定;从网站上下载的oracle产

  99. 怎样判断数据库是运行在归档模式下还是运行在非归档模式下?            
  进入dbastudio,历程--〉数据库---〉归档查看。                  
  100. sql>startup pfile和ifile,spfile有什么区别?

  pfile就是Oracle传统的初始化参数文件,文本格式的;                
  ifile类似于c语言里的include,用于把另一个文件引入;            
  spfile是9i里新增的并且是默认的参数文件,二进制格式;                
  startup后应该只可接pfile。 

你可能感兴趣的:(oracle)