1.语句结构模板

declare --声明
begin
dbms_output.put_line('Legend Hello world');
end;

2.变量使用 & 是输入符号

declare
c_name constant varchar2(20) :='Legend';
v_num number(3) :='I am';
begin
dbms_output.put_line(v_num ||c_name || &n);
end;

3.rowtype的运用

declare
v_dept dept%rowtype;
begin
select * into v_dept from dept where deptno=&n;
dbms_output.put_line('部门编号:' || v_dept.DEPTNO ||'部门名称:'|| v_dept.DNAME ||'部门位置' || v_dept.LOC);
end;

4.record的使用

declare
type type_emp_dept is record(
v_ename emp.ename%type,
v_sal emp.sal%type,
v_dname dept.dname%type
); v_record type_emp_dept; begin
select e.ename,e.sal,d.dname into v_record from emp e,dept d where d.deptno = e.deptno and e.empno=&n;
dbms_output.put_line('员工姓名:'|| v_record.v_ename ||'员工工资:' || v_record.v_sal ||'部门名称:'|| v_record.v_dname);
end;

5.作业练习

/*

提示:获得键盘输入操作,可使用 empno=&名称

*/

1、使用块结构输出:学校:XXX学号:XXX,姓名:XXX,性别:XXX.

declare
v_school varchar2(20) :='桂林理工大学';
v_sid number(20) :=01;
v_sname varchar2(30) :='Legend';
v_sex varchar2(5) :='男';
begin
dbms_output.put_line('学校:' ||v_school || '学号:' || v_sid || '姓名:'|| v_sname ||'性别:' || v_sex);
end;

2、输入员工号,显示员工姓名、工资(使用%type完成)。

declare
v_ename emp.ename%type;
v_sal emp.sal%type;
begin
select ename,sal into v_ename,v_sal from emp where empno=&n;
dbms_output.put_line('姓名:'|| v_ename ||'工资:' || v_sal);
end;

3、输入员工号,显示员工姓名、工资(使用%rowtype完成)。

declare
v_emp emp%rowtype;
begin
select ename,sal into v_emp.ename,v_emp.sal from emp where empno=&n;
dbms_output.put_line('姓名:'||v_emp.ename||'工资:'||v_emp.sal);
end;

4、输入员工姓名,显示员工编号、工资、及工作(使用record完成)

declare
type type_emp is record(
v_empno emp.empno%type,
v_sal emp.sal%type,
v_job emp.job%type
);
v_record type_emp;
begin
select empno,sal,job into v_record from emp where ename='&n';
dbms_output.put_line('员工编号:'||v_record.v_empno || '工资:'||v_record.v_sal||'工作:'||v_record.v_job);
end;

5、输入员工号,显示雇员姓名、工资、个人所得税(税率为0.03)为例(使用record、%type完成).

declare
type type_emp is record(
v_ename emp.ename%type,
v_sal emp.sal%type,
v_money emp.sal%type
);
v_record type_emp;
begin
select ename,sal,sal-sal*0.03 into v_record from emp where empno=&n;
dbms_output.put_line('姓名'||v_record.v_ename ||'工资'|| v_record.v_sal || '个人所得税'||v_record.v_money);
end;

6、输出最高工资员工的名字,工作岗位。

declare
v_name emp.ename%type;
v_job emp.job%type;
begin
select ename,job into v_name,v_job from emp where sal=(select max(sal) from emp);
dbms_output.put_line('员工的名字'||v_name||'工作岗位'||v_job);
end;

7、输出员工中最高工资和最低工资

declare
v_max number(20);
v_min number(20);
begin
select max(sal),min(sal) into v_max,v_min from emp;
dbms_output.put_line('最高工资:'|| v_max ||'最低工资:' || v_min);
end;

8、输入员工的编号,显示员工的姓名,部门名称,工资及工资的级别

declare
type type_emp_dept_salgrade is record(
v_ename emp.ename%type,
v_dname dept.dname%type,
v_sal emp.sal%type,
v_grade salgrade.grade%type
);
v_record type_emp_dept_salgrade;
begin
select e.ename,d.dname,e.sal,s.grade into v_record from emp e ,salgrade s,dept d where e.deptno=d.deptno and e.sal between s.lowsal and s.hisal
and e.empno=&n;
dbms_output.put_line('员工姓名:' || v_record.v_ename || '部门名称:' || v_record.v_dname || '员工工资 : ' || v_record.v_sal ||'工资级别 : ' || v_record.v_grade);
end;

2.第二个中方法不显示会报错

declare
v_name emp.ename%type;
v_job dept.dname%type;
v_sal emp.sal%type;
v_grade salgrade.grade%type;
begin
select e.ename,d.dname,e.sal,s.grade into v_name,v_job,v_sal,v_grade from emp e,dept d,salgrade s where empno=&no
and e.deptno = d.deptno
and e.sal between s.losal and s.hisal;
dbms_output.put_line('员工号:'||v_name ||'工作:'||v_job||'工资:'||v_sal|| '工资级别: '||v_grade);
end;

最新文章

  1. 自己动手写游戏:Flappy Bird
  2. 【leetcode❤python】 225. Implement Stack using Queues
  3. 对div作用域的理解
  4. 一、HTML和CSS基础--网页布局--网页布局基础
  5. ReactiveCocoa的使用方法
  6. 【Origin】晨起忆梦
  7. 安卓WebView中接口隐患与手机挂马利用(远程命令执行)
  8. WHU 1579 Big data (DP)
  9. TypeScript开发ReactNative之fetch函数的提示问题
  10. VC分发包版本问题
  11. Identity Server 4 - Hybrid Flow - 使用ABAC保护MVC客户端和API资源
  12. C# ComboBox绑定值问题
  13. oracle数据库之plsql可视化操作建表
  14. Linux 安装 powershell
  15. Holer实现外网访问本地MySQL数据库
  16. css中换行与不换行的样式
  17. 中国将有可能在全球化的背景下收获新的人口红利:3星|《<财经>2019:预测与战略》
  18. FTP在CentOS上安装与使用
  19. Atitit  undac网络设备管理法案 (路由器 交换机等)    法案编号USRr101510
  20. python-django开发学习笔记四

热门文章

  1. 洛谷P1441 砝码称重
  2. Multi-catch parameters are not allowed for source level below 1.7 报错处理
  3. HDU1863-畅通工程
  4. 关于状态压缩DP以及状态压缩
  5. Exadata中的dbserver_backup.sh脚本
  6. Shell面试,笔试整理
  7. spark_20180328
  8. Unity GameObject.Find 和 transform.Find
  9. 【密码学】SSL双向认证以及证书的制作和使用
  10. ajax无刷新评论示例