PLSQL 笔记

oracle的左连接或右连接 以下是解释,自己研究下: ------------------------------------------------------------------- 数据表的连接有: 1、内连接(自然连接): 只有两个表相匹配的行才能在结果集中出现 2、外连接: 包括 (1)左外连接(左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右两表都不加限制) 3、自连接(连接发生在一张基表内) select a.studentno, a.studentname, b.classname from students a, classes b where a.classid(+) = b.classid; STUDENTNO STUDENTNAM CLASSNAME ---------- ---------- ------------------------------ 1 周虎 一年级一班 2 周林 一年级二班 一年级三班 以上语句是右连接: 即"(+)"所在位置的另一侧为连接的方向,右连接说明等号右侧的所有 记录均会被显示,无论其在左侧是否得到匹配。也就是说上例中,无 论会不会出现某个班级没有一个学生的情况,这个班级的名字都会在 查询结构中出现。
反之: select a.studentno, a.studentname, b.classname from students a, classes b where a.classid = b.classid(+);
STUDENTNO STUDENTNAM CLASSNAME ---------- ---------- ------------------------------ 1 周虎 一年级一班 2 周林 一年级二班 3 钟林达
则是左连接,无论这个学生有没有一个能在一个班级中得到匹配的部门号, 这个学生的记录都会被显示。
select a.studentno, a.studentname, b.classname from students a, classes b where a.classid = b.classid;
这个则是通常用到的内连接,显示两表都符合条件的记录
总之,
左连接显示左边全部的和右边与左边相同的 右连接显示右边全部的和左边与右边相同的 内连接是只显示满足条件的!
create or replace procedure insert_procedure is
begin  
insert into employee(id,username,password,birthday,email,address) values(5,'dog','dog123',to_date('2010-10-15 12:15:01','YYYY-MM-DD hh:mi:ss'),'dog@126.com','China,Henan');
end;
create or replace procedure delete_procedure is
begin  
delete from employee where id = 5;
end;
/
create or replace procedure delete_procedure(p_id number) is
begin  
delete from employee where id = p_id;
end;
/
begin  
dbms_output.put_line('Hello, world');
end;
create or replace procedure name_procedure(v_id number) is  
v_name employee.username%type;
begin  
select username into v_name from employee where id = v_id;  
dbms_output.put_line('username is ' || v_name);
end; /
create or replace procedure name_exception_procedure(v_id number) is  
v_name employee.username%type;
begin  
select username into v_name from employee where id = v_id;  
dbms_output.put_line('username is ' || v_name);
exception  
when no_data_found then    
dbms_output.put_line('根据ID找不到相关记录');
end;
/
create or replace procedure name_many_procedure(v_id number) is  
v_username employee.username%type;
begin  
select username into v_username from employee where id = v_id;
exception  
when too_many_rows then    
dbms_output.put_line('返回记录数过多');
end;
/
create or replace procedure update_procedure(v_id in number,v_username in varchar2,v_password in varchar2) is
begin  
update employee set employee.password = v_password,employee.username = v_username where employee.id = v_id;
end;
/
create or replace function password_function(v_username in varchar2)
return varchar2 is v_password employee.password%type;
begin  
select employee.password into v_password from employee where employee.username = v_username; return v_password;
Exception   when no_data_found then    
dbms_output.put_line('用户名不存在 !');    
return null;
end;
/
create or replace package sys_package is   procedure update_procedure(v_username in varchar2);  
function select_function(v_username in varchar2) return varchar2;
end;
/
create or replace package body sys_package is   procedure update_procedure(v_username in varchar2) is    
begin      
update employee set employee.username = v_username where employee.id = 1;    
end;    
function select_function(v_username in varchar2)
return varchar2 is     v_password employee.password%type;    
begin      
select employee.password into v_password from employee where employee.username = v_username;      
return v_password;    
end;
end; /
declare  
type employee_record_type is     record(v_username employee.username%type, v_password employee.password%type, v_email employee.email%type);   employee_record employee_record_type;
begin  
select employee.username, employee.password, employee.email into employee_record from employee where employee.id = 1;  
dbms_output.put_line('username :' || employee_record.v_username || 'password :' || employee_record.v_password || 'email :' || employee_record.v_email);
end;
/
declare   type employee_cursor_type is ref cursor;
employee_cursor employee_cursor_type;  
v_username employee.username%type;  
v_password employee.password%type;
begin  
open employee_cursor for     select employee.username, employee.password from employee where employee.id = 5;  
loop    
fetch employee_cursor into v_username,v_password;  
exit when employee_cursor%notfound;    
dbms_output.put_line('username :' || v_username || 'password :' || v_password);  
end loop;  
close employee_cursor;
end;
/
create or replace procedure if_employee_procedure(v_id number) is v_username employee.username%type;
begin   select employee.username into v_username from employee where employee.id = v_id;  
if length(v_username) < 11 then    
update employee set employee.username = rpad(v_username, 11, 0) where employee.id = v_id;  
end if;
end;
/
create or replace procedure if_else_employee_procedure(v_id in number) is v_username employee.username%type;
begin  
select employee.username into v_username from employee where employee.id = v_id;  
if length(v_username) < 10 then    
update employee set employee.username = rpad(v_username, 18, 0) where id = v_id;  
else    
update employee set employee.username = rpad(v_username, 15, 0) where id = v_id;  
end if;
end;
/
create or replace procedure loop_employee_procedure is
v_id number:=6;
begin  
loop    
insert into employee values(v_id, 'ding', 'ding', to_date('2012-10-06 10:15:27','yyyy-mm-dd hh:mi:ss'), 'ding@126.com', 'China');  
exit when v_id = 15;  
v_id:=v_id + 1;  
end loop;
end;
/
create or replace procedure while_procedure is
v_id number := 16;
begin   while v_id < 30 loop    
insert into employee values(v_id, 'dys','dys456',to_date('1988-10-15 15:24:18','yyyy-mm-dd hh24:mi:ss'),'dys456@126.com','China ,hebei');     v_id:=v_id+1;  
end loop;
end;
/
create or replace procedure return_procedure(v_id in number,v_username out varchar2) is begin
select employee.username into v_username from employee where employee.id = v_id;
end;
/
create or replace package myPackage is  
type v_employee_cursor is ref cursor;
end;
/
create or replace procedure ref_cursor_procedure(v_id in number,v_out_result out myPackage.v_employee_cursor) is
begin  
open v_out_result for     select * from employee where employee.id = v_id;
end;
/
create or replace procedure fenYeProcedure(v_in_table in varchar2,v_in_pageSize in number,v_in_pageNow in number,v_out_result out myPackage.v_employee_cursor,v_out_totalRows out number,v_out_pageCount out number) is
v_sql varchar2(2000);
v_start_row number;
v_end_row number;
begin  
v_start_row:=v_in_pageSize*(v_in_pageNow-1)+1;  
v_end_row:=v_in_pageSize*v_in_pageNow;  
v_sql:='select t2.* from (select t.*, rownum rn from (select * from ' || v_in_table || ') t where rownum <= ' || v_end_row || ') t2 where t2.rn >= '|| v_start_row;   open v_out_result for v_sql;  
select count(*) into v_out_totalRows from emp;  
if mod(v_out_totalRows,v_in_pageSize)=0 then
v_out_pageCount:=v_out_totalRows/v_in_pageSize;  
else    
v_out_pageCount:=v_out_totalRows/v_in_pageSize+1;  
end if;
end;
/
create or replace view employee_view as select * from employee; /
create or replace view employee_view as select * from employee with read only; /
create or replace trigger insert_trigger
after insert on scott.employee
begin  
dbms_output.put_line('添加了一条记录');
end;
/
insert into employee values(110,'abcdefg','abcdefg123',to_date('2011-12-14 12:45:36','yyyy-mm-dd hh:mi:ss'),'abcdefg@126.com','China,toString');
create or replace trigger update_trigger
after update on scott.employee
for each row begin  
dbms_output.put_line('更改了一条数据');
end;
/
create or replace trigger before_brigger
before delete on scott.employee begin  
if to_char(sysdate,'day') in ('星期日','星期六','星期四') then    
raise_application_error('-20001','星期天不能删除员工信息!');  
end if;
end;
/
create or replace trigger all_trigger
before insert or update or delete on scott.employee begin  
case     when inserting then      
dbms_output.put_line('请不要添加');      
raise_application_error(-20002,'不能添加数据');    
when updating then      
dbms_output.put_line('请不要修改');      
raise_application_error(-20003,'不能修改数据');   
when deleting then     
dbms_output.put_line('请不要删除');     
raise_application_error(-20004,'不能删除数据');  
end case;
end;
/
create or replace trigger new_old_trigger
before update on scott.employee for each row
begin   if :new.id < :old.id then    
dbms_output.put_line('ID不能变小');    
raise_application_error(-20005,'ID不能小于原来');   
else    
dbms_output.put_line('原来ID是 : ' || :old.id || '新的ID是 : ' || :new.id);  
end if;
end;
/
create or replace trigger backup_trigger
before delete on scott.employee for each row
begin  
insert into employee_backup values (:old.id,:old.username);
end;
/
create or replace trigger limit_trigger
before update on scott.employee for each row begin  
if (:new.id<:old.id or :new.id>:old.id*2) then    
dbms_output.put_line('ID范围不对!');    
raise_application_error(-20006,'ID范围不合理');  
end if;   
end;
/
create or replace trigger limit_age_trigger
before insert on scott.employee for each row begin  
if :new.id>200 then    
dbms_output.put_line('ID过大');    
raise_application_error(-20007,'ID值太大了');  
end if;
end;
/
create or replace trigger limit_age_trigger
before insert on scott.employee for each row
begin  
if add_months(:new.birthday,18*12)>sysdate then    
dbms_output.put_line('年龄太小了');    
raise_application_error(-20007,'对不起年龄太小了');  
end if;
end;
/
insert into employee values(120,'good','good123',to_date('1999-12-13 12:15:49','yyyy-mm-dd hh:mi:ss'),'good@126.com','China,Hubei');
create or replace trigger generate_birthday_trigger
before insert on scott.test for each row declare  
v_length int;  
v_date varchar2(10);
begin   v_length := length(:new.IDCard);  
if v_length = 18 then    
v_date := substr(:new.IDCard,7,8);  
elsif v_length = 15 then    
v_date := '19' || substr(:new.IDCard,7,6);  
else    
:new.birthday := null;  
end if;  
:new.birthday := to_date(v_date,'yyyy/mm/dd');
end;
/
create or replace procedure delete_all_procedure(v_ids in long) is v_sql long; begin   v_sql:='delete from users t where t.id in (' || v_ids || ')';   execute immediate v_sql; end;

