⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 作业_getbookname.txt

📁 orale培训教材包括了所有的sql说明和实例
💻 TXT
字号:
--基本表结构
--图书
create table book (
isbn char(13) primary key,--ISBN号
name varchar2(20),
zuozhe varchar2(40), --考虑合著
price number(6,2),
publisher varchar2(30),
shuliang number(8,0),
publishdate date);
--建立定购表
create table booked( 
isbn char(13),
benshu number(3,0), 
uername varchar2(20));
--------------------------------数据---------------------------------
insert into book values
('7-5053-6548-7','ORACLE入门','Tom',30.5,'清华大学出版社',1000,'16-7月 -02');

insert into book values
('7-5053-6548-6','ORACLE宝典','PETER CHEN,赵德奎',60,'清华大学出版社',1000,'16-7月 -02');

insert into book values
('7-5053-6548-5','oracle实用技巧','JACK',60,'北京大学出版社',1000,'16-7月 -01');

insert into book values
('7-5053-6548-4','JAVA入门','赵德奎',30,'清华大学出版社',1000,'10-7月 -02');

insert into book values
('7-5053-6548-3','JAVA技巧','赵德奎',60,'清华大学出版社',0,'16-1月 -01');

insert into book values
('7-5053-6548-2','oracle大全','JACK',40,'北京大学出版社',1000,'16-7月 -01');

--参见  综合练习2.txt---------------------------------

--基本功能:按给定isbn输出相应图书信息
create or replace procedure getbookname 
(p_isbn in char) is
--loacal 变量
  v_name book.name%TYPE;--用type方法声明变量
  v_price number;

begin

  select name,price into v_name,v_price from book
  where isbn = p_isbn;
  dbms_output.put_line('ISBN : ' || p_isbn);
  dbms_output.put_line('书名 : ' || v_name);
  dbms_output.put_line('售价 : ' || v_price);
end;

--没有对应isbn没处理。想输出一个提示

----改进1。解决没有isbn问题

create or replace procedure getbookname 
(p_isbn in char) is
--loacal 变量
  v_name book.name%TYPE;--用type方法声明变量
  v_price number;

begin

  select name,price into v_name,v_price from book
  where isbn = p_isbn;
  if v_price is null then 
     dbms_output.put_line('没有这本书!');
     
  else
	  dbms_output.put_line('ISBN : ' || p_isbn);
	  dbms_output.put_line('书名 : ' || v_name);
	  dbms_output.put_line('售价 : ' || v_price);
  end if;
end;
--企图判断有无此isbn:失败!  具体见 图书_exception.ppt
--当没有输入的isbn,总无法输出这句话.
--因为select into 要求必须有并且只有一条记录,返回0条2条,都出错.会产生一个exception.
--跳过其他语句 ,直接end.

--改进 :用exception处理
create or replace procedure getbookname 
(p_isbn in char) is
--loacal 变量
  v_name book.name%TYPE;--用type方法声明变量
  v_price number;

begin

  select name,price into v_name,v_price from book
  where isbn = p_isbn;
  
  dbms_output.put_line('ISBN : ' || p_isbn);
  dbms_output.put_line('书名 : ' || v_name);
  dbms_output.put_line('售价 : ' || v_price);

exception
  when no_data_found then 
  dbms_output.put_line('没有这本书!');
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -