• oracle PL/SQL语法基础


    目录

    数据类型

     定义变量

     PL/SQL控制结构

    参考资料

    Oracle10g数据类型总结

    PL/SQL之基础篇

    数据类型

     

    学习总结

    字符类型

    char、nchar、varchar、nvarchar:有n的以字符存储无n的以字节存储,有var是可变的,存储空间以实际大小存储,无var的是固定大小,从空格补齐。

     数字类型

    NUMBER(p[,s]):定点数,s为小数位数

    BINARY_FLOAT:32位单精度浮点数类型

    BINARY_DOUBLE:64位双精度浮点数类型。

    时间类型

    date

    定义变量

    参考资料

    Oracle使用手册(一)---声明变量

    定义变量时可以用:=来赋值

    1、定义基本变量

    如:declare 变量名 变量类型

    2、用属性来定义%type

    可以是表字段或变量的属性

    declare name tableName.fieldName%type;

    declare name2 name%type

    3、用%rowtype,定义变量是表的一行

    delcare row tableName%rowtype

    4、定义记录类型变量--将多个基本数据类型捆绑在一起的记录数据类型。

    语法:type 记录类型名 is record(定义基本类型)

    set serveroutput on
        declare
            type myrecord is record(
               sid int,
               sdate date);
            srecord myrecord; --声明一个自定义记录类型变量的实例
        begin
            select sid,sdate into srecord from student where sid=68;
            dbms_output.put_line('ID: '|| srecord.sid ||'Date:'||  srecord.sdate); --'||': 它是字符串连接符.
        end;

    5、表类型变量

    语法:

    TYPE table_name IS TABLE OF data_type [ NOT NULL ]
    INDEX BY BINARY_INTEGER ;
    语法说明如下:
    --table_name  创建的表类型名称。
    --IS TABLE  表示创建的是表类型。
    --data_type  可以是任何合法的PL/SQL数据类型,例如varchar2。
    --INDEX BY BINARY_INTEGER  指定系统创建一个主键索引,用于引用表类型变量中的特定行。

    声明只有一个字段的表:

    declare

    type tabletype1 is table of varchar2(4) index by binary_integer; 

    mytable1 tabletype1

    声明多个字段的表

    Declare
          type tabletype1 is table of student%rowtype index by binary_integer;
          table1 tabletype1;

            type tabletype2 is table of 记录类型变量 index by binary_integer

        table2 taabletype2

    declare
         num_1 number(7,2):=1234.33;--初始值
        field1 tableName.fieldName%type--用表字段申明
        field2 field1%type--用变量属性申明

     PL/SQL控制结构

    1、if

  • 相关阅读:
    C# List<string>和List<int>互相转换
    sourcetree跳过注册的方法
    列举 contentType: 内容类型(MIME 类型)
    nginx 使用过程中一些基础性问题总结
    MVC3升级到MVC4模型验证信息显示为英文问题及解决方案
    ckeditor:复制内容到ckeditor时,只保留文本,忽略其样式解决方法
    MVC从视图传参到Controller几种方式
    Window Service 计划任务
    Git命令行连Github与TortoiseGit 连Github区别
    For xml path
  • 原文地址:https://www.cnblogs.com/shengyu-kmust/p/4437660.html
Copyright © 2020-2023  润新知