ORACLE 纯度级别(PURITY)
PRAGMA RESTRICT_REFERENCES(),这个PRAGMA比较复杂, 总的来说,它是一个程序辅助检验码,检查子程序的纯度(PURITY),帮助检验子程序是否有违反规则的地方。一般用在函数上,但当函数调用过程时,也要作相应的设置检查。这是为了避免当在DML语句上调用函数时正常执行不至于产生错误。
语法,PRAGMA RESTRICT_REFERENCES(function_name | default , )RNDS, WNDS, RNPS, WNPS) | , TRUST);
RNDS,WNDS,RNPS,WNPS可以同时指定。但当TRUST指定是,其它的被忽略。
DEFAUT是指作用在该程序包上的所有子程序,函数。
RNDS(Read No Database State),规定子程序不能读取任何的数据库状态信息。(即不会查询数据库的任何表,包括DUAL虚表)
RNPS(Read No Package State),规定子程序不能读取任何程序包的状态信息,如变量等。
WNDS(Write No Database State),规定子程序不能向数据库写入任何信息。(即不能修改数据库表)
WNPS(Write No Package State),规定子程序不能向程序包写入任何信息。(即不能修改程序包变量的值)
TRUST,指出子程序是可以相信的不会违反一个或多个规则。这个选项是需要的当用C或JAVA写的函数通过PL/SQL调用时,因为PL/SQL在运行是对它们不能检查。
示例:
create or replace package purity is
minsal number(6,2);
maxsal number(6,2);
function max_sal return number;
function min_sal return number;
--限制函数不能改变包变量:WNPS,其它的还有
pragma restrict_references(max_sal,wnps);
pragma restrict_references(min_sal,wnps);
end;
create or replace package body purity is
function max_sal return number
as
begin
--select max(sal) into maxsal from emp;
--加上面这行对包变量进行改变,则提示"违反相关编译指示"
return maxsal;
end;
function min_sal return number
as
begin
--select min(sal) into minsal from emp;
--加上面这行对包变量进行改变,则提示"违反相关编译指示"
return minsal;
end;
--构造函数
--写构造函数构造变量时,BEGIN开始,共用包体结束的END;标志
begin
select min(sal),max(sal) into minsal,maxsal from em
相关文档:
select column_name from all_cons_columns cc
where owner='SSH' --SSH为用户名称,要注意大小写
and table_name='SYS_DEPT' --SYS_DEPT为表名,注意大小写
and exists (select 'x' from all_constraints c
where c.owner = cc.owner
and c.constraint_name = cc.constraint_name
and c.constraint_type ='P'
......
--oracle jobs批处理命令参考
qlplus /nolog
connect sys/lee as sysdba
--以下两句在sys(即具有dba权限的用户)用户下执行
show parameter job_queue_processes;
alter system set job_queue_processes=10;
exit
sqlplus /nolog
connect jcy/jcy
ALTER TABLE T_OA_AFFICHE MODIFY (INPUT_TIME DATE);
ALTER TABLE ......
基本从来不用left/right join
一个项目被迫要用别人写的 sql
本打算改写一下,提高效率
发现:
【1】
select * from a
left outer join b on a.id= b.id AND ...1...
where ...2...
与
【2】
select * from a , b
where a.id= b.id(+)
A ......
Oracle创建删除用户、角色、表空间、导入导出、...命令总结
//创建临时表空间
create temporary tablespace zfmi_temp
tempfile 'D:\oracle\oradata\zfmi\zfmi_temp.dbf'
size 32m
autoextend on
next 32m maxsize 2048m
extent management local;
//tempfile参数必须有
//创建数据表空间
create table ......
5.调用函数FN_ADDONE
--------------------
SQL> SET SERVEROUTPUT ON
SQL> DECLARE CNUM NUMBER;
2 BEGIN
3 CNUM := USER1_ADB.FN_ADDONE(3);
4 DBMS_OUTPUT.PUT_LINE('CNUM = ' || CNUM);
5 END;
6&nbs ......