转载于:https://www.cnblogs.com/dingyingsi/archive/2013/02/26/2933491.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/433873.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

上位机与1200组态步骤_组态王与 I/O 设备

组态王软件是一种通用的工业监控软件&#xff0c;它将过程控制设计、现场操作以及工厂资源管理融于一体&#xff0c;将一个企业内部的各种生产系统和应用以及信息交流汇集在一起&#xff0c;实现最优化管理。它基于Microsoft Windows XP/Win7/Win8/Win10/WinServer 系列操作系统…

MySQL安装错误: unknown option '--skip-federated'

mysql启动时出现以下错误&#xff1a; [ERROR] /usr/local/mysql/libexec/mysqld: unknown option --skip-federated [ERROR] Aborting [Note] /usr/local/mysql/libexec/mysqld: Shutdown complete 只要将/etc/my.cnf文件中的skip-federated注释掉即可 通过查看/var/log/mysql…

华为鸿蒙发布2.0,华为做到了!鸿蒙2.0正式发布,苹果安卓有危机?

孩子的梦想总是天真烂漫&#xff0c;无论年龄大小&#xff0c;每个人都有属于自己的梦想&#xff0c;儿童节刚过华为天真的梦就照进了现实。6月2日晚间&#xff0c;鸿蒙2.0版本发布会如期而至&#xff0c;余承东正式向全世界宣布这款挑战安卓和 iOS的商用移动操作系统&#xff…

