易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 :

Oracle 存储过程

 
create or replace procedure p   //有就替换,没有就创建
is
     cursor c is
         select * from emp for update;
begin
  for v_emp in c loop
      if (v_emp.deptno =10) then
         update emp2 set sal*2 where current of c;
      elsif () then
         update emp2 set sal*2 where current of c;
      else
          update emp2 set sal*2 where current of c;;
      end if;
  end loop;
  commit;
end;
2、执行
exec p;
--------
begin
 p;
end;
3、带参数的存储过程
create or replace procedure p  
    (v_a in number,v_b number,v_ret out number,v_temp in out number)  //in 传的参数,out传出参数
is
begin
   if(v_a> ......

Oracle 触发器

 
create table emp2_log(
 uname varchar2(20),
 action varchar(10),
 atime date
);
create or replace trigger trig
   after insert or delete or update on emp2 for each row  //绑在一张表上,before after 都可
以,before是 插数据之前,after是之后
begin
   if inserting then
       insert into emp2_log values(USER,'insert',sysdate);
   elsif updating then
       insert into emp2_log values(USER,'update',sysdate);
   elsif deleting then
       insert into emp2_log values(USER,'delete',sysdate);
   end if;
end;
----------------
create or replace trigger trig
   after  update on emp2 for each row
begin
  update emp set deptno=:NEW.deptno where deptno=:OLD.deptno;  //  对有外键约束进行设置
end; ......

Oracle 分析函数


   分析函数是oracle816引入的一个全新的概念,为我们分析数据提供了一种简单高效的处理方式.在分析函数出现以前,我们必须使用自联查询,子查询或者内联视图,甚至复杂的存储过程实现的语句,现在只要一条简单的sql语句就可以实现了,而且在执行效率方面也有相当大的提高.
下面主要介绍一下以下几个函数的使用方法
1.   Over() 开窗函数
2.    Nvl()函数
3.  Rollup,Cube自动汇总函数
4.  Rank,Dense_rank,Row_number函数
5.  Lag , Lead函数
6.  Sum,Avg, Count, Max函数
7.  Ratio_to_report报表处理函数
8.  First,Last,First_value,Last_value取基数的分析函数
9.   Greatest, Least 函数
10.  Trunc, Round,Decode, Substr函数
一. Over() 开窗函数
Over() 开窗函数是Oracle的分析函数,其语法如下:
函数名([ 参数 ]) over( [ 分区子句 ] [ 排序子句 [ 滑动窗口子句 ] ])
分区子句类似 ......

“优秀示例”: Oracle代码规程

 在PL/SQL中使用阵列处理是一个很好的做法(如,使用bulk collect和forall)。批量处理能够大大减少PL/SQL语句执行引擎的环境切换次数,从而提高其性能。
  另一个优秀示例是把存储过程中的所有代码放入锁定的软件包中,这样可以生成模块单元。把存储过程放入软件包里可以实现相关程序和功能的分组。当
单个包被使用,整个软件包都会载入内存中(内存会启动整个软件包?),把磁碟存取时间减到最少。通过这个方法我们同样可以把整个应用程序包载进内存中,防
止发生重新载入和代码解析,从而减少严重影响性能的代码递归。
  PL/SQL(和SQL)的另一个优秀示例是使用适当的变量类型(当你需要NUMBER时不要使用VARCHAR2,反之亦然)。使用不适当的变量(用character跟number进行比较)会导致无用索引。保证变量类型正确的一种方法就是使用%TYPE 和%ROWTYPE。
  还有就是永远使用DBMS_PROFILER或使用像Quest Software的Quest Code Tester工具来验证循环逻辑。DBMS_PROFILER是Oracle提供的一个软件包,能够使你的代码生成对每行执行时间及所需时间的追踪。你可以验证循环执行次数应为最少。
  你同样应该验证适当的IF-THEN-ELSE结构。我的意思是你应该把最常用的选项放在前 ......

Oracle数据导入导出imp/exp命令 [转]

Oracle数据导入导出imp/exp就相当于oracle数据还原与备份。exp命令可以把数据从远程数据库服务器导出到本地的dmp文件,imp命令可以把dmp文件从本地导入到远处的数据库服务器中。 利用这个功能可以构建两个相同的数据库,一个用来测试,一个用来正式使用。
 
执行环境:可以在SQLPLUS.EXE或者DOS(命令行)中执行,
 DOS中可以执行时由于 在oracle 8i 中  安装目录ora81BIN被设置为全局路径,
 该目录下有EXP.EXE与IMP.EXE文件被用来执行导入导出。
 oracle用java编写,SQLPLUS.EXE、EXP.EXE、IMP.EXE这两个文件有可能是被包装后的类文件。
 SQLPLUS.EXE调用EXP.EXE、IMP.EXE所包裹的类,完成导入导出功能。
 
下面介绍的是导入导出的实例。
数据导出:
 1 将数据库TEST完全导出,用户名system 密码manager 导出到D:daochu.dmp中
   exp system/manager@TEST file=d:daochu.dmp full=y
 2 将数据库中system用户与sys用户的表导出
   exp system/manager@TEST file=d:daochu.dmp owner=(system,sys)
 3 将数据库中的表inner_notify、notify_staff_relat导出
    exp& ......

Virtual Columns in Oracle Database 11g

When queried, virtual columns appear to be normal table columns, but
their values are derived rather than being stored on disc. The syntax
for defining a virtual column is listed below.
column_name [datatype] [GENERATED ALWAYS] AS (expression) [VIRTUAL]
If the datatype is omitted, it is determined based on the result of the expression. The GENERATED ALWAYS
and VIRTUAL
keywords are provided for clarity only.
The script below creates and populates an employees table with two
levels of commission. It includes two virtual columns to display the
commission-based salary. The first uses the most abbreviated syntax
while the second uses the most verbose form.
CREATE TABLE employees (
id NUMBER,
first_name VARCHAR2(10),
last_name VARCHAR2(10),
salary NUMBER(9,2),
comm1 NUMBER(3),
comm2 NUMBER(3),
salary1 AS (ROUND(salary*(1+comm1/100),2)),
salary2 NUMBER GENERATED ALWAYS AS (ROUND(salary*(1+comm2/100),2)) VIRTUAL,
CONS ......
总记录数:40319; 总页数:6720; 每页6 条; 首页 上一页 [5532] [5533] [5534] [5535] 5536 [5537] [5538] [5539] [5540] [5541]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号