PL/SQL错误过程、函数及解决方案笔记
2007-10-24 12:05
387 查看
PL/SQL错误过程、函数及解决方案笔记
1、創建一個過程,利用cursor將一個表中的兩個字段的內容,以循環的方式放到另外一個表中。
create or replace
procedure copy_data_into_newTable
as
declare
f_name
varchar(50);
l_name
varchar(50);
cursor
t_cursor is
select first_name,last_name
from students;
begin
open t_cursor;
loop
fetch t_cursor
into f_name,l_name;
exit when
t_cursor%notfound;
insert into
stu4 values(f_name,l_name);
exit loop;
close
t_cursor;
end copy_data_into_newTable;
解決方法:
錯誤很簡單,把loop的循環尾由exit
loop改為end loop問題解決。
2、創建一個過程,用以實現一個表的完全拷貝(包括結構及內容)
create or replace
procedure copy_table(
old_table varchar(50),
new_table varchar(50)
)
as
declare
--sql_copy_structure varchar(500);
--sql_copy_date varchar(200);
sql_copy
varchar(500);
begin
sql_copy:='create table '||new_table||'
as select * from '||old_table;
execute
immediate sql_copy;
end copy_table;
解決方法:
錯誤例舉:
1、參數只能申明類型,而不能夠申明大小
2、declare是匿名块使用的聲明,在過程和函數中不要用
3、表名不要聲明過大,oracle有規定,不能夠超30
更改后程序如下:
create or replace
procedure copy_table(
old_table varchar2,
new_table varchar
)
as
--sql_copy_structure varchar(500);
--sql_copy_date varchar(200);
sql_copy
varchar(100);
begin
sql_copy:='create table '||new_table||'
as select * from '||old_table;
execute
immediate sql_copy;
exception
--people using this procedure don't have the proviledge to run this procedure
when
others then
raise;
end copy_table;
3、觸發器觸發的時候出錯
這個觸發器的功能就是希望把當前插入的數據顯示出來。
表結構:
id first_name .....等
觸發器如下:
create or replace
trigger T
after insert on stu
for each row
declare
ID
int;
str_sql
varchar(100);
begin
ID:=:new.id;
str_sql:='select * from stu where id='||ID;
execute
immediate str_sql;
exception
when others
then
raise;
end T;
編譯通過。
可是當我stu表中插入數據的時候:
insert into stu
values(student_sequence.NEXTVAL,'Feng','Meteor','Technology',4,120);
報以我這樣的錯誤:
table HR.STU is mutating,trigger/function may not see it。
插入不成功。
請問是什么原因嗎?
謝謝解答!
4、存儲過程運行的時候出錯
編譯不出錯,可是運行出錯
create or replace
procedure FLB_2
as
cursor c1
is
select cno
from prd_flow_bak
group by cno;
thcur c1%rowtype;
sql1
varchar(100);
begin
--if not c1%isopen then
open
c1;
--end if;
loop
fetch c1
into thcur;
exit when
c1%notfound;
sql1:='select * from prd_flow_bak where cno='||thcur.cno;
--dbms_output.put_line(thcur.cno);
execute
immediate sql1;
exit;
end loop;
close
c1;
end FLB_2;
運行出錯
begin
FLB_2;
end;
出錯提示如下:
什么原因呢?
解決:
本文出自:冯立彬的博客
1、創建一個過程,利用cursor將一個表中的兩個字段的內容,以循環的方式放到另外一個表中。
create or replace
procedure copy_data_into_newTable
as
declare
f_name
varchar(50);
l_name
varchar(50);
cursor
t_cursor is
select first_name,last_name
from students;
begin
open t_cursor;
loop
fetch t_cursor
into f_name,l_name;
exit when
t_cursor%notfound;
insert into
stu4 values(f_name,l_name);
exit loop;
close
t_cursor;
end copy_data_into_newTable;
解決方法:
錯誤很簡單,把loop的循環尾由exit
loop改為end loop問題解決。
2、創建一個過程,用以實現一個表的完全拷貝(包括結構及內容)
create or replace
procedure copy_table(
old_table varchar(50),
new_table varchar(50)
)
as
declare
--sql_copy_structure varchar(500);
--sql_copy_date varchar(200);
sql_copy
varchar(500);
begin
sql_copy:='create table '||new_table||'
as select * from '||old_table;
execute
immediate sql_copy;
end copy_table;
解決方法:
錯誤例舉:
1、參數只能申明類型,而不能夠申明大小
2、declare是匿名块使用的聲明,在過程和函數中不要用
3、表名不要聲明過大,oracle有規定,不能夠超30
更改后程序如下:
create or replace
procedure copy_table(
old_table varchar2,
new_table varchar
)
as
--sql_copy_structure varchar(500);
--sql_copy_date varchar(200);
sql_copy
varchar(100);
begin
sql_copy:='create table '||new_table||'
as select * from '||old_table;
execute
immediate sql_copy;
exception
--people using this procedure don't have the proviledge to run this procedure
when
others then
raise;
end copy_table;
3、觸發器觸發的時候出錯
這個觸發器的功能就是希望把當前插入的數據顯示出來。
表結構:
id first_name .....等
觸發器如下:
create or replace
trigger T
after insert on stu
for each row
declare
ID
int;
str_sql
varchar(100);
begin
ID:=:new.id;
str_sql:='select * from stu where id='||ID;
execute
immediate str_sql;
exception
when others
then
raise;
end T;
編譯通過。
可是當我stu表中插入數據的時候:
insert into stu
values(student_sequence.NEXTVAL,'Feng','Meteor','Technology',4,120);
報以我這樣的錯誤:
table HR.STU is mutating,trigger/function may not see it。
插入不成功。
請問是什么原因嗎?
謝謝解答!
4、存儲過程運行的時候出錯
編譯不出錯,可是運行出錯
create or replace
procedure FLB_2
as
cursor c1
is
select cno
from prd_flow_bak
group by cno;
thcur c1%rowtype;
sql1
varchar(100);
begin
--if not c1%isopen then
open
c1;
--end if;
loop
fetch c1
into thcur;
exit when
c1%notfound;
sql1:='select * from prd_flow_bak where cno='||thcur.cno;
--dbms_output.put_line(thcur.cno);
execute
immediate sql1;
exit;
end loop;
close
c1;
end FLB_2;
運行出錯
begin
FLB_2;
end;
出錯提示如下:
什么原因呢?
解決:
本文出自:冯立彬的博客
相关文章推荐
- Oracle笔记:pl/sql过程、函数、包
- 【Oracle 】PL/SQL重用函数调用过程中PLS-307的错误
- 使用wrap和unwrap加密解密Oracle的PL/SQL对象(包,存储过程,函数等)代码
- Oracle学习笔记 -- day08 PL/SQL语法之存储过程、存储函数
- Oracle笔记 十一、PL/SQL函数和触发器
- ORACLE PL/SQL编程之六:把过程与函数说透(穷追猛打,把根儿都拔起!)
- ORACLE PL/SQL编程之六:把过程与函数说透
- ORACLE PL/SQL编程之六: 把过程与函数说透(穷追猛打,把根儿都拔起!)
- ORACLE PL/SQL编程之六:把过程与函数说透
- 关于PL/SQL中复杂的存储过程或者是函数等的查询==避免在PL/SQL当中写SQL语句查询存储过程或者是函数
- PL/SQL--存储过程与函数
- PL/SQL函数学习笔记:trim和to_char的应用
- pl/sql学习笔记之五 错误管理 error mgt
- Oracle数据库之PL/SQL过程与函数
- Oracle笔记 十一、PL/SQL函数和触发器
- 在PL/SQL 开发中调试存储过程和函数的一般性方法
- PL/SQL学习笔记之函数
- Oracle(20)pl/sql编程 过程、函数、包以及触发器概念
- PL/SQL --> 动态SQL调用包中函数或过程
- 【PL/SQL调试】SQL*Plus 或者 PL/SQL Developer查看存储过程编译错误