• 存储过程基础


    准备数据:

    create table student(
    sName varchar(20) primary key,
    sAge int,
    sEmail varchar(100),
    sPhone varchar(20),
    sAddress varchar(100)
    )
    begin 
      insert into student values('Jack',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('Jack1',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('Jack2',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('Jack3',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('Jack54',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('Jack6',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('Jack7',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('Jack21',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('Rose',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('rose1',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('rose2',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('rose4',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('Adi',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('Aditt',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('Niyes',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('Jassic',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('Carken',21,'dfdf@qq.com','2134343','Singapore');
    insert into student values('Donview',21,'dfdf@qq.com','2134343','Singapore');
    end;

    我们查看姓名=Jack的信息,这里只有一条记录

    declare 
           l_name student.sname%type;
    ------这句话的意思就是l_name和student.sname的类型是一样的
          %rowtype就是整个表都是一样的。不用一个字段一个字段的了 begin select sname into l_name from student where sname
    ='Jack'; dbms_output.put_line('find the name;'|| l_name); end;

     查看姓名包含rose的信息(多条记录的)

    DECLARE
      cursor name_rose_cur is
      select sName from student where upper(sName) like upper('%rose%');
      l_name  student.sName%TYPE;
    BEGIN
       open name_rose_cur;
       Loop
           fetch name_rose_cur into l_name;
           exit when name_rose_cur%NOTFOUND;
            
           DBMS_OUTPUT.put_line ('find the name: '||l_name);
       end loop;
        
       close name_rose_cur;
    END;

    或者:

    DECLARE
     
      cursor name_rose_cur is
      select * from student where upper(sName) like upper('%rose%');
    BEGIN
       for student_cur
        in name_rose_cur
       Loop
           DBMS_OUTPUT.put_line ('find the name: '||student_cur.sName);
       end loop;
    END;
  • 相关阅读:
    C#根据长度创建数组
    PLC读取数据高低位交换,批量保存到list集合,方便调用。
    C#读取图片流保存到文件,再读取流文件,把图片再显示出来
    C#从SQL server数据库中读取l图片和存入图片[转]
    C# 数据库查询表字段,写入到combox
    C# MSSQL数据库查询SQL语句拼接
    C# winform只允许程序运行一个
    C# 定时关机代码
    C#用委托来动态显示日期和时间
    使用margin负值实现压住相邻边距
  • 原文地址:https://www.cnblogs.com/bulrush/p/6141283.html
Copyright © 2020-2023  润新知