Chinaunix首页 | 论坛 | 博客
  • 博客访问: 447473
  • 博文数量: 135
  • 博客积分: 4177
  • 博客等级: 上校
  • 技术积分: 1145
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-13 17:16
文章分类

全部博文(135)

文章存档

2011年(5)

2010年(4)

2009年(26)

2008年(25)

2007年(29)

2006年(42)

2005年(4)

分类: Oracle

2006-11-24 17:15:53

/*=========================================================================*/
/*            显示最近被改动的10个文件               */
/*=========================================================================*/
ls -alt|head
/*=========================================================================*/
/*            把Oracle的SGA钉在内存中               */
/*=========================================================================*/
HP-UX AND LINUX AS 3
LOCK_SGA = TURE
SUN Solaris
USE_ISM=TRUE

/*=========================================================================*/
/*         汇出数据库成文件                 */
/*=========================================================================*/
exp owner=arms file=(arms_1123-1.dmp,arms_1123-2.dmp,
arms_1123-3.dmp,arms_1123-4.dmp,arms_1123-5.dmp,arms_1123-6.dmp,arms_1123-7.dmp)
 filesize=2GB log=arms_1123.log

imp armsetl/armsetl fromuser=armsetl touser=armsetl rows=y indexes=n
commit=y buffer=65536 feedback=100000 ignore=n volsize=0
file=exp_icd.dmp
--oracle10g中汇入需要system用户做汇入动作
imp fromuser=ARMS  touser=ARMSETL file=(arms_1123-1.dmp,arms_1123-2.dmp,
arms_1123-3.dmp,arms_1123-4.dmp,arms_1123-5.dmp) filesize=2GB  COMMIT=Y log=ARMSETL.log

E:\export>imp fromuser=arms touser=armsetl tables=VW_PAY
MNTRESP indexes=n ignore=y file=VW_PAYMNTRESP.dmp filesize=2GB log=VW_PAYMNTRESP
_imp.log

D:\ARMS_EXP>exp tables=VW_PAYMNTRESP direct=y file=VW_PAYM
NTRESP.dmp filesize=2GB log=VW_PAYMNTRESP.log

/*=========================================================================*/
/*         查看消耗CPU的百分比                 */
/*=========================================================================*/
RHORA*ORA-/etc>ps auxgw|sort +2 |tail
oracle   14482  0.0  3.9 303796 20068 ?      S    17:09   0:01 oracleORA (LOCAL=NO)
oracle   14184  0.0  5.1 303132 26188 ?      S    11:58   0:01 ora_smon_ORA
oracle   14305  0.0  5.9 303280 30208 ?      S    15:08   0:04 oracleORA (LOCAL=NO)
oracle   14216  0.0  6.3 305588 32440 ?      S    12:04   0:10 oracleORA (LOCAL=NO)
oracle   14180  0.1  0.8 308684 4248 ?       S    11:58   0:29 ora_lgwr_ORA
oracle   14178  0.2  7.5 305536 38748 ?      S    11:58   0:50 ora_dbw0_ORA
oracle   14512 14.1 11.2 309252 57364 ?      S    18:05   3:25 oracleORA (LOCAL=NO)
oracle   14289  2.0 12.9 305088 65976 ?      S    13:51   5:44 oracleORA (LOCAL=NO)
oracle   14226  2.3  3.1 305868 16116 ?      S    12:09   8:47 oracleORA (LOCAL=NO)
USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND

/*=========================================================================*/
/*         查看消耗CPU最长时间的进程                 */
/*=========================================================================*/
RHORA*ORA-/etc>ps -ef |grep oracle|sort +6|tail
sort 按第六排排序....
tail显示输出后的多少行.默认为前10行
/*=========================================================================*/
/*          更改字符集问题解决详细请见本人BLOG                    */
/*=========================================================================*/
select userenv('language') from dual;
SIMPLIFIED CHINESE_CHINA.ZHT16BIG5
SIMPLIFIED CHINESE_CHINA.WE8ISO8859P1
SQL> ALTER DATABASE CHARACTER SET ZHT16BIG5;
ALTER DATABASE CHARACTER SET ZHT16BIG5
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set
使用平常的这种方式是不可以更改数据库字符集的.
改了字符集后
SQL> conn / as sysdba;
ERROR:
ORA-12705: invalid or unknown NLS parameter value specified
解决办法:
export NLS_LANG=CHINESE_CHINA.ZHT16BIG5
当服务器客户机无法登录;
/*=========================================================================*/
/*          表空间文件丢失问题解决                    */
/*=========================================================================*/
SQL> startup
ORACLE instance started.

