当前位置:文档之家› oracle常用笔记总结

oracle常用笔记总结

1、用dba权限的用户查看数据库都有哪些锁select ername,t2.sid,t2.serial#,t2.logon_timefrom v$locked_object t1,v$session t2where t1.session_id=t2.sid order by t2.logon_time;2、查看有哪些对象被锁了select b.owner,b.object_name,a.session_id,a.locked_modefrom v$locked_object a,dba_objects bwhere b.object_id = a.object_id3、根据sid查找进程idselect pro.spid from v$session ses,v$process pro where ses.sid=129 and ses.paddr=pro.addr;select ses.sid from v$session ses,v$process pro where pro.spid=129 and ses.paddr=pro.addr;4:根据这个spid对应linux下的进程pidlinux命令:ps -ef | gre | 'ora' (找到所有ora开头的进程)kill -9 (pid)5、解决delete后表的高水位的问题初步判断应该是之前有大量数据,后来delete了,选成高水位,用shrink清除高水位:alter table t_mobile_client_tp_prov enable row movement;alter table t_mobile_client_tp_prov shrink space;重新收集统计信息:begindbms_stats.gather_table_stats(ownname=>'traffic',tabname=>'T_MOBILE_CLIENT_TP_PR end;6、ORA-02064 distributed operation not supportedCause:One of the following unsupported operations was attempted:Array execute of a remote update with a subquery that references a database link, orAn update of a long column with bind variable and an update of a second column with a subquery that both references a database link and a bind variable, orA commit is issued in a coordinated session from an RPC with OUT parameters.Action:Simplify the remote update statement.问题: 数据库A ,B 通过DBlink互相访问, 数据库A 调用数据库B的存储过程pro_b , pro_b 过程中有out 输出参数,并且里面有dml语句,之后commit ,或rollback. 这时数据库A 通过DBlink 的调用pro_b@B就会产生这个错误.解决办法:a. 去掉pro_b中的commit, rollback ,统一有数据库B来控制事务.(当然也可以去掉out参数,这样也破坏是事务的完整性)b.用自制事务来控制pro_b , 在pro_b中添加.PRAGMA AUTONOMOUS_TRANSACTION; 优点:不用去修改调用的所有方法.当然这样也不能控制事务的完整.7、建表开启并行v_table_sql := 'CREATE TABLE T_MOBILE_CAP_DETA82_'||in_date||' parallel (degree 4) as '||' select /*+parallel(t1 4) */ * fromT_MOBILE_CAP_DETAIL_'||in_date||'@QAS82 t1';EXECUTE IMMEDIATE v_table_sql;8、创建dblinkCREATE DATABASE LINK CONNECT TO TRAFFICIDENTIFIED BY "pwd"USING '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.228.65)(PORT=1521)))(CONNECT_DATA=(SID=qas)))'9、创建临时表a.create global temporary table temp_tbl(col_a varchar2(30))on commit preserve rows(当提交后保留数据,session结束时才清除数据)b.create global temporary table temp_tbl(col_a varchar2(30))on commit delete rows (当提交后不保留数据,session结束时也清除数据)10、drop后的表被放在回收站(user_recyclebin)里,而不是直接删除掉。

这样,回收站里的表信息就可以被恢复,或彻底清除。

a.通过查询回收站user_recyclebin获取被删除的表信息,然后使用语句 flashback table <user_recyclebin.object_name oruser_recyclebin.original_name> to before drop [rename to<new_table_name>];将回收站里的表恢复为原名称或指定新名称,表中数据不会丢失。

若要彻底删除表,则使用语句:drop table <table_name> purge;b.清除回收站里的信息清除指定表:purge table <table_name>;清除当前用户的回收站:purge recyclebin;清除所有用户的回收站:purge dba_recyclebin;11、REGEXP_SUBSTR函数格式如下:function REGEXP_SUBSTR(String, pattern, position, occurrence, modifier)__srcstr :需要进行正则处理的字符串__pattern :进行匹配的正则表达式__position :起始位置,从第几个字符开始正则表达式匹配(默认为1)__occurrence :标识第几个匹配组,默认为1__modifier :模式('i'不区分大小写进行检索;'c'区分大小写进行检索。

默认为'c'。

)例:selectregexp_substr(call_logs,'\d*',instr(call_logs,'"duration":"')+12,1,'i'),call_logs from t_mobile_callogs_sdk_20130519 where upper(client_type) like'%C8812%'12、alter table T_MON_APP_COOP modify mark varchar(10)13、alter table T_MOBILE_CAP_USE_20130822 drop column is_run14、ORACLE利用TNS控制远程访问的IP地址利用TNS可以实现IP地址的过滤。

