当前位置:网站首页>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; 成功显示打印结果
边栏推荐
- Ladies and gentlemen, oracle11g, cdc2.2, flink1.13.6, single-table incremental synchronization.Without adding data
- 2022河南萌新联赛第(五)场:信息工程大学 J - AC自动机
- 强化学习_06_pytorch-DQN实践(CartPole-v0)
- Why do games need hot updates
- 几行代码就可以把系统高崩溃;
- May I ask why sqlserver cdc will report this error one day after the task is started, obviously cdc has been opened.
- 机器学习_LGB调参汇总(开箱即食)
- About MongoDb query Decimal128 to BigDecimal problem
- CuteOneP is a PHP-based OneDrive multi-network disk mount program with member synchronization and other functions
- 高质量WordPress下载站模板5play主题
猜你喜欢
深入理解LTE网络的CDRX
数据库学习之数据类型
CuteOneP is a PHP-based OneDrive multi-network disk mount program with member synchronization and other functions
Chapter 11 Database Design Specifications [2. Index and Tuning] [MySQL Advanced]
761. 特殊的二进制序列
【Event Preview on August 9】Prometheus Summit
WooCommerce 安装和 rest api 使用
[Reinforcement Learning] "Easy RL" - Q-learning - CliffWalking (cliff walking) code interpretation
COLMAP+OpenMVS realizes 3D reconstruction mesh model of objects
【电商业务】外行为何难区别 商品属性与商品规格
随机推荐
几行代码就可以把系统高崩溃;
The difference between initializing objects as null and empty objects in JS
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
2022 Henan Mengxin League No. 5: University of Information Engineering J-AC Automata
Elementary Structure
MySQL database monthly growth problem
Data types for database learning
mysql之两阶段提交
ESP32 485风速
A few lines of code can crash the system;
2022 Henan Mengxin League Game (5): University of Information Engineering C - Throwing a Handkerchief
自动化测试框架Pytest(一)——入门
浅谈C语言整型数据的存储
About MongoDb query Decimal128 to BigDecimal problem
COLMAP+OpenMVS实现物体三维重建mesh模型
High quality WordPress download station 5 play theme template
MVCC详解
【强化学习】《Easy RL》- Q-learning - CliffWalking(悬崖行走)代码解读
基于STC8G2K64S4单片机通过OLED屏幕显示模拟量光敏模拟值
关于数据库中的中文模糊检索探讨