【IE大叔的嘴歪眼斜】之—— 由hasLayout引发的临床CSS Bug表

IE大叔这嘴歪眼斜的毛病不是一天两天了&#xff0c;集体拉出来测试时候&#xff0c;明明大家都在微笑&#xff0c;就丫一副呲牙咧嘴的...... 哎&#xff0c;没办法&#xff0c;谁让咱国内市面上都是这种呲牙咧嘴的浏览器呢.....(关注IE678死亡速度) 查阅&#xff0c;翻读&#…

greenplum 查询出来的数字加减日期_Python实践代码总结第5集(日期相关处理)

英文的月份转数字及数字转英文import calendar# 数字转月份的简写calendar.month_abbr[12]--> Dec# 简写月份转数字list(calendar.month_abbr).index(Dec)--> 12# 数字转月份的全写calendar.month_name[12]--> December# 月份转数字list(calendar.month_name).index(D…

静态代码和动态代码的区别_无代码和低代码有哪些区别

代码是大多数软件程序和应用程序的骨干。代码是大多数软件程序和应用程序的骨干。每行代码充当一条指令&#xff1a;采用一种逐步性的逻辑机制&#xff0c;以便计算机、服务器和其他机器执行操作。想创建那些指令&#xff0c;就要知道如何编写代码&#xff0c;这项宝贵的技能有…

备注html网页代码,备注.html · dengzhao/prd_zhangyao - Gitee.com

&#xfeff;备注$axure.utils.getTransparentGifPath function() { return resources/images/transparent.gif; };$axure.utils.getOtherPath function() { return resources/Other.html; };$axure.utils.getReloadPath function() { return resources/reload.html; };备注…

mysqld与mysqld_safe的区别

直接运行mysqld程序来启动MySQL服务的方法很少见&#xff0c;mysqld_safe脚本会在启动MySQL服务器后继续监控其运行情况&#xff0c;并在其死机时重新启动它。用mysqld_safe脚本来启动MySQL服务器的做法在BSD风格的unix系统上很常见&#xff0c;非BSD风格的UNIX系统中的mysql.s…

