if语句
1.语法:
if 条件表达式 then
plsql语句
end if;
语义:当条件成立时,执行then 和end if 之间的代码,如果条件不成立,不做任何操作。
--写一个代码块,从键盘接收一个值,如果这个值大于10,那么打印这个值,如果小于10什么也不做
declare
--声名一个变量保存,键盘输入的值
n number:=&值;
begin
if n>10 then
dbms_output.put_line(n);
end if;
end;
2.else 语句
语法:
if 条件表达式 then
plsql语句
else
plsql 语句
end if;
语义:当if后面的条件成立时,执行then和else之间的语句,如果条件不成立,执行else和end if 之间的程序
--写一个程序,从键盘输入两个值,判断两个值的大小,打印比较大的值
declare
--声名两个变量,保存键盘输入的两个值
m number:=&第1个值;
n number:=&第2个值;
begin
if m > n then
--m是最大值,打印m
dbms_output.put_line('m='||m);
else
--n是较大的值,打印n
dbms_output.put_line('n='||n);
end if;
end;
3.elsif 语句
语法:
if 条件表达式1 then
plsql语句
elsif 条件表达式2 then
plsql语句
elsif 条件表达式3 then
plsq语句
......
else
plsql语句
end if;
语义:当前条件1成立时,执行then和elsif之间的代码,当elsif后面的条件成立时,执行相应得then和elsif之间的代码,如果条件都不成立,执行else和end if 之间的代码,只有一个分支被执行,其中else部分是可以省略的,
declare
--声名一个变量保存成绩
score number:=&成绩;
begin
if score<60 then
dbms_output.put_line('不及格');
elsif score<70 then
dbms_output.put_line('及格');
elsif score<80 then
dbms_output.put_line('良好');
else
dbms_output.put_line('优秀');
end if;
end;
4.case语句
语法1
case when 条件表达式 then
plsql语句
when 条件表达式then
plsq语句
....
else
plsql语句
end case;
语法2
cese 表达式
when 值 then
plsql语句
when 值 then
plsql语句
....
end case;
表达式:返回一个固定的值
when 用来列举表达式结果,如果表达式的结果和when列的值相同时,执行相应的plsql语句,只有一个分支被执行。
declare
--声名一个变量,接收键盘输入的成绩
score number:=&成绩;
begin
case
when score<60 then
dbms_output.put_line('不及格');
when score<70 then
dbms_output.put_line('及格');
when score<80 then
dbms_output.put_line('良好');
else
dbms_output.put_line('优秀');
end case;
end;
declare
score number:=&成绩;
begin
case floor(score/10)
when 10 then
dbms_output.put_line('优秀');
when 9 then
dbms_output.put_line('优秀');
when 8 then
dbms_output.put_line('优秀');
when 7 then
dbms_output.put_line('良好');
when 6 then
dbms_output.put_line('及格');
else
dbms_output.put_line('不及格');
end case;
end;
循环:相同或相似的代码重复执行
5.loop循环***
语法:
loop
---循环体语句,实现功能的代码
--退出循环语句,决定退出循环的时机,条件:exit :表示退出循环,exit when 退出条件
--循环控制语句,修改循环变量的值
end loop
loop 循环需要自己声明循环变量,结合退出条件决定循环执行的次数
declare
--声名一个循环变量,保存数字
n number:=1;
begin
/***
n=1
第1次 打印n的值 n=1 判断退出条件n>8 1>8不成立 n=n+1=2
第2次 ......... n=2 ................2>8 .... n=n+1=3
第3次 。。。。。n=3 ................3>8 .... n=n+1=4
........
第8次 ,........ n=8 。。。。。。。。8>8 ... n=n+1=9
第9次 。。。。。n=9 ................9>8成立 exit
*/
loop
--循环体语句
dbms_output.put_line(n);
--退出循环语句
exit when n>8;
/*
if n>8 then
exit;
end if;
*/
--循环控制语句
n:=n+1;
end loop;
end;
6.while循环
语法:
while 循环条件 loop
--循环控制语句
--循环控制语句
```end loop;
示例
```sql
declare
--声名一个循环变量
n number:=1;
begin
/**
n=1
第1次 判断while后面的循环条件 n<=9 1<=9成立 打印n=1 n=n+1=2
第2次 .............................2<=9.... 打印n=2 n=n+1=3
第3次 .............................3<=9... .....n=3 n=n+1=4
.......................................
第8次 。。。。。。。。。。。。。。 8<=9 打印n=8 n=n+1=9
第9次 .............................9<=9 打印n=9 n=n+1=10
第10次 。。。。。。。。。。。。。。 10<=9不成立退出
*/
while n<=9 loop
--循环体语句
dbms_output.put_line(n);
--循环控制语句
n:=n+1;
end loop;
end;
7for 循环***
语法:
for 循环变量 in [reverse] 集合|游标|select 语句 loop
--循环体语句
end loop;
reverse :表示反转
begin
for n in reverse 1..9 loop
dbms_output.put_line(n);
end loop;
end;
min..max:表示一连续数字集合
--当for循环in后面不是数字集合时,循环变量默认是一个记录类型 变量名.属性名
begin
for v in (select ename,sal from emp) loop
dbms_output.put_line(v.ename||','||v.sal);
end loop;
end;
for循环的循环变量不需要声名,但是只能在loop和end loop之间使用
1.引入库
代码如下(示例):
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
2.读入数据
代码如下(示例):
data = pd.read_csv(
'https://labfile.oss.aliyuncs.com/courses/1283/adult.data.csv')
print(data.head())
该处使用的url网络请求的数据。
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。