
oracle数据库
Richard888888888
这个作者很懒,什么都没留下…
展开
-
oracle何时使用索引
以下情况可以使用索引 :1.列中数据值分布范围广。比如,人的工资,范围可能是从1000到上亿,分布比较广,所以可以使用索引来提速,查询。若是范围 比较小,比如人生存的年龄 ,顶多是1到130左右,这样就不适合使用索引 。 2.列经常在where子句或连接条件中出现。3.表经常被 访问而且数据量很大,访问的数据大概占数据总量的2%-4%索引类似于字典的索引。不适合使用索引原创 2016-12-03 18:40:42 · 1026 阅读 · 0 评论 -
pl/sql exception例子
--exception异常declarev_sal employees.salary%type;begin select salary into v_sal from employees where employee_id=100;exception--非预定义异常when too_many_rows then dbms_output.put_line('不只一条数原创 2016-12-06 12:34:39 · 443 阅读 · 0 评论 -
oracle存储过程和自定义函数
(学习中遇到的相关问题PLSQL是什么?)数据库的对象:表、视图、索引、序列、同义词、存储过程、存储函数。存储过程和存储函数:指存储在数据库中供所有用户程序调用的子程序叫存储过程、存储函数。相同点:完成特定功能的程序。区别:是否用return语句返回值。存储函数可以通过return返回值,而存储过程不能。第一个存储过程,打印helloword;create or r原创 2016-11-08 15:22:37 · 517 阅读 · 0 评论 -
oracle 存储函数,存储过程
--存储函数--返回一个'helloword'字符串create or replace function helloword return varchar2is--声明部分begin return 'helloword';end;--调用存储函数begin dbms_output.put_line(helloword);end;--或者用se原创 2016-12-06 13:37:09 · 569 阅读 · 0 评论 -
oracle报PL/SQL:ORA:04044:此处不允许过程、函数、程序包或类型;
select sysdate from dual ;执行带这dual虚表就报 :PL/SQL:ORA:04044:此处不允许过程、函数、程序包或类型;通过查询:select * from all_objects where object_name='DUAL';发现,有一个存储过程名也叫dual,将该存储过程删除后,就OK了。原创 2017-03-01 10:54:47 · 13367 阅读 · 0 评论 -
oracle 不支持级联更新
alter table profession_skill modify (constraint pk_skill_id foreign key (pro_id) references profession(pro_id) on update cascade);--在我删 除了原有的外键想要添加级联更新时候 ,发现oracle并不能成功。会报缺失关键字。--但改成 on delete c原创 2017-03-02 14:30:41 · 460 阅读 · 0 评论 -
外键和内键.个人理解
alter table personal_equip add constraint fk_P_id foreign key(p_id) references man3(ID);--外键要建立在personal_equip(个人装备表),alter table man3 add constraint fk_man_id foreign key(id) references personal_原创 2017-03-02 16:19:21 · 3377 阅读 · 0 评论 -
oracle for循环,要注意的一点
--就是这段代码 ,一直以为 for循环中的i就是指的 id。其实不然,i代表的是一个获取了id的集合,若要用id,这个--属性,必须要i.id才能获得其中的值 。declare v_random man3.m_level%type;cursor cur_id is select id from man3;begin for i in cur_id loopv_rand原创 2017-03-02 13:25:29 · 927 阅读 · 0 评论 -
begin end 中嵌套 begin endman
--如下代码:将exception块放在for循环里,若是没将一个循环的代码添加 begin end 将会报错declare cursor cur_coin is select coin from man3 where idbegin for x in cur_coin loop begin --一个完整的代码块-->end;if x.coin update man3原创 2017-03-04 10:08:22 · 2986 阅读 · 0 评论 -
游标
--游标declaretype emp is RECORD(v_sal employees.salary%type,v_id employees.employee_id%type,v_name employees.last_name%type);v_emp emp;cursor cursor_emp_sal is select salary,employee_id,la原创 2016-12-05 18:38:38 · 210 阅读 · 0 评论 -
pl/sql的循环运用
--loopdeclarev_i number(5):=1;beginloop dbms_output.put_line(v_i);EXIT when v_i>=100;v_i:=v_i+10;end loop;end;set serveroutput on;declarev_i number(5):=1;beginwhile v_i原创 2016-12-05 17:18:16 · 257 阅读 · 0 评论 -
pl/sql case when then
--查询出150号员工的工资,若其工资大于或等 于10000,则打印'打印salary>=10000';--若其工资大于5000且小于10000,则打印出“5000可以这样写declarev_sal employees.salary% type;v_tem VARCHAR2(30);begin select salary into v_sal from employe原创 2016-12-05 15:42:59 · 442 阅读 · 0 评论 -
oravle 视图
--查找工资在40-到50名的员工 ,rownum 不能用>或者>=,否则将不返回结果--如下例子将不返回 任何结果select rownum, last_name ,salary,employee_id from (select last_name,salary,employee_id from employees order by salary desc) where rown原创 2016-12-03 15:20:25 · 573 阅读 · 0 评论 -
jquery的load方法
//原创 2016-11-17 11:07:20 · 473 阅读 · 0 评论 -
oracle组函数
--查出每个部门的最高工资,并在每个最高工资中找出最低的那个SELECT min(max(salary)) from employees group by department_id;group by department_id;组函数中能套组函数,但不能写成这样select min(select max(salary) from employees group by departme原创 2016-12-02 19:52:18 · 314 阅读 · 0 评论 -
其它数据库对象
常见的数据库对象:表、视图、序列、索引,同义词。创建序列create sequence empseq(序列名)increment by 10 --自增10start with 10--起始值为10maxvalue 100--最大值为100cycle--需要循环(不需要循环nocycle)nocache;--不需要缓存登入--更改序列alter sequen原创 2016-12-03 18:47:37 · 277 阅读 · 0 评论 -
oracke控制用户权限
DBA使用create user创建用户CREATE USER userIDENTIFIED BY password;例子:create user zhouqi1identified by 123456;--授予登入权限grant create session to zhouqi1;--授予创表权限 grant create table to zhouqi1;原创 2016-12-03 20:45:57 · 447 阅读 · 0 评论 -
oracle set运算符
--union取两个查询结果的合集 order by 1相当于按第一列,employee_id排,第二列相当于安department_id排select employee_id, department_id id from empbunion allselect employee_id, department_id from empc order by 1;--inters原创 2016-12-04 14:56:13 · 411 阅读 · 0 评论 -
oracle 高级子查询
--查询与141号或174号员工的manager_id和department_id相同的其它员工的employee_id,department_id,manager_id信息select employee_id,department_id,manager_id from employees where manager_id in(select manager_id from employe原创 2016-12-04 21:53:00 · 418 阅读 · 0 评论 -
PL/SQL基础语法
什么是PL/SQL程序:PL/SQL是oracle对sql语言的过程化扩展。指在SQL命令语言中增加 了过程处理语句(如分支,循环等),使SQL语言具有过程处理能力。PL/SQL的程序结构:declare说明部分(变量说明,光标申明,例外说明 )begin 语句序列(DML语句)exception例外处理语句end;/--举例--定义基本变量类型原创 2016-11-08 21:46:56 · 363 阅读 · 0 评论 -
存储过程
--以下存储过程 实现了,输入参数 0,找出对应数据表中性别 为难的记录,输入参数 为1,找出性别为女的,输入其--它,找出性别一栏为空的记录 create or replace procedure P_TEST_SQL1(val number)isTYPE ref_cursor_type IS REF CURSOR; v_sex zhouqi_0208.sex%type原创 2017-02-11 16:52:21 · 253 阅读 · 0 评论