create_procedure.md 1.8 KB
Newer Older
M
Mars Liu 已提交
1 2 3 4 5 6
# 创建存储过程

计算个人所得税的函数 individual_income_tax 很好用,但是每次要保存税额和税后工资,
Joe 希望这个计算更紧凑一些,在已经有 individual_income_tax 的前提下,Joe 决定
写一个存储过程 sp_idt ,同时生成所得税和税后工资。这个存储过程的声明应该是:

M
Mars Liu 已提交
7 8
<hr/>

F
feilong 已提交
9
点击进入[MySQL实战练习环境](https://mydev.csdn.net/product/pod/new?image=cimg-centos7-skilltreemysql&connect=auto&create=auto&utm_source=skill){target="_blank"}。
F
feilong 已提交
10

F
feilong 已提交
11 12
* `show databases;` 列出所有数据库
* `show tables;` 列出所有表
M
Mars Liu 已提交
13

M
Mars Liu 已提交
14 15
## 答案

fix bug  
张志晨 已提交
16
```sql
17 18 19 20
create procedure sp_idt(
    in salary decimal(12, 4), 
    out tax decimal(12, 4), 
    out take_home decimal(12, 4)) 
M
Mars Liu 已提交
21 22 23 24 25 26 27 28 29 30
begin 
    set tax = individual_income_tax(salary);
    set take_home = salary - tax;
end;
```

## 选项

### A

fix bug  
张志晨 已提交
31
```sql
32 33 34
create procedure sp_idt(salary decimal(12, 4)) 
    returns (tax decimal(12, 4), 
        take_home decimal(12, 4))
M
Mars Liu 已提交
35 36 37 38 39 40 41 42 43
begin 
    set tax = individual_income_tax(salary);
    set take_home = salary - tax;
end;
```

### B


fix bug  
张志晨 已提交
44
```sql
45 46
create procedure sp_idt(salary decimal(12, 4)) 
    returns (decimal(12, 4), decimal(12, 4))
M
Mars Liu 已提交
47 48 49 50 51 52 53 54 55 56
begin 
    declare tax, take_home decimal(12, 4);
    set tax = individual_income_tax(salary);
    set take_home = salary - tax;
    return (tax, take_home);
end;
```

### C

fix bug  
张志晨 已提交
57
```sql
M
Mars Liu 已提交
58 59 60 61 62 63 64 65 66
create procedure sp_idt(in salary decimal(12, 4), out tax decimal(12, 4), out take_home decimal(12, 4)) returns void
begin 
    set tax = individual_income_tax(salary);
    set take_home = salary - tax;
end;
```

### D

fix bug  
张志晨 已提交
67
```sql
M
Mars Liu 已提交
68 69 70 71 72 73 74 75
create procedure sp_idt(in salary decimal(12, 4)) 
begin
    declare tax, take_home decimal(12, 4);
    set tax = individual_income_tax(salary);
    set take_home = salary - tax;
    select tax, take_home;
end;
```