oracle递归查询函数
select a.client_department_id, a.parent_id, level "层次", sys_connect_by_path(client_department_id, '->') "合并层次", prior a.client_department_id "父节点", connect_by_root a.client_department_id "根节点", decode(connect_by_isleaf, 1, a.client_department_id, null) "子节点", decode(connect_by_isleaf, 1, '是', '否') "是否子节点"from client.client_department a--where client_department_id=103star
innodb的一些参数设置(zt)
innodb_buffer_pool_size如 果用Innodb,那么这是一个重要变量。相对于MyISAM来说,Innodb对于buffer size更敏感。MySIAM可能对于大数据量使用默认的key_buffer_size也还好,但Innodb在大数据量时用默认值就感觉在爬了。 Innodb的缓冲池会缓存数据和索引,所以不需要给系统的缓存留空间,如果只用Innodb,可以把这个值设为内存的70%-80%。和 key_buffer相同,如果数据量比较小也不怎么增加,那么不要把这个值设太高也可以提高内存的使用率。innodb_additional_pool_size 这个的效果不是很明显,至少是当操作系统能合理分配内存时。但你可能
Merge into 详细介绍(zt)
/*Merge into 详细介绍MERGE语句是Oracle9i新增的语法,用来合并UPDATE和INSERT语句。通过MERGE语句,根据一张表或子查询的连接条件对另外一张表进行查询,连接条件匹配上的进行UPDATE,无法匹配的执行INSERT。这个语法仅需要一次全表扫描就完成了全部工作,执行效率要高于INSERT+UPDATE。 *//*語法:MERGE [INTO [schema .] table [t_alias] USING [schema .] { table | view | subquery } [t_alias] ON ( condition ) WHEN MATCHED THEN merge_update_clause WHEN NOT MATCHED THEN merge_insert_clause;*//*我们还是以《sql中的case应
求当年的日期列表
select to_date('2012-01-01','yyyy-mm-dd')+level-1 from dual connect by level<367[@more@]
sqlserver求标准偏差,oracle求标准偏差(zt)
oracle 求标准偏差:select STDdEV(column1) from (select 50 column1 from dualunion select 90 from dualunion select 70 from dual) ttsqlserver 里求标准偏差:select STDEV(column1) from (select 50 column1 union select 90 union select 70 ) tt[@more@]
Oracle索引碎片分析和整理
频繁对索引字段进行delete、update操作,会对索引造成大量碎片,从而极大地影响索引的使用效率,并造成索引IO的增加。索引碎片分析:analyze index index_name validate structure online;select name,del_lf_rows_len,lf_rows_len,(del_lf_rows_len/lf_rows_len)*100 as "索引碎片率" from index_stats;如果索引碎片率超过20%,则说明索引碎片已经非常严重。可以编写一个检测所有索引碎片率的脚本,定期运行该脚本,保持对索引碎片率的监控。索引碎片整理:重建 alter index index_name rebuild;alter index index_name rebuil
Oracle索引监控特性
Oracle可以监控索引是否使用到打开监控:alter index index_name monitoring usage;关闭监控:alter index index_name nomonitoring usage;之后就可以查看在打开监控和关闭监控之间的时间段里,这个索引是否使用到了。select * from v$object_usage;[@more@]
oracle的lead函数和lag函数研究
lead和lag是偏移量函数,可以查出同一个字段上一个值和下一个值,在新列中显示,需要结合开窗函数进行显示数据准备:create table test(test_id varchar2(10),test_name varchar2(10),test_value number);insert into test values('1','aaa',10);insert into test values('1','bbb',20);insert into test values('1','ccc',30);insert into test values('2','ddd',40);insert into test values('2','eee',50);insert into test values('3','fff',60);commit;lead函数:select test_id,test_name,test_value,lead(test_value,1,null)over(p
Oracle中NVARCHAR2和VARCHAR2的区别(zt)
Oralce官方文档“Datatypes”部分对NVARCHAR2、VARCHAR2以及VARCHAR有一段描述,可以清晰得到它们的区别。罗列在此,供大家参考。【链接】http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements001.htm#sthref71NVARCHAR2 DatatypeThe NVARCHAR2 datatype is a Unicode-only datatype. When you create a table with an NVARCHAR2 column, you supply the maximum number of characters it can hold. Oracle subsequently stores each value in the column exactly as you specify it, provided the value does n
打开和关闭回收站
10g可以用:alter system set recyclebin=off; 和alter system set recyclebin=on;来关闭和开启11g可以用:alter system set recyclebin=off deferred; 和alter system set recyclebin=on deferred;来关闭和开启[@more@]
DG 主备机切换(zt)
DG 主备机切换主机 alter database commit to switchover to physical standby;如果出现以下错误:ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected解决方法: alter database commit to switchover to physical standby with session shutdown;没有问题后:shutdown immediate startup mountalter database recover managed standby database disconnect from session;主机切为备机结束。 备机操作:alter database commit to switchover to primary;shutdown immediatestartup备机变为主机。最大保护出现以下
清空回收站(zt)
从Oracle10g开始删除数据库表的时候并不是真正删除表,而是把表放到了recyclebin中,这个过程类似于windows里面删除的文件会被临时放到回收站中。 删除的表系统会自动给他重命名就是大家看到的【BIN$】开头的名字。 通过show recyclebin命令可以查看被删掉的表的详细信息,或者查询: select * from recyclebin; 收回表的命令: flashback table 原表名 to before drop; 清空回收站的命令: purge recyclebin; 如果想直接删除表而不经过回收站: drop table 表名 p
对磁盘条带化性能的探索(zt)
1. 环境说明主机: IBM P520CPU: 4695MHz × 4内存: 15744MB操作系统: AIX 6100-06存储: 400GB × 4(主机自带磁盘)# lspvhdisk0 00cbc586dda5fad1 rootvg activehdisk1 00cbc586d6338d91 rootvg activehdisk2 00cbc586551a042f testvg activehdisk3 00cbc586551a04b7 testvg active# lsvg testvgVOLUME GROUP: testvg VG IDENTIF
Oracle的一个bug,desc的bug,很夸张,这么基础的功能居然有bug
SQL> shutdown immediate数据库已经关闭。已经卸载数据库。ORACLE 例程已经关闭。SQL> startup nomountORACLE 例程已经启动。Total System Global Area 612368384 bytesFixed Size 1292036 bytesVariable Size 234883324 bytesDatabase Buffers 369098752 bytesRedo Buffers 7094272 bytesSQL> desc user_tablesERROR:ORA-04043: ?? user_tables ???SQL> alter database mount;数据库已更改。SQL> alter database open;数据库已更改。SQL> desc user_tablesERROR:ORA-04043: ???? user_tables ??????SQL> exit从 Ora