python词频统计代码_机器学习必备宝典-《统计学习方法》的python代码实现及课件...

《统计学习方法》可以说是机器学习的入门宝典&#xff0c;许多机器学习培训班、互联网企业的面试、笔试题目&#xff0c;很多都参考这本书。本站根据网上资料用python复现了课程内容&#xff0c;并提供本书的代码实现、课件下载。《统计学习方法》简介《统计学习方法》全面系统…

Oracle中用rownum替代Top函数的方法

今天写一个方法&#xff0c;主要功能是从数据库中根据条件查出第一条信息。以前用sql server的时候&#xff0c;我记得TOP方法还是非常简单实用的。 方法是&#xff1a;select top n [列名] from [表名] where [查询条件] 这个方法想必像我这样的新人也会非常熟悉&#xff0c;所…

view类不响应自定义消息_安卓平台如何给控件添加自定义操作?

在安卓应用设计和开发过程中&#xff0c;设计人员为了界面简洁、有独特的交互方式&#xff0c;可能会为控件设计特殊的操作手势&#xff0c;例如消息列表中单指按住消息向左滑删除消息&#xff1b;系统顶部的通知单指向左滑可以关闭通知等。这些操作对于普通用户非常方便&#…

mysql 密码

使用mysqladmin&#xff0c;这是前面声明的一个特例。 mysqladmin -u root -p password 新密码 输入这个命令后&#xff0c;需要输入root的原密码&#xff0c;然后root的密码将改为mypasswd。 把命令里的root改为你的用户名&#xff0c;你就可以改你自己的密码了。 当然如果你的…

html5 css登录注册实现,html5+css3实现一款注册表单实例

效果图如下&#xff1a;html源码&#xff1a;复制代码代码如下:个人信息账号:密码:重复密码:邮箱地址:其他信息个人网址:年龄:月薪:10000function showValue(value) {document.getElementById("rangevalue").innerHTMLvalue;}描述:css源码&#xff1a;复制代码代码如…

图解SQL的inner join、left join、right join、full outer join、union、union all的区别

对于SQL的Join&#xff0c;在学习起来可能是比较乱的。我们知道&#xff0c;SQL的Join语法有很多inner的&#xff0c;有outer的&#xff0c;有left的&#xff0c;有时候&#xff0c;对于Select出来的结果集是什么样子有点不是很清楚。Coding Horror上有一篇文章,通过文氏图 Ven…

华南主板超频设置图解_AMD用户不会超频不要紧,开启这个功能免费的性能提升...

现在谈到DIY电脑&#xff0c;基本上大家都会了解到“超频”这个词&#xff0c;超频就是采用人为的方式将CPU、显卡等硬件的工作频率提高&#xff0c;让它们在高于其额定的频率状态下稳定工作。完整的超频必须有两点&#xff0c;提升频率并且稳定&#xff0c;很多时候提升频率容…

凹入表形式打印树形结构_【树形立方体】立方体有哪些特性?

迈安带你走进【迈安带你走进】如上图所示&#xff0c;这是由三个维度构成的一个树形立方体&#xff0c;立方体中包含了满足条件的cell(子立方块)值&#xff0c;这些cell里面包含了要分析的数据&#xff0c;称之为度量值。显而易见&#xff0c;一组三维坐标唯一确定了一个子立方…

小学有学计算机课程,如何进行小学计算机课程有效教学.doc

如何进行小学计算机课程有效教学如何进行小学计算机课程有效教学摘要&#xff1a;计算机课程&#xff0c;作为近年来在基础教育阶段&#xff0c;特别是小学阶段新开设的课程&#xff0c;如何进行有效教学&#xff0c;尽可能的提高课堂教学效果&#xff0c;是众多教师关注的热点…

cs架构用什么语言开发_用Rust语言开发微信小程序

由于stdweb已经好久没有更新了&#xff0c;本人又写了另外一篇&#xff1a;JiaYe&#xff1a;用Rust语言开发微信小程序&#xff1a;wasm-bindgen​zhuanlan.zhihu.comstdweb可以轻松将Rust代码编译为JavaScript和Webassembly字节码&#xff0c;本例中使用asmjs-unknown-emscri…

利用线性代数的方法求斐波那契数列的通项

由于word编辑的公式打出来全是黑的&#xff0c;所以只能贴图咯。下次换个编辑器。转载于:https://www.cnblogs.com/maplewizard/archive/2013/03/10/2952623.html

zookeeper 可视化_大厂,常用,四款,大屏可视化工具

小编最经常的工作是将一些项目的数据从数据库导出&#xff0c;然后分门别类的列到excel表格中&#xff0c;领导看起来眼花缭乱。小编想&#xff0c;要是能以图表可视化展现出来&#xff0c;领导就可以看到项目近几个月的走势&#xff0c;也知道之后要怎么决策了。小编尝试了使用…