Oracle
共 23 篇文章
Oracle中有关Group by 中avg();sum();min();max();count();的运用整理(Oracle的执行顺序)
表 tabzx: select * from tabzx 表数据: 查询语句: 1: select count(*),avg(tabzx.salary),sum(tabzx.salary),max(tabzx.salary),min(tabzx.salary)from tabzx 结果: 分析: 此时Oracle将表tabzx作为一个单独的组(group)进行函数处理的; Assumption: SQL表达式编写为: select tabzx.dept_id, count(*),avg(tabzx.salary),sum(tabzx.salary),max(tabzx.salary),min…
2011-06-15 18:11 · Oracle · SQL · Oracle
(Oracle) Oracle入门基础理论
一:Oracle的概述 什么是Oracle Oracle数据库是Oracle(中文名称叫甲骨文)公司的核心产品,Oracle数据库是一个适合于大中型企业的数据库管理系统。在所有的数据库管理系统中(比如:微软的SQL Server,IBM的DB2等),Oracle的主要用户涉及面非常广,包括:银行、电信、移动通信、航空、保险、金融、电子商务和跨国公司等。Oracle产品是免费的,可以在Oracle官方网站上下载到安装包,另一方面Oracle服务是收费的。 Oracle的特点 -- 方便地从一种计算机配置移至另一种计算机配置上。 -- 支持大数据库、多用户的高性能的事务处理。 -- ORACLE…
2011-06-08 19:29 · Oracle · SQL Server · 数据结构 · 配置管理 · 电信 · Oracle
(Index)Oracle 中Index的运行机制
从表单访问数据时,Oracle提供了两种方法 a.全表扫描(从表中读取每一行);b.通过ROWID一次读取一行; 索引改进性能的程度部分取决于数据的选择性以及在表的块之间分布数据的方式; 数据的选择性: 如果数据非常具有选择性,即只有很少的行匹配索引值(for instance PassPort Id).Oracle能快速查询的匹配索引值的RowID索引,并且可以快速查询少量的相关表块。 如果数据不是非常具有选择性(例如国家名),则索引可能返回许多ROWID,导致从表中查询许多单独的块。 如果数据非常具有选择性,但是相关的行在表中的存储位置并不互相靠近,则会进一步减少索引的益处。 如果匹配索…
2011-06-01 12:12 · Oracle · Yahoo · Oracle
(数据库范式) 第一范式(1NF);第二范式(2NF);第三范式(3NF)
第一范式(1NF)Unique Columns 无重复的列 第一范式(INF)数据库表的每一列都是不可分割的基本数据项;在第一范式(1NF)中表的每一行只包含一个实例的信息。简而言之,第一范式就是无重复的列。 第二范式(2NF)Property/Attrubites属性 完全依赖于主键[消除非主属性对主码的部分函数依赖] ; 第三范式(3NF)Attrubites属性 不依赖于其它非主属性[消除传递依赖] ;简而言之,第三范式(3NF)要求一个数据库表中不包含已在其它表中已包含的非主关键字信息。 简而言之: 1NF确定表的列的名称(即表的解构) 2NF确定表的主键 3NF确定表的外键(外键对…
2011-05-30 10:22 · Oracle
浅说:in、not in、exists和not exists的区别
in、not in、exists和not exists的区别: in和exists的区别: exists: 存在,后面一般都是子查询,当子查询返回 行数 时,exists返回true。 select * from class where exists (select'x"form stu where stu.cid=class.cid) 当in和exists在查询效率上比较时,in查询的效率快于exists的查询效率 exists(xxxxx)后面的子查询被称做相关子查询, 他是不返回列表的值的. 只是返回一个ture或false的结果(这也是为什么子查询里是select 'x'的原因 当然…
2011-05-29 15:08 · Oracle · SQL
(笔记)oracle中的join的整理和结构分析
在Oracle中的join主要分为: 外连接(outter join),内连接(inner join),自身连接(self-join) 外连接(outter join)又分为左外连接(left outer join)、右外连接(right outer join)、全外连接(full outer join)。在sql语句(structured Query Language)是:table_1 left/right/full outer join table_2,通常我们省略outer。 下面利用一个例子说明数据库的外连接问题: 一:创建两张表out_join1 and out_join2并插入…
2011-05-29 13:56 · Oracle · C · C++ · 数据结构 · C# · Oracle
(笔记)Oracle中的批量删除数据
在一个ORACLE数据库运行过程中,有时候会遇到要批量删除数据的情况,如一个保存历史数据的表中有大量的数据已经不需要保留,要将这部分数据删除。以下就这种情况可以采取的方法进行讨论。 1、使用TRUNCATE命令进行删除。 如果是整个表的数据都要删除的话,使用TRUNCATE TABLE命令是理想的选择。它删除了表中的所有数据,并且因为不写REDO LOG FILE,所以速度很快。删除的同时,表的索引和约束条件仍然存在。这种方法适用于ORACLE的各个版本。但是当要删除的数据只是表中的一部分时,这种方法便行不通了。 2、直接进行DELETE操作。 直接使用DELETE命令进行删除,如果删除的数…
2011-05-27 12:03 · Oracle · SQL · Oracle
续触发器:instead of ;事件触发--用户和系统
定义:instead of 1) 基于view表单的处理可以在表和视图上指定一个instead of 触发器 2) 执行这种触发器可以代替原来的触发器,instead of 触发器扩展了视图跟新类型 3) 每一个表和视图只能有一个instead of 触发器 4) INSTEAD OF触发器被用于更新那些没有办法通过正常方式更新的视图 5) INSTEAD OF触发器的主要优点就是可以使不能更新的视图支持更新。基于多个表的视图必须使用。 6) INSTEAD OF触发器来支持多个表中数据的插入、更新和删除操作。 注:不能在带有with check option 定义的视图中创建INSTEAD…
2011-05-26 18:04 · Oracle · C · Yahoo · C++ · C#
(trigger)触发器的定义和作用
第一:触发器(trigger) 触发器(trigger)是指隐含执行的存储过程procedure,当定义触发器时必须要指定触发事件和触发的操作,通常触发事件包括insert,update,delete语句,触发器实际上就是一个pl/sql(procedure language/Structured Query Language).create trigger来创建触发器; 第二:触发器的作用; a.允许/限制对表的修改 b.自动派生列,如自增字段 c.强制数据的一致性 d.提供审计和日志记录 e.防止无效的事务处理 f.启动复杂的业务逻辑 第三:触发器的语法; create or repla…
2011-05-25 16:00 · Oracle · C · C++ · C# · SQL · F#
Oracle中的loop循环的例子
第一:loop... exit when...end loop; declare temp_salary employee.salary%type; temp_emp employee%rowtype; cursor mycursor is select * from employee where employee.salary>temp_salary; begin temp_salary:=2000; open mycursor; loop fetch mycursor into temp_emp; exit when mycursor%notfound; dbms_output.put_…
2011-05-25 15:07 · Oracle · Oracle
(oracle)如何通过函数去调用procedure的注意事项
创建一个带参数的procedure temp_pr(): create or replace procedure temp_pr(temp_no in employee.empid%type,temp_name out employee.empname%type)as begin select employee.empname into temp_name from employee where employee.empid=temp_no; end; 在上一篇关于procedure的日志中提到 as 在这里的功能相当于 declare的作用 用来声明变量,此处没有变量所以as后面接代码; …
2011-05-25 12:06 · Oracle · Oracle
在oracle中创建一个exception
Gramma: 1:声明一个exceptin: declare exception_name exception; 2:触发一个exception; raise exception_name; 3:捕获一个exception when exception_name1 then statements; when exception_name2 then statements 代码: declare a exception; t_salary employee.salary%type; begin select salary into t_salary from employee where e…
2011-05-24 19:24 · Oracle · Oracle
(oracle)如何创建和使用procedure
1:定义procedure(在高级程序设计语言中的模块的概念) create or replace procedure procedure_name (param_1 in type,param_2 in out type) as param_inner type begin statement; end; a:不含参数的procedure create or replace procedure temp as temp_salary employee.salary%type; begin select salary into temp_salary from employee where …
2011-05-24 18:44 · Oracle · C · C++ · C# · D语言 · Oracle
(笔记)如何声明使用cursor及其属性
Defined cursor ; cursor mycursor is select * from employees where employees.salary>tempsal; Learning point on cursor; declare tempsal employees.salary%type; cursor mycursor is select * from employees where employees.salary>tempsal; currecord employees%rowtype; begin tempsal:=800; open mycursor; if …
2011-05-24 14:55 · Oracle
(游标)How to define and implement THE CURSOR
Definition: cursor的作用是从数据表中提取来的数据,以 临时表的形式 存放在内存中,在cursor有一个 数据指针 ,在initical status下指向首记录,利用fetch语句可以移动指针,从而对cursor的数据进行各种操作,然后将操作结果写回表中; Gramma/parse: 注意:cursor是一种数据类型 cursor name is select satements open mycursor; 打开游标的过程有以下两个步骤: (1)将符合条件的记录送入内存. (2)将指针指向第一条记录. fetch mycursor into columns_1,colum…
2011-05-24 11:29 · Oracle
(savepoint) savepoint--rollback
语法: savepoint 保存点的名称; rollback to 保存点的名称; --savepoint-- insert into users values(user_seq.nextval,'anan','anan','an','1'); savepoint a; insert into users values(user_seq.nextval,'demon','demon','dem','1'); insert into users values(user_seq.nextval,'kevin','kevin','kev','1'); --rollback to -- rollba…
2011-05-24 10:38 · Oracle
(笔记)Oracle中的表达式
(1)数值表达式 --+(加法),-(减法),*(乘法),/(除法)和**(乘方)等-- declare --此处number(9)和integer都行-- result_1 integer; begin result_1:=10+3*4-20+5**2; dbms_output.put_line('输出的结果为='||to_char(result_1)); end; --dbms_output.put_line函数输出只能是字符串,因此利用to_char函数将数值型结果转换为字符型-- (2)字符表达式 字符表达式 字符表达式由字符型常数,变量,函数和字符运算符组成,唯一可以使用的字符运算…
2011-05-23 16:44 · Oracle · Oracle
(笔记)基本复合型数据类型的声明
--(1)使用%type定义变量 -- declare n_name users.usedname%type; begin commit; end; --(2)定义记录类型变量 -- declare --定义了名为myrecord的记录类型,该记录类型由整数型的myrecordnumber和日期型的mycurrentdate基本类型变量组成 type myrecord is record( myrecordnumber int, mycurrentdate date); --然后声明一个myrecord类型的变量; srecord myrecord; begin select * into …
2011-05-23 16:16 · Oracle · 数据结构 · SQL
复杂的Oracle的查询--查询各个部门的总员工和总薪水占整个公司的比率
查询各个部门的总员工和总薪水占整个公司的比率: SELECT a.department_id "Department", a.num_emp/b.total_count "%_Employees", a.sal_sum/b.total_sal "%_Salary" FROM (SELECT department_id, COUNT(*) num_emp, SUM(salary) sal_sum FROM employees GROUP BY department_id) a, (SELECT COUNT(*) total_count, SUM(salary) total_sal FROM e…
2011-05-20 16:56 · Oracle · C · C++ · C# · Oracle