zoukankan      html  css  js  c++  java
  • pl/sql

    --PL/SQL(procedual Language/SQL):过程化SQL语言。对SQL语言做的一个扩展性的语言。

    --要比SQL增加了编程语言的特点。

    --PL/SQL程序是由三部分组成:声明部分,执行部分,异常处理部分

    -- declare

        --声明部分:变量的声明,函数的声明,存储过程的声明......

    -- begin

        --执行部分:函数的调用 ,存储过程的调用,SQL语句 

    -- exception

        --异常处理部分

    -- end;

    -- 注意:执行部分不可以为空

    --PL/SQL对标识符定义的要求:

       --1.标识符的长度不能大于30个字符

       --2.第一个字符必须是字母

       --3.不区分大小写

       --4.不能是SQL、PL/SQL的关键字

       

    --数据类型:

       --char:定长的字符串类型

       --varchar2():不定长的字符串类型

       --binary_integer:带符号的整形。

       --number(p,s):整形,浮点型

       --Date:日期类型

       --boolean:布尔类型

       

    --declare

       --声明部分:声明部分和异常处理部分如果不需要可以不写,但是执行部分必须写。

    begin

      --执行部分:打印一个字符串数据值

      dbms_output.put_line('this is my first pl/sql program!');

      dbms_output.put_line(sysdate);

    end;   

    --变量的声明和使用:

      --声明变量:变量名 数据类型;

      --声明变量是直接赋值:变量名 数据类型 := 数据值;

      --声明变量后给其赋值:变量名:=数据值;

    declare

      i number(3);

      -- i:=200; error,才操作不属于声明操作,属于执行操作。

      j number(3):=100;

    begin

       i:=200;

       dbms_output.put_line(i);

    end;

    --拼接字符串:||

    declare

       num number(3):=100;

       

    begin

      dbms_output.put_line('num='||num);

    end;

    --给员工编号为 num 的员工涨 n 元工资。

    DECLARE

             num number(3):=100;

             n number(4):=5;

    BEGIN

             update employees set salary=salary+n where employee_id=num;  --DML

             commit;  --TCL

           -- error  select * from employees; --DQL

           -- error drop table t_user; --DDL

    END;

    --注意:PLSQL中的执行部分,DML和TCL是可以直接执行的。

    --DQL操作必须使用select...into才可以执行

    --DDL操作必须使用动态SQL才可执行

    --select...into语法格式:select 列1,列2 into 变量1,变量2 

    --需求:将员工标号为100的员工last_name和salary查询出来。

    --表名1.列名1%type:表示引用表名1中的列名1的数据类型。

    declare

         p_name employees.last_name%type;

         p_salary employees.salary%type;                      

    begin

          select last_name,salary into p_name,p_salary from employees where employee_id=100;

          dbms_output.put_line(p_name||','||p_salary);

    end;

    --注意:如果查询语句返回多条结果值,则select...into会报错。

    --录入:变量名 数据类型 := &input;

    declare

       p_id employees.employee_id%type := &input;--类型引用,该变量用来存储用户手动录入的数据值

      

       p_name employees.last_name%type;

       p_salary employees.salary%type;  

    begin

      

       select last_name,salary into p_name,p_salary from employees where employee_id=p_id;

        dbms_output.put_line(p_name||','||p_salary||','||p_id);

    end;

    --'&input':表示如果用户不录入数据,则将null赋值给相应变量。

    declare

       p_id employees.employee_id%type := '&input';--类型引用,该变量用来存储用户手动录入的数据值

      

       p_name employees.last_name%type;

       p_salary employees.salary%type;  

    begin

      

       --select last_name,salary into p_name,p_salary from employees where employee_id=p_id;

        dbms_output.put_line(p_name||','||p_salary||','||p_id);

    end;

    --PL/SQL(procedual Language/SQL):过程化SQL语言。对SQL语言做的一个扩展性的语言。--要比SQL增加了编程语言的特点。
    --PL/SQL程序是由三部分组成:声明部分,执行部分,异常处理部分

    -- declare    --声明部分:变量的声明,函数的声明,存储过程的声明......-- begin    --执行部分:函数的调用 ,存储过程的调用,SQL语句 -- exception    --异常处理部分-- end;-- 注意:执行部分不可以为空
    --PL/SQL对标识符定义的要求:   --1.标识符的长度不能大于30个字符   --2.第一个字符必须是字母   --3.不区分大小写   --4.不能是SQL、PL/SQL的关键字   --数据类型:   --char:定长的字符串类型   --varchar2():不定长的字符串类型   --binary_integer:带符号的整形。   --number(p,s):整形,浮点型   --Date:日期类型   --boolean:布尔类型   
    --declare   --声明部分:声明部分和异常处理部分如果不需要可以不写,但是执行部分必须写。begin  --执行部分:打印一个字符串数据值  dbms_output.put_line('this is my first pl/sql program!');  dbms_output.put_line(sysdate);end;   

    --变量的声明和使用:  --声明变量:变量名 数据类型;  --声明变量是直接赋值:变量名 数据类型 := 数据值;  --声明变量后给其赋值:变量名:=数据值;

    declare  i number(3);  -- i:=200; error,才操作不属于声明操作,属于执行操作。  j number(3):=100;begin   i:=200;   dbms_output.put_line(i);end;
    --拼接字符串:||declare   num number(3):=100;   begin  dbms_output.put_line('num='||num);end;
    --给员工编号为 num 的员工涨 n 元工资。DECLARE         num number(3):=100;         n number(4):=5;BEGIN         update employees set salary=salary+n where employee_id=num;  --DML         commit;  --TCL       -- error  select * from employees; --DQL       -- error drop table t_user; --DDLEND;
    --注意:PLSQL中的执行部分,DML和TCL是可以直接执行的。--DQL操作必须使用select...into才可以执行--DDL操作必须使用动态SQL才可执行
    --select...into语法格式:select 列1,列2 into 变量1,变量2 
    --需求:将员工标号为100的员工last_name和salary查询出来。--表名1.列名1%type:表示引用表名1中的列名1的数据类型。declare     p_name employees.last_name%type;     p_salary employees.salary%type;                      begin      select last_name,salary into p_name,p_salary from employees where employee_id=100;      dbms_output.put_line(p_name||','||p_salary);end;
    --注意:如果查询语句返回多条结果值,则select...into会报错。
    --录入:变量名 数据类型 := &input;declare   p_id employees.employee_id%type := &input;--类型引用,该变量用来存储用户手动录入的数据值     p_name employees.last_name%type;   p_salary employees.salary%type;  begin     select last_name,salary into p_name,p_salary from employees where employee_id=p_id;    dbms_output.put_line(p_name||','||p_salary||','||p_id);end;


    --'&input':表示如果用户不录入数据,则将null赋值给相应变量。declare   p_id employees.employee_id%type := '&input';--类型引用,该变量用来存储用户手动录入的数据值     p_name employees.last_name%type;   p_salary employees.salary%type;  begin     --select last_name,salary into p_name,p_salary from employees where employee_id=p_id;    dbms_output.put_line(p_name||','||p_salary||','||p_id);end;

  • 相关阅读:
    无刷电机控制基本原理
    SPI 串行Flash闪存W25Q128FV 的使用(STM32F407)_软件篇
    CAN总线简介
    RS-232串口特性
    PLSQL 安装教程
    JS 常用正则表达式备忘录
    JS数组去重
    Js中Map对象的使用
    JS操作字符串
    前端小技巧
  • 原文地址:https://www.cnblogs.com/hdj1073678089/p/7460520.html
Copyright © 2011-2022 走看看