oracle的timestamp类型使用
我们都知道date和timestamp都是对日期和时间的表示,只是两种类型的精确度不同,前者精确到秒,后者精确到小数秒(fractional_seconds_precision),可以是 0 to 9,缺省是6。但是对date类型的运算很简单,有很多函数可用来处理;而两个timestamp的差则是很直观地显示为多少天+多少小时+多少分钟+多少秒+多少小数秒,SQL> create table test (T1 TIMESTAMP(6),2 T2 TIMESTAMP(6));表已创建。SQL> insert into test values(2 to_timestamp('2006-01-01 12:10:10.1','yyyy-mm-dd hh24:mi:ss.ff'),3 to_timestamp('2006-01-01 12:
Use SYS_CONTEXT to Obtain Session Information
select SYS_CONTEXT('USERENV','TERMINAL') terminal,SYS_CONTEXT('USERENV','LANGUAGE') language,SYS_CONTEXT('USERENV','SESSIONID') sessionid,SYS_CONTEXT('USERENV','INSTANCE') instance,SYS_CONTEXT('USERENV','ENTRYID') entryid,SYS_CONTEXT('USERENV','ISDBA') isdba,SYS_CONTEXT('USERENV','NLS_TERRITORY') nls_territory,SYS_CONTEXT('USERENV','NLS_CURRENCY') nls_currency,SYS_CONTEXT('USERENV','NLS_CALENDAR') nls_calendar,SYS_CONTEXT('USERENV','NLS_DATE_FORMAT') nls_date_format,SYS_CONTEXT('USERENV','NLS_DA
日常sql列表
--监控索引是否使用alter index &index_name monitoring usage;alter index &index_name nomonitoring usage;select * from v$object_usage where index_name = &index_name;--求数据文件的I/O分布select df.name,phyrds,phywrts,phyblkrd,phyblkwrt,singleblkrds,readtim,writetimfrom v$filestat fs,v$dbfile dfwhere fs.file#=df.file# order by df.name;--求某个隐藏参数的值col ksppinm format a54col ksppstvl format a54select ksppinm, ksppstvlfrom x$ksppi pi, x$ksppcv cvwhere cv.indx=pi.indx and pi.ksppinm li
START WITH and CONNECT BY in Oracle SQL
select ... start with initial-condition connect by nocycle recurse-conditionselect ... connect by recurse-conditionselect ... start with initial-condition connect by nocycle recurse-conditionselect ... connect by recurse-conditionThe start with .. connect by clause can be used to select data that has a hierarchical relationship (usually some sort of parent->child (boss->employee or thing->parts). It is also being used when an sql execution plan is explained. recurse-condition can mak
按行数据累加计算
create table test(km varchar2(10), --会计科目dzrq date, --登帐日期jfje number(18,2), --借方金额dfje number(18,2), --贷方金额ye number(18,2) default 0 --余额); insert into test(km,jfje,dfje,dzrq) values('1',300,500,to_date('2006-01-01','yyyy-mm-dd'));insert into test(km,jfje,dfje,dzrq) values('1',600,800,to_date('2006-01-02','yyyy-mm-dd'));insert into test(km,jfje,dfje,dzrq) values('2',300,600,to_date('2006-01-01','yyyy-mm-dd'));insert into test(km,jfje,dfje,dzrq) values('3',700,500,to_date('2006
树形查询
create table test(bm number(8),bmmc varchar2(20),sjbm number(8));insert into test values(1,'aaa',0);insert into test values(11,'aaa1',1);insert into test values(12,'aaa2',1);insert into test values(111,'aaa11',11);insert into test values(112,'aaa12',11);insert into test values(113,'aaa13',11);insert into test values(121,'aaa21',12);insert into test values(122,'aaa22',12);insert into test values(123,'aaa23',12);--select bm,bmmc,sjbm,levelfrom zjstart with sjbm=0connect by prior bm = sjbm;或者sele