17:00:59 SQL> desc dbms_random;
Element Type
---------- ---------
SEED PROCEDURE
VALUE FUNCTION
NORMAL FUNCTION
STRING FUNCTION
INITIALIZE PROCEDURE
RANDOM FUNCTION
TERMINATE PROCEDURE
NUM_ARRAY TYPE
使用desc命令查看该过程的结构,其中我们需要用到的也就values 、normal、string、random这四个函数吧,这四个函数都具有取随机值的功能,具体呢就不太一样了。
且看:
17:01:06 SQL> select dbms_random.value() from dual;
DBMS_RANDOM.VALUE()
-------------------
0.0536824248407651
17:05:09 SQL> select dbms_random.value(10,100) from dual;
DBMS_RANDOM.VALUE(10,100)
-------------------------
29.2420951206225
17:05:27 SQL> select dbms_random.value(-1,-4) from dual;
DBMS_RANDOM.VALUE(-1,-4)
-------------- ......
单值函数在查询中返回单个值,可被应用到select,where子句,start with以及connect by 子句和having子句。
(一).数值型函数(Number Functions)
数值型函数输入数字型参数并返回数值型的值。多数该类函数的返回值支持38位小数点,诸如:COS, COSH, EXP, LN, LOG,
SIN, SINH, SQRT, TAN, and TANH 支持36位小数点。ACOS, ASIN, ATAN, and
ATAN2支持30位小数点。
1、MOD(n1,n2) 返回n1除n2的余数,如果n2=0则返回n1的值。
例如:SELECT MOD(24,5) from DUAL;
2、ROUND(n1[,n2])
返回四舍五入小数点右边n2位后n1的值,n2缺省值为0,如果n2为负数就舍入到小数点左边相应的位上(虽然oracle
documents上提到n2的值必须为整数,事实上执行时此处的判断并不严谨,即使n2为非整数,它也会自动将n2取整后做处理,但是我文档中其它提到
必须为整的地方需要特别注意,如果不为整执行时会报错的)。
例如:SELECT ROUND(23.56),ROUND(23.56,1),ROUND(23.56,-1) from DUAL;
3、TRUNC(n1[,n2] 返回截尾到n2位小数的n1的值,n2缺省设置为0,当n2为缺省设置时会将n1截尾为整数,如果n2为负值,就截尾在小数点左边相应的位上。
例如:SELE ......
很不幸,建立的表被某人误删了,,,
还好可以通过这样恢复。
select * from user_recyclebin where original_name like 'FINANCE_%' order by droptime desc;
FLASHBACK TABLE FINANCE_CASE_FEE_ITEM TO BEFORE DROP
即所有drop的表都在 user_recyclebin 这个oracle回收站里面的,再通过flashback命令还原即可。
看了网上还可以通过调整oracle时间 ,回到删除的某一状态的。,关键词“闪回” ......
Oracle 中的树查询和 connect by
使用 connect by 和 start with 来建立类似于树的报表并不难,只要遵循以下基本原则即可:
使用 connect by 时各子句的顺序应为:
select
from
where
start with
connect by
order by
prior 使报表的顺序为从根到叶(如果 prior 列是父辈)或从叶到根(如果 prior 列是后代)。
where 子句可以从树中排除个体,但不排除它们的子孙(或者祖先,如果 prior 列是后代)。
connect by 中的条件(尤其是不等于)消除个体和它所有的子孙(或祖先,依赖于怎样跟踪树)。
connect by 不能与 where 子句中的表连接在一起使用。
下面是几个例子
1. 从根到叶遍历
SELECT n_parendid, n_name, (LEVEL - 1), n_id
from navigation
WHERE n_parendid IS NOT NULL
START WITH n_id = 0
CONNECT BY n_parendid = PRIOR n_id;
2. 从叶到根遍历
SELECT n_parendid, n_name, (LEVEL - 1), n_id
from navigation
WHERE n_parendid IS NOT NULL
START WITH n_id = 300
CONNECT BY n_id = PRIOR n_parendid;
3. 排除个体,但不排除它们的子孙
SELECT n_parendid, n_name, (LEVEL - 1), n_id
from navigation
WHERE n_parend ......
ADDM (Automatic Database Diagnostic Monitor) implements the Oracle performance method and analyzes statistics to provide automatic diagnosis of major performance problems. Because ADDM can significantly shorten the time required to improve the performance of a system, it is one of the most used performance tuning tools of Oracle database.
1. Run some operations on your database instance.
First, start your database instance and do the database operations (select, update, delete...) which will be optimized. e.g. run a script to make some queries in database:
sh run.sh -r rdf1mm-performance -t p -f p3.txt
2. Login to EM
Login to Database EM home page (https://:5500/em), click Performance tab.
3. Run ADDM
Click Button "Run ADDM Now", and click "Yes" on the confirmation page. After a while, we will see the ADDM analysis page.
Database Activity chart shows the database activity during the ADDM analysis period.
In the ADDM Performance Analysis table, ADDM findings are listed ......
由于系统中数据不断增多,使得原用的like语法来进行查询法律全文变得十分缓慢,因此在原有系统中增加了全文检索的功能。
全文检索功能依赖于Oracle Text。首先保证Oracle Text组件在数据库中已安装。然后建立索引
Sql代码
--法律全文内容字段增加索引
create index idx_flqw_nr on flqw(nr) indextype is ctxsys.context;
--法律条款字段增加索引
create index idx_fltk_nr on fltk(nr) indextype is ctxsys.context;
由于Oracle Text使用的ctxsys.context类型索引不会自动维护,因些需要定时进行更新索引并进行索引优化,索引优化的次数要稍微少些。
Sql代码
--更新索引
exec ctx_ddl.sync_index('idx_flqw_nr');
exec ctx_ddl.sync_index('idx_fltk_nr');
--优化索引
exec ctx_ddl.optimize_index('idx_flqw_nr','full');
exec ctx_ddl.optimize_index('idx_fltk_nr','full');
也可以将更新索引及优化写成job,这样可以定时运行,该job要与用户建立在同一个目录下。
先创建相对应的存储过程。
Sql代码
--给flyy用户赋予在存储过程中执行全文索引的权限
GRANT EXECUTE ANY ......