欢迎光临
我们一直在努力

写PL/SQL程序时碰到的一些问题-数据库专栏,SQL Server

建站超值云服务器,限时71元/月

记的上次写pl/sql程序还是刚毕业不久,还用的是oracle 7 for novell
后来只是偶尔用一下oralce, pl/sql的一些语法已经全忘了,
这不,碰到好些低级的问题,谨记下,希望不会再忘记。

1.有for update类型的cursor
定义cursor时,加了for update,因为需要打开cursor后还要对这些数据进行修改和删除,
但在修改和删除数据后在关闭cursor前就commit,就出现了下面的错误:
ora-01002: 读取违反顺序
ora-06512: 在”jwgl.pckgstudsltcourse”, line 62
ora-06512: 在line 2

error: ora-06550: 第 2 行, 第 0 列:
pls-00103: 出现符号 “end-of-file”在需要下列之一时:
begin case declare
exit for goto if loop mod null pragma raise return select
update while with 《an identifier》
《a double-quoted delimited-identifier》 《a bind variable》
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge
《a single-quoted sql string》 pipe

刚开始还以为是因为我嵌套select子句,而不能加for update。
后来才发现是因我在修改删除了数据马上commit后,又马上从cursor中fetch数据。
其实在打开有for update的cursor时,系统会给取出的数据加上排他锁(exclusive),
这样在这个锁释放前其他用户不能对这些记录作update、delete和加锁。
而我一旦执行了commit,锁就释放了,游标也变成无效的,再去fetch数据时就出现错误了。
因而要把commit放在循环外,等到所有数据处理完成后再commit,然后关闭cursor.

2.如何在一个对象类型的方法中对该对象的属性进行赋值
在一般情况下,调用一个对象的方法时,对象自己self是以in类型的参数传进去的,因此不能
对对象的属性进行修改否则会出现下面的错误。

error: pls-00363: 表达式 self 不能用作赋值目标
line: 26
text: setroundno(vsltcoursecalendar.getroundno());

error: pl/sql: statement ignored
line: 26
text: setroundno(vsltcoursecalendar.getroundno());
trying to compile an object in oracle 9i.
why is this throwing an exception?
does anyone have a clue? or all of you as puzzled as me? any experts?

throws error:
pls-00363: expression self.attrib_number cannot be used as an assignment target

但可以通过把self以in out方式传进去,然后在方法内就能对对象属性进行赋值了。
member function test_function(self in out test_object) return number

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 写PL/SQL程序时碰到的一些问题-数据库专栏,SQL Server
分享到: 更多 (0)

相关推荐

  • 暂无文章