create_procedure.md 1.7 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 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
## 答案

```mysql
create procedure sp_idt(in salary decimal(12, 4), out tax decimal(12, 4), out take_home decimal(12, 4)) 
begin 
    set tax = individual_income_tax(salary);
    set take_home = salary - tax;
end;
```

## 选项

### A

```mysql
create procedure sp_idt(salary decimal(12, 4)) returns (tax decimal(12, 4), take_home decimal(12, 4))
begin 
    set tax = individual_income_tax(salary);
    set take_home = salary - tax;
end;
```

### B


```mysql
create procedure sp_idt(salary decimal(12, 4)) returns (decimal(12, 4), decimal(12, 4))
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

```mysql
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

```mysql
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;
```