1、假设student表如下:
create table student(stuid int,stuname varchar(10),sex char(2));
2、定一个插入数据的过程如下:
create or replace Procedure InserStudent(NewStudent in Student%Rowtype) as
iRec Integer;
Not_Exists_Student Exception;
Begin
Select count(*) into iRec from student where stuId=newstudent.stuID;
if iRec>0 then
Raise Not_Exists_Student;
else
Insert into Student values(newStudent.stuId,newStudent.stuName,newStudent.Sex);
commit;
end if;
Exception
When Not_Exists_Student then
DBMS_output.put_line('要插入的编号为'||newStudent.stuId||'已存在');
When others then
DBMS_output.put_line('查询过程中发生意外情况');
End InserStudent;3、问题:如何执行这个过程?我不知道参数部分怎么写,
exec insert_student(这里面应该填什么?);
create table student(stuid int,stuname varchar(10),sex char(2));
2、定一个插入数据的过程如下:
create or replace Procedure InserStudent(NewStudent in Student%Rowtype) as
iRec Integer;
Not_Exists_Student Exception;
Begin
Select count(*) into iRec from student where stuId=newstudent.stuID;
if iRec>0 then
Raise Not_Exists_Student;
else
Insert into Student values(newStudent.stuId,newStudent.stuName,newStudent.Sex);
commit;
end if;
Exception
When Not_Exists_Student then
DBMS_output.put_line('要插入的编号为'||newStudent.stuId||'已存在');
When others then
DBMS_output.put_line('查询过程中发生意外情况');
End InserStudent;3、问题:如何执行这个过程?我不知道参数部分怎么写,
exec insert_student(这里面应该填什么?);
解决方案 »
- 关于数据集拼凑组合的思路
- 各位高手,按照一定的数量,怎么将一行数据复制多行,oracle的树查询可以,但是得将每一行数据按照一定的数量复制为多行
- oracle中得函数索引怎么建立,在arcsde中能否建立函数索引
- 求个SQL语句
- 这段代码哪出错了
- 请教大家怎么才能在oracle里面来执行一个字符串表示的sql语句呢?
- help me 有关oracle8.03还原的问题,总是还原不正确。请高手指点
- 求助,创建数据库的顺序?100相送!
- 怎么样使用oracle中nubmer型的字段呀!
- oracle 11g 如何导入导出数据到 sqlserver 2008 R2?
- 各位大哥请帮我看下这个SQL语句出什么问题了?
- 请问绑定变量是不是必须已知SQL语句的结构?
2 begin
3 n_student.stuid := 55;
4 n_student.stuname := 'test';
5 n_student.sex := '1';
6 InserStudent(n_student);
7 end;
8 /PL/SQL procedure successfully completed
======〉
如果没有数据,则会跳到exception块,错误是NO_DATA_FOUND,执行when others then
实际上是不对的