Total System Global Area  236000356 bytes
Fixed Size                   451684 bytes
Variable Size             201326592 bytes
Database Buffers           33554432 bytes
Redo Buffers                 667648 bytes
Database mounted.
ORA-01122: database file 18 failed verification check
ORA-01110: data file 18: '/opt/oracle/product/9.2.0/dbs/LHB.DAT'
ORA-01251: Unknown File Header Version read for file number 18
问题如上所示:没有办法找到LHB.DAT
1.SQL> startup mount
ORACLE instance started.
Total System Global Area  236000356 bytes
Fixed Size                   451684 bytes
Variable Size             201326592 bytes
Database Buffers           33554432 bytes
Redo Buffers                 667648 bytes
Database mounted.
SQL> alter database datafile '/opt/oracle/product/9.2.0/dbs/LHB.DAT' offline drop;
Database altered.
SQL> alter database open;
Database altered.
SQL>

/*=========================================================================*/
/*          修改global_name                     */
/*=========================================================================*/
conn / as sysdba
update props$ set value$ = 'oradb' where name = 'GLOBAL_DB_NAME';
commit;
shutdown immediate
startup
之后再创建dblink即不带域名。


grant connect to arms
/*=========================================================================*/
/*          TO_DATE函数问题解决.                     */
/*=========================================================================*/
select OHDUEDATE,to_date(lhb.OHDUEDATE,'dd/mm/yy') from lhb --写错了这样的一个格式,害得我花了半天的时间
最终总结,要看清格式这点很重要:to_date/'dd/月/yy')...这种方式.'dd/mon/yy'这样解决问题;

/*=========================================================================*/
/*              不断显示输出新的行                       */
/*=========================================================================*/
tail -f logfile.log


/*=========================================================================*/
/*              设置ORACLE下的ksh命令提示符                       */
/*=========================================================================*/
export PS1="`hostname`*\${ORACLE_SID}-\${PWD}>"

/*=========================================================================*/
/*               强制在UNIX下关闭ORACLE进程                       */
/*=========================================================================*/
 ps -ef |grep "ora_"|grep -v grep|awk '{print $2}' |xargs kill -9
 shutdown abort

/*=========================================================================*/
/*               db_block_size                       */
/*=========================================================================*/
show parameter db_block_size     (高速缓存区(Database Buffer Cache))
每个表空间可以建立不同的DB_BLOCK_SIZE     说明:8k的高速缓存通过DB_8K_CACHE_SIZE
参数来设定的.
share pool 存储数据字典高速缓存
当share pool装满时,最近最少使用的执行路径和分析树将从库高速缓存中删除,以便为新的
项腾出空间.

 

/*=========================================================================*/
/*                oracle 9.2.4+linux启动与关闭相关                         */
/*=========================================================================*/
linux+oracle 9.2.4 的启动方法与原来oracle 8.1.7的启动方式有些不同
方式为:
[oracle@RHORA oracle]$ sqlplus /nolog
SQL*Plus: Release 9.2.0.4.0 - Production on Wed Nov 8 17:24:47 2006
Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
SQL> conn / as sysdba
Connected.
SQL> startup
关闭就改为shutdown immediate;

LRM-00109: could not open parameter file '/opt/oracle/product/9.2.0/dbs/initORCL.ora'
把initORA.ora拷贝过去就可以使用了.

ORA-01990: error opening password file '/opt/oracle/product/9.2.0/dbs/orapw'
把密码文件拷贝过去就可以启动了.
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3

