寫PL/SQL程序時碰到的一些問題
2024-07-21 02:05:59
供稿:網友
 
國內最大的酷站演示中心!
記的上次寫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