如下:在D:\oracle\ora92\network\admin的sqlnet.ora文件中添加你需要排除或者允许访问的地址按照规定格式TCP.VALIDNODE_CHECKING = YES 该参数表明会对连接进行验证TCP.EXCLUDED_NODES= (10.83.25.44) 该参数表明排除该地址的访问TCP.INVITED_NODES= (10.83.25.125) 该参数表明允许该地址的访问如果有多个地址怎么搞?很简单,全部都搞就好了。

TCP.INVITED_NODES= (10.83.25.125, 10.83.25.1)中间用逗号隔开。

首先查看当前使用的数据库实例:select name from V$database;切换两个数据库实例在sqlplus里connect username/passWord@sid或host set ORACLE_SID=sid或cmd里set ORACLE_SID=sid或修改注册表里ORACLE_SID项更改oracle 密码 ALTER USER "TRAFFIC" IDENTIFIED BY "TRAFFIC209";密码过期解决办法1. 查看用户的profile设置:SELECT username,profile FROM dba_users;2. 查看系统profiles中PASSWORD_LIFE_TIME设置:SELECT * FROM dba_profiles s WHERE s.profile='DEFAULT' AND resource_name='PASSWORD_LIFE_TIME';3. 修改DBA_PROFILES中PASSWORD_LIFE_TIM的设置,改为ULIMITEDALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;4. 已经被报告了密码快要过期的账户必须再改一次密码(需要DBA权限)以system用户为例alter user system identified by root;job执行、删除exec dbms_job.run(4);exec dbms_job.remove(4);commit;恢复delete的数据select * from T_MOBILE_REPORT_LOG as of timestampto_timestamp('20131220 9:40:00','yyyy-mm-dd hh24:mi:ss')where error_info like '%ORA%' order by op_date desc其中时间点只要在删除之前就行了ALTER SYSTEM SET db_block_buffers=1677721 SCOPE=BOTH;生成awr报告@/home/oracle/product/10.2.0/rdbms/admin/awrrpt.sql;@/home/oracle/product/11.2.0/rdbms/admin/awrrpt.sql;@/home/oracle/11g/oracle/product/11.2.0/dbhome_1/rdbms/admin/awrrpt.sql; oracle : oinstall asmdba dba oper警告日志目录select * from v$diag_info;oracle 中 NLSSORT函数的用法NLSSORT(),用来进行语言排序拼音SELECT * FROM TEAM ORDER BY NLSSORT(排序字段名,'NLS_SORT = SCHINESE_PINYIN_M')笔划SELECT * FROM TEAM ORDER BY NLSSORT(排序字段名,'NLS_SORT = SCHINESE_STROKE_M')部首SELECT * FROM TEAM ORDER BY NLSSORT(排序字段名,'NLS_SORT = SCHINESE_RADICAL_M')plsq求余if mod(to_number(substr(in_date,7,2)),2)=0 thenend ifselect * from dba_objects a,v$locked_object b where a.object_id = b.object_id;ORACLE里锁有以下几种模式:0:none1:null 空2:Row-S 行共享(RS):共享表锁,sub share3:Row-X 行独占(RX):用于行的修改,sub exclusive4:Share 共享锁(S):阻止其他DML操作,share5:S/Row-X 共享行独占(SRX):阻止其他事务操作,share/sub exclusive 6:exclusive 独占(X):独立访问使用,exclusiveselect object_name,machine,s.sid,s.serial# from v$locked_objectl,dba_objects o ,v$session s where l.object_id = o.object_id andl.session_id=s.sid;ps -ef|grep LOCAL=NO|grep -v grep|cut -c 9-15|xargs kill -9dbms_space_admin.segment_drop_corruptexec dbms_space_admin.segment_corrupt('TRAFFIC',153,977835);exec dbms_space_admin.segment_drop_corrupt('TRAFFIC',153,977835); exec dbms_space_admin.tablespace_verify ('TRAFFIC');select 'execdbms_space_admin.segment_corrupt(''TRAFFIC'','||HEADER_FILE||','||HEADER FROMdba_segments where segment_type like 'TEMP%' and tablespace_name='TRAFFIC'让数据文件脱机alter database datafile '/oradata/qas/traffic23.dbf' offline drop;alter database datafile '/oradata/qas/system02.dbf' offline drop;系统全局区SGA:SGA包含的组件:共享池(shared pool);数据库缓冲区高速缓存(database buffer cache);日志缓冲区(redo buffer cache);大池;Java池;流池等。

相关主题