Oracle creates B-trees, reverses, bitmap indexes, declares variables, process control (judgment), catches exceptions, opens cursors, stored procedures, and passes parameters

Wang Wenfeng's attention picture, Gan!

learning target

1. Master JAVA entry to advanced knowledge in one week ( continuous writing... )
2. Master basic C# l window knowledge ( creating... )
3. Teach you how to make vbs scripts ( complete... )
4. Powerful IDEA programming tool ( written in ...... )
5, the classic common interview questions skills ( update ...... )


Oracle creates B-trees, reverses, bitmap indexes, declares variables, process control (judgment), catches exceptions, opens cursors, stored procedures, and passes parameters


Preface

Insert picture description here


Hope: In the new year of 2021, you will have everything you want and let it go!

Create index

SELECT * FROM STUDENT WHERE SSEX='男'
-- 创建B树索引
CREATE INDEX index_id ON STUDENT(SID)
--删除索引
DROP INDEX index_id
--创建反向键索引
CREATE INDEX index_reverse_id ON STUDENT(SID) REVERSE
-- 创建位图索引
CREATE BITMAP INDEX index_bit_sex ON STUDENT(SSEX)
drop INDEX index_bit_sex

Declare variable

声明变量
declare 
     v_name varchar2(50):='男神';
     -- 把student表中sex字段的数据类型作为当前变量的数据类型
     v_sex STUDENT.SSEX%type;
begin
  -- 第一种赋值方式
  v_name:='男神';
  -- 输出语句
  dbms_output.put_line(v_name);
  -- 第二种赋值方式,把表中的某条数据赋值到变量中
  SELECT SNAME,SSEX INTO v_name,v_sex FROM STUDENT WHERE SID=10;
  dbms_output.put_line(v_name||'-'||v_sex);
end;

Process control (judgment)

- 流程控制(判断)
declare
   v_score number:=90;
   v_remark varchar2(50);
begin
  case --判断开始
    --when 判断 then 满足条件后执行;
    when v_score=100 then v_remark:='满分';
    when v_score>=80 then v_remark:='优秀';
    when v_score>=60 then v_remark:='及格';
    else --如果前面的条件都不符合就进入else
        v_remark:='不及格';
  end case;--判断结束  
  dbms_output.put_line(v_remark);

Catch exception

-- 捕获异常
  -- exception
   -- when 需要捕获的异常类型 then 如果发生该异常怎么处理;
  exception
    when ACCESS_INTO_NULL then dbms_output.put_line('报错了');
end;
--游标,类似于java jdbc查询后的结果集,可以保存一条sql的查询结果
declare
    v_name STUDENT.SNAME%TYPE;
    -- cursor(定义游标关键字) 游标名称 IS 查询语句
    cursor cursor_sname IS SELECT SNAME FROM STUDENT;
 begin
   --打开游标
   open cursor_sname;
   loop
        --循环游标把每次获取到的值放到变量中
        fetch cursor_sname into v_name;
        --循环的退出条件
        --cursor_sname%NOTFOUND游标中是否还存在下一个数据
        exit when cursor_sname%NOTFOUND;
        dbms_output.put_line(v_name);
   end loop;
 end;

Stored procedure

--存储过程,类似java中的方法,Java可以通过存储过程名称调用已经定义好的存储过程
 --创建或者修改存储过程
 CREATE OR REPLACE PROCEDURE add_student(
        --参数,输入参数和输出参数
        v_sname varchar2,
        v_ssex varchar2,
        v_sage out number 
 )
 is
 begin
   insert into student values(STU_ID.Nextval,v_sname,v_ssex,v_sage);
 end; 
declare  
 v_xxxx varchar2(50);
begin
 -- 按照顺序传参
 add_student('小三角','女',v_xxxx);
 
 -- 按照参数名称传值
 add_student(v_ssex=>'男',v_sage=>11,v_sname=>'dsadsa');
 
 commit;
end;
SELECT * FROM STUDENT

to sum up

Insert picture description here

Learning Oracle is a long and arduous process. If you have no interest but are forced to learn, then it is difficult to learn well. To summarize briefly, it is: interest, learning and practice.

Guess you like

Origin blog.csdn.net/Feng_wwf/article/details/114071654