Variables of sql in pl / sql

I. Definition of variables

1. Grammar

declare 
    变量名 数据类型 := 赋值;
begin
    dbms_output.put_line(变量名);---打印变量的语法

end;

2. Examples
image

image

2. Advanced application of variables

1. Syntax one [reference variable]

--变量的高级应用:将别的表中的某列的数据赋值到变量
--格式解析:变量名 表名.列名%type;获取指定列的数据类型引入到变量
    ena emp.ename%type;--引用型变量
--将指定数据赋值变量:into赋值变量,需要在begin输出语句下写
select ename into ena from emp where empno = 7788

2. Examples

image

image

3. Grammar two [recorded variables]

--格式解析:变量名 表名%rowtype;获取指定列的数据类型引入到变量
    --记录型变量的数据类型引入
    emprow emp%rowtype;--记录型变量

--格式解析:变量名 表名%rowtype;获取一行的数据类型记录到变量
    select * into emprow from emp where empno = '7788';--赋值到记录型变量

dbms_output.put_line (emprow.ename || ', this is the oracle connector: ||,' || emprow.job); – verification result

4. Examples
image

5. Verify the answer

image

3. Summary

Assignment operation can use **: = , can also use into **.

The connector of the string is ** || **.

The record variable cannot be directly output, and the data needs to be output through the column name.

Published 62 original articles · won praise 20 · views 6775

Guess you like

Origin blog.csdn.net/qq_45421186/article/details/105464013