首页 > 数据库 >5.PL/SQL数据类型

5.PL/SQL数据类型

时间:2022-12-15 17:25:38浏览次数:41  
标签:stuname 表中 数据类型 stuinfo SQL 类型 PL ls

1.标量数据类型

变量数据类型的变量只有一个值,且内部没有分量

  1. 数值类型:用于存储数值类型的数据。如:
    number:可以存储小数和整数类型数据。格式为:
    number(p,s):p表示长度,s表示小数点后的位数
  2. 字符类型:用来存储单个字符或字符串,有:
    1. char
    2. varchar2
    3. long
      3.时间类型:date,timestamp
      4.布尔类型:true,false,null

2.引用数据类型

是PL/SQL程序语言中特有的数据类型,是用来引用数据库当中的某一行或者某个字段作为数据类型的声明。

  1. %type类型:引用数据库表中的某列的类型作为某变量的数据类型
declare
ls_stuname stuinfo.stuname%type;--通过学生姓名字段声明ls_stuname
begin
  select t.stuname into ls_stuname
    from student.stuinfo t
   where t.stuid = 'SC201801006';   
  dbms_output.put_line(ls_stuname);
exception
  when no_data_found  then
     dbms_output.put_line('该学生在学生信息表中找不到');
end;
  1. %rowtype类型:引用数据库表中的一行作为数据类型
declare
ls_stuinfo stuinfo%rowtype;
xsjbxx varchar2(50);
begin
  select t.* into ls_stuinfo
    from stuinfo t
   where t.stuid='SC201801006';
   xsjbxx:='姓名:' ||ls_stuinfo.stuname || ' 学号:' ||ls_stuinfo.stuid || ' 年龄:' ||ls_stuinfo.age;
  dbms_output.put_line(xsjbxx);
exception
  when no_data_found  then
     dbms_output.put_line('该学生在学生信息表中找不到');
end;

标签:stuname,表中,数据类型,stuinfo,SQL,类型,PL,ls
From: https://www.cnblogs.com/mxx520/p/16985582.html

相关文章

  • 6.PL/SQL控制结构
    1.PL/SQL顺序结构顺序结构中我们经常使用goto的关键字进行程序的跳转(不在非不得已的情况下,不要使用)declarels_stuinfostuinfo%rowtype;xsjbxxvarchar2(50);begin......
  • 7.PL/SQL动态执行DDL语句
    1.语法EXECUTEIMMEDIATE动态SQL语句[into变量列表][using参数列表]语法解析:如果动态SQL语句是SELECT语句,可以把查询的结果保存到INTO后面的变量中。如果......
  • 8.PL/SQL异常处理
    语法结构declare--声明部分begin--执行部分exception--异常部分whenexception1then--异常1处理程序[whenexception2then--异常2处理程序][whenother......
  • 盘点现在用的SqlServer 5种分页方式和拉姆达表达式分页,进来看看吧。
    现在基本上大家都在使用各种轮子自带的分页,大家是否还记得sql分页怎么写?今天我们就来盘一盘怎么写和用哪种方式写。欢迎大家评论区讨论。1、ROW_NUMBER()OVER()方式(SQL......
  • k8s创建MySQL
    Kubernetes创建MysQL整体流程:创建数据存储PV、PVC;创建MySQL数据库、创建访问入口Service;导入测试数据库test-db创建数据存储PV、PVC这里我们使用nfs作为storageclass......
  • 嵌入式数据库 sqllite & h2  utils
    使用场景:简单脚本,但是有需要数据记录.(使用前升级下版本)     我的使用:老机器,老项目,jkd6, 需要记录 SqlLiteUtilspackagecom.icil.edi.listener......
  • ORM执行SQL 双下划线查询 ORM外键字段创建 外键字段相关操作 ORM跨表查询 跨表查询进
    目录ORM执行SQL语句方式1:使用pymysql模块方式2:使用raw方法方式3:djangoconnection双下划线查询__gt(>)__lt(<)queryset对象特性__gte(≥)__lte(≤)__in__range__cont......
  • SQL的使用总结
    select*fromempselect*fromdeptselect*fromjobselect*fromsalarygrade--1.查询所有员工信息。查询员工编号,员工姓名,工资,职务名称,职务描述SELECT t1......
  • JavaconfigApplicationTests
    packagecom.example.demo;importcom.example.demo.config.JavaConfig;importcom.example.demo.model.Printer;importorg.junit.Test;importorg.junit.runner.Ru......
  • vite plugin
    //自定义插件./plugins/fullImportPluginimport*aspathfrom'path'importtype{Plugin,ResolvedConfig}from'vite'exportdefaultfunctionfullImportPl......