/*=========================================================================*/
/*                    utl_file的相关问题                        */
/*=========================================================================*/
查找导出路径:show parameter utl_file_dir     -oracle 8i 可以直接更改初始参数文
件而后重新启动数据库就可以保存;
alter system set utl_file_dir='\home\oracle' scope=spfile;   更改9i的版本可以这样更改
注上面只能更改到spfile(也是所说的内存).要更改到pfile 请从pfile------spfile
呵呵.

startup mount;
recover database until cancel;
alter database open resetlogs;
/*=========================================================================*/
/*                     检查剩余表空间                        */
/*=========================================================================*/
SELECT tablespace_name, sum ( blocks ) as free_blk , 
 
trunc ( sum ( bytes ) /(1024*1024) ) as free_m, 
 
max ( bytes ) / (1024) as big_chunk_k, count (*) as num_chunks 
 
FROM dba_free_space GROUP BY tablespace_name;

/*=========================================================================*/
/*                      JOB按时间去执行存储过程                            */
/*=========================================================================*/
DECLARE
  X NUMBER;
BEGIN
  SYS.DBMS_JOB.SUBMIT
    ( job       => X
     ,what      => 'ARMS1.SP_OUTPUT_COL_CUST_PAY;'
     ,next_date => to_date('26-10-2006 20:09:06','dd/mm/yyyy hh24:mi:ss')
     ,interval  => 'TRUNC(LAST_DAY(SYSDATE)) + 1 + 1/24 + 30/1440'
     ,no_parse  => TRUE
    );
  SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
END;
/
commit;
午夜12点....TRUNC(SYSDATE+1)  
第二天凌晨一点整 ...TRUNC(LAST_DAY(SYSDATE)) + 1 + 1/24
如还要在后面加分钟,可以继续

/*=========================================================================*/
/*                      建立常用输出包                                  */
/*=========================================================================*/
CREATE OR REPLACE Package PKG_APBT  As

    type Type_Ret_Curs is ref Cursor;

    msg_0 CONSTANT VARCHAR2(100) := '執行成功!';
    msg_1 CONSTANT VARCHAR2(100) := '執行失敗!';
    msg_2 CONSTANT VARCHAR2(100) := '沒有該紀錄!';
    msg_3 CONSTANT VARCHAR2(100) := '主鍵已經存在!';
    msg_4 CONSTANT VARCHAR2(100) := '長度太長!';
    msg_5 CONSTANT VARCHAR2(100) := '輸入參數不能為空!';
    msg_6 CONSTANT VARCHAR2(100) := '沒有數據!';
    msg_7 CONSTANT VARCHAR2(100) := '用戶不存在!';
    msg_9 CONSTANT VARCHAR2(100) := '輸入參數不正確!';
End;
/

/*=========================================================================*/
/*                      建日志表                                  */
/*=========================================================================*/
CREATE TABLE LOGDATA
(
  LOG_DATE    VARCHAR2(20)     DEFAULT to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') NOT NULL,
  OPERATOR    VARCHAR2(50),
  LOG_TYPE    CHAR(1),
  USER_TABLE  VARCHAR2(50),
  INFO        VARCHAR2(4000),
  SYS_TYPE    NUMBER(1)   DEFAULT 0     NOT NULL
)
/*=========================================================================*/
/*                      建立同义词并使用                                   */
/*=========================================================================*/
我们先看如下的一系列执行:

SQL> create or replace view v_bmw_pay_online_new as
  2  select *
  3  from ;
 
SQL> create or replace procedure sp_v_test is
  2  v_id number;
  3  begin
  4     select id into v_id from v_bmw_pay_online_new where id=1;
  5  end;
  6  /

Procedure created

SQL> create or replace synonym s_bmw_pay_online_new
  2        for ;

Synonym created

SQL> create or replace procedure sp_s_test is
  2  v_id number;
  3  begin
  4     select id into v_id from s_bmw_pay_online_new where id=1;
  5  end;
  6  /

Warning: Procedure created with compilation errors

SQL> show error
Errors for PROCEDURE TAOBAO.SP_S_TEST:

