当前位置:网站首页>PLSQL学习第一天
PLSQL学习第一天
2022-08-10 06:49:00 【loveforever__】
一 学习内容
1.plsql developer安装教程及配置
2.plsql developer 工具的简单使用
3.使用plsql developer工具创建数据库
create table test_5(
id number(2) primary key,
name varchar(10) not null
);

4.plsql块结构和组成元素
PL/SQL 块 PL/SQL 程序由三个块组成, 即声明部分DECLARE、 BEGIN 执行部分、 异常处理部分EXCEPTION
PL/SQL 块的结构:
DECLARE
BEGIN
EXCEPTION
END;
5.变量和类型
变量类型有
char (定长字符串)
varchar2 (可变字符串)
binary _integer (带符号整数)
number(p,s) (小数)
long
date
boolean
rowid(存放数据库行号)
urowid(通用行标识符)
6.变量赋值
语法: variable := expression ;
variable 是一个 PL/SQL 变量 ,
expression 是一个 PL/SQL 表达式
7.%TYPE
使用 %TYPE 定义一个变量, 其数据类型与已经定义的某个数据变量的类型相同, 或者与数据库表的某个列的数据类型 相同, 这时可以使用 %TYPE 。
使用 %TYPE 特性的优点在于所引用的数据库列的数据类型可以不必知道;所引用的数据库列的数据类型可以实时改变。
8.注释使用双-号,它的作用范围是只能在一行有效。
9.使用plsql语句实现增删改查
在新建的test_5表中插入一条语句
declare
v_id number(2) :=10;
v_name varchar(20) :='bill';
begin
insert into test_5 (id, name)
values(v_id, v_name);
commit;
end;

declare
v_id number(2) :=2;
begin
delete from test_5 where id=v_id;
commit;
end;

10.plsql流程控制语句
一共有三类:
控制语句 : I F 语句
循环语句 : LOOP 语句 , EXIT 语句
顺序语句 : GOTO 语句 , NULL 语句
11.游标的使用
-- Created on 2022/8/2 by YINGYING01.YU
--打印出部门为80的所有员工的薪水
declare
v_sal employees.salary%type;
v_empid employees.employee_id%type;
--定义游标
cursor emp_sal_cursor is select salary,employee_id from employees where department_id=80;
begin
--打开游标
open emp_sal_cursor;
--提取游标
fetch emp_sal_cursor into v_sal,v_empid;
while emp_sal_cursor%found loop
dbms_output.put_line('empid:'||v_empid||'salary:'||v_sal);
fetch emp_sal_cursor into v_sal,v_empid;
end loop;
--关闭游标
close emp_sal_cursor;
end;
-- Created on 2022/8/2 by YINGYING01.YU
--打印出部门为80的所有员工的薪水
declare
--声明一个记录型
type emp_record is record(
v_sal employees.salary%type,
v_empid employees.employee_id%type
);
--声明一个记录行型的变量
v_emp_record emp_record;
--定义游标
cursor emp_sal_cursor is select salary,employee_id from employees where department_id=80;
begin
--打开游标
open emp_sal_cursor;
--提取游标
fetch emp_sal_cursor into v_emp_record;
while emp_sal_cursor%found loop
dbms_output.put_line('empid:'|| v_emp_record.v_empid||'salary:'|| v_emp_record.v_sal);
fetch emp_sal_cursor into v_emp_record;
end loop;
--关闭游标
close emp_sal_cursor;
end;

--游标的for循环 可以省略游标的定义提取和关闭
-- Created on 2022/8/2 by YINGYING01.YU
--打印出部门为80的所有员工的薪水
declare
v_sal employees.salary%type;
v_empid employees.employee_id%type;
--定义游标
cursor emp_sal_cursor is select salary,employee_id from employees where department_id=80;
begin
/*---打开游标
open emp_sal_cursor;
--提取游标
fetch emp_sal_cursor into v_sal,v_empid;
while emp_sal_cursor%found loop
dbms_output.put_line('empid:'||v_empid||'salary:'||v_sal);
fetch emp_sal_cursor into v_sal,v_empid;
end loop;
--关闭游标
close emp_sal_cursor;
*/
for c in emp_sal_cursor loop
dbms_output.put_line('empid:'||v_empid||'salary:'||v_sal);
end loop;
end;

12.利用游标,调整公司中员工的的工资
二:遇到的问题
问题一:plsql的命令行窗口不显示DBMS_OUTPUT的打印结果

解决:需要设置set serveroutput on; 成功显示打印结果

边栏推荐
- 杭州公积金修改手机号信息
- S0:12345:respawn:/bin/start_getty 115200 ttyS0 vt102
- WooCommerce installation and rest api usage
- 添加spark的相关依赖和打包插件(第六弹)
- 3.事务篇【mysql高级】
- Unity3d famous project-Dark Tree translation
- COLMAP+OpenMVS realizes 3D reconstruction mesh model of objects
- I would like to ask you guys, when FLink SQL reads the source, specify the time field of the watermark. If the specified field is in the grid
- 【强化学习】《Easy RL》- Q-learning - CliffWalking(悬崖行走)代码解读
- Bigder:42/100 showCase多少bug可以打回去
猜你喜欢

navicat for mysql 连接时报错:1251-Client does not support authentication protocol requested by server

几行代码就可以把系统高崩溃;

A few lines of code can crash the system;

1413. Stepwise Summation to Get Minimum Positive Numbers

ES13 - ES2022 - The 123rd ECMA Congress approves the ECMAScript 2022 language specification

What is an MQTT gateway?What is the difference with traditional DTU?

WooCommerce 安装和 rest api 使用

WooCommerce installation and rest api usage

761. Special Binary Sequences

delta method 介绍
随机推荐
几行代码就可以把系统高崩溃;
Bigder:42/100 showCase多少bug可以打回去
MySQL索引事务
order by注入与limit注入,以及宽字节注入
自动化测试框架Pytest(三)——自定义allure测试报告
DGIOT三千万电表集抄压测
修改 QtCreator 配置解决 “无法运行 rc.exe” 问题
幂函数 指数函数 对数函数
自组织是管理者和成员的双向奔赴
Qt程序字体初始化引起的白屏问题
调试ZYNQ的u-boot 2017.3 不能正常启动,记录调试过程
3. Transactions [mysql advanced]
Confluence可以连接数据库但是在下一步就报错了
【Day10】进程管理命令
Sort binary tree code
结构体初阶
941 · 滑动拼图
关于数据库中的中文模糊检索探讨
u-boot ERROR: Failed to allocate 0x5c6f bytes below 0x17ffffff.Failed using fdt_high value
软件测试面试题避雷(HR面试题)最常见的面试问题和技巧性答复