码迷,mamicode.com
首页 > 数据库 > 详细

Oracle 实验四

时间:2016-11-19 02:05:40      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:from   span   case   exe   partition   rom   copy   when   过程   

SQL*Plus: Release 11.2.0.1.0 Production on 星期五 11月 18 19:32:00 2016

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

请输入用户名:  system
输入口令:

连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> connect / as sysdba
已连接。

SQL> /
输入 str 的值:  20110002
原值    5: v_no := &str;
新值    5: v_no := 20110002;

PL/SQL 过程已成功完成。

SQL> set serveroutput on



SQL> /
输入 str 的值:  20110002
原值    5: v_no := &str;
新值    5: v_no := 20110002;
马力

PL/SQL 过程已成功完成。

SQL> insert into t_student(Sno,Sname,sbirthday) values(20110002,马力,TO_DATE(1991-02-21,YYYY-MM-DD));

已创建 1 行。

SQL> /

已创建 1 行。







SQL> edit
已写入 file afiedt.buf

  1  declare
  2  v_score  t_score.score%type;
  3  begin
  4  select score into v_score from t_score where sno=20100002 and Sub_no=001;
  5  case
  6  when v_score<81 then v_score:=v_score+8;
  7  when v_score<91 then v_score:=v_score+5;
  8  when v_score<97 then v_score:=v_score+3;
  9  end case;
 10  update t_score set score=v_score where sno=20100002 and Sub_no=001;
 11* end;
 12  /

PL/SQL 过程已成功完成。

SQL> select * from t_score where sno = 20100002 and Sub_no=001;

SNO        SUB_NO          SCORE
---------- ---------- ----------
20100002   1                  92



SQL> edit
已写入 file afiedt.buf

  1  declare
  2  v_counter binary_integer:=1;
  3  begin
  4  while v_counter<=100 loop
  5  if mod(v_counter,3) = 0 and mod(v_counter,2)=0
  6  then dbms_output.put_line(v_counter|| );
  7  end if;
  8  v_counter :=v_counter+1;
  9  end loop;
 10* end;
SQL> /
6
12
18
24
30
36
42
48
54
60
66
72
78
84
90
96

PL/SQL 过程已成功完成。

SQL> create or replace procedure add_student(p_sno t_student.sno%type, p_sname t_student.sname%type, p_ssex t_student.ssex%type, p_sbirthday t_student.sbirthday%type)
  2  as
  3
  4  begin
  5  insert into t_student values(p_sno,p_sname,p_ssex,p_sbirthday);
  6  end;
  7  /

过程已创建。



SQL> execute add_student(20140001,林蔚然,1,15-2月-1996);

PL/SQL 过程已成功完成。

SQL> select * from t_student;

SNO        SNAME            SSEX SBIRTHDAY
---------- ---------- ---------- --------------
20110002   马力                  21-2月 -91
20100002   张杰                1 03-1月 -92
20100003   李娟                0 14-6月 -92
20110001   王强                1
20100001   刘浩                1 12-10月-91
20140001   林蔚然              1 15-2月 -96

已选择6行。




SQL> edit
已写入 file afiedt.buf

  1  create or replace procedure ave(p_sno t_score.sno%type)
  2  as
  3  avg_score t_score.score%type;
  4  begin
  5  select avg(score) into avg_score from t_score where sno=p_sno;
  6  dbms_output.put_line(avg_score);
  7* end;
SQL> /

过程已创建。

SQL> execute ave(20100003);
86.5

PL/SQL 过程已成功完成。

SQL> edit
已写入 file afiedt.buf

  1  declare
  2  name t_student.sname%type;
  3  no t_student.sno%type;
  4  begin
  5  no := &str;
  6  select sname into name from t_student where sno=no;
  7  dbms_output.put_line(name);
  8  exception
  9  when no_data_found then
 10  dbms_output.put_line(data not found!);
 11* end;
SQL> /
输入 str 的值:  20140001
原值    5: no := &str;
新值    5: no := 20140001;
林蔚然

PL/SQL 过程已成功完成。

SQL> /
输入 str 的值:  20140002
原值    5: no := &str;
新值    5: no := 20140002;
data not found!

PL/SQL 过程已成功完成。

SQL>

 

Oracle 实验四

标签:from   span   case   exe   partition   rom   copy   when   过程   

原文地址:http://www.cnblogs.com/waynelin/p/6079373.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!