LINE/COL ERROR
-------- ------------------------------------------------------------------------------------
4/29     PL/SQL: ORA-00600: 内部错误代码,参数: [17069], [0x57E77854], [], [], [], [], [], []
4/4      PL/SQL: SQL Statement ignored


可以看到,在同样一个远程对象上面,我可以通过创建视图,然后在该视图上创建存储过程,是没有任何问题的,
但是如果我对该远程操作做一个同义词,再在同义词上创建存储过程,则报出了Ora-00600。跟踪也无果,
看产生的日志文件也不能看出来什么,上metalink,搜索"ora-00600 17069",发现查出现的东西一大堆,
大致是library cache错误,但是到底怎么会产生这个错误呢,online联系上一个oracle在线技术支持,聊了一会儿,
问题是解决了,但是他就是不承认是bug,呵呵。

以下是聊天的总结:
ORA-00600 [17069] reorted on compiling a procedure.

Invalid lock in library cache.
Unable to pin the object and hence the Error.

"Failed to pin a library cache object after 50 attempts"

Clearing the shared memory will help to get rid of inconsistant information
in memory which is causing the error.

The inconsistency was suspected to be in the remote site. But flushing the
shared pool in remote location didnt help.Tried recreation of the procedure
after dropping and recreating the synonym in the local database. But the
same failed.Flushed the shared pool in local database abd successfully
created the procedure.

alter system flush share_pool;

/*=========================================================================*/
/*                      建立同义词并使用                                   */
/*=========================================================================*/
create synonym synonym_name for ;
select * from table_name;

/*=========================================================================*/
/*                      建立DB-LINK连接并使用                              */
/*=========================================================================*/
设置之前请设置alter system set global_names = false
create public database link db_link
connect to user identified by pwd
using 'connect string';
select sysdate from ;

/*=========================================================================*/
/*                               插入时间串                                */
/*=========================================================================*/
insert into test(IMPORT_DATE) values
(to_date('2002-10-20 15:30:00','yyyy-mm-dd hh24:mi:ss'));
insert into test(testtime) values(sysdate);
取得时候可以to_char(sysdate,'yyyy-mm-dd   hh24:mi:ss')

/*=========================================================================*/
/*                      更改表时记录其变化的TRIGGER                        */
/*=========================================================================*/
CREATE OR REPLACE TRIGGER T_APBT_CONTRACT_ALL_AIUDR
after insert or update or delete on APBT_CONTRACT_ALL
for each row   
/*无论一条语句改变了多少条记录,ORACLE对于每条记录触发一次触发器*/
/*before和after的区别:事件发生前还是事件发生后*/
begin
    if inserting then
        insert into A_APBT_CONTRACT_ALL(ID,CONTRACT_SERIAL_NUM,flag)
        values (Seq_APBT_ARMS.NEXTVAL,:new.CONTRACT_SERIAL_NUM,1);/* :new*/
    elsif updating then
        insert into A_APBT_CONTRACT_ALL(ID,CONTRACT_SERIAL_NUM,flag)
        values (Seq_APBT_ARMS.NEXTVAL,:old.CONTRACT_SERIAL_NUM,2);
        /*此句存在问题*/
    elsif deleting then
        insert into A_APBT_CONTRACT_ALL(ID,CONTRACT_SERIAL_NUM,flag)
        values (Seq_APBT_ARMS.NEXTVAL,:old.CONTRACT_SERIAL_NUM,3);
    end if;
end;
/

/*=========================================================================*/
/*                      你能够创建被如下语句所触发:                        */
/*=========================================================================*/
DML语句( DELETE,INSERT,UPDATE)
DDL语句( CREATE,ALTER,DROP)
数据库操作( SERVERERROR, LOGON, LOGOFF, STARTUP, SHUTDOWN)

/*=========================================================================*/
/*                                  建立sequence序列:                        */
/*=========================================================================*/
DROP SEQUENCE ARMS.SEQ_APBT_ARMS;
CREATE SEQUENCE ARMS.SEQ_APBT_ARMS
  START WITH 30
  MAXVALUE 999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER;

阅读(1717) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~