日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

oracle不使用游标,oracle – 为什么我们不能在动态SQL语句中使用强引用游标?

發(fā)布時(shí)間:2024/9/30 数据库 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle不使用游标,oracle – 为什么我们不能在动态SQL语句中使用强引用游标? 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

這是一個(gè)帶有強(qiáng)類型引用游標(biāo)的過(guò)程:

SQL> create or replace procedure p1 is

2 type dept_rc is ref cursor return dept%rowtype;

3 my_ref_cursor dept_rc;

4 begin

5 open my_ref_cursor for

6 select * from dept;

7 end;

8 /

Procedure created.

SQL>

下一個(gè)語(yǔ)句失敗,因?yàn)镋MP記錄的簽名與DEPT表的簽名不匹配.

SQL> create or replace procedure p1 is

2 type dept_rc is ref cursor return dept%rowtype;

3 my_ref_cursor dept_rc;

4 begin

5 open my_ref_cursor for

6 select * from emp;

7 end;

8 /

Warning: Procedure created with compilation errors.

SQL> show error

Errors for PROCEDURE P1:

LINE/COL ERROR

-------- -----------------------------------------------------------------

5/5 PL/SQL: SQL Statement ignored

6/9 PLS-00382: expression is of wrong type

SQL>

但是如果我們改變投影以匹配DEPT表,那么我們?cè)俅潍@得成功:

SQL> create or replace procedure p1 is

2 type dept_rc is ref cursor return dept%rowtype;

3 my_ref_cursor dept_rc;

4 begin

5 open my_ref_cursor for

6 select deptno, ename, job from emp;

7 end;

8 /

Procedure created.

SQL>

那么,為什么我們不能使用帶有動(dòng)態(tài)SQL的強(qiáng)類型引用游標(biāo)?

SQL> create or replace procedure p1 is

2 type dept_rc is ref cursor return dept%rowtype;

3 my_ref_cursor dept_rc;

4 begin

5 open my_ref_cursor for

6 'select * from dept';

7 end;

8 /

Warning: Procedure created with compilation errors.

SQL> show error

Errors for PROCEDURE P1:

LINE/COL ERROR

-------- -----------------------------------------------------------------

5/5 PL/SQL: Statement ignored

5/10 PLS-00455: cursor 'MY_REF_CURSOR' cannot be used in dynamic SQL

OPEN statement

SQL>

因?yàn)榫幾g器無(wú)法解析動(dòng)態(tài)SQL語(yǔ)句中的字符串.因此,它無(wú)法斷言查詢投影中的列與數(shù)字和數(shù)據(jù)類型匹配ref游標(biāo)的簽名.因此,它無(wú)法驗(yàn)證ref游標(biāo)變量和查詢之間的契約.當(dāng)我們考慮可以從USER_TAB_COLUMNS上的查詢匯編動(dòng)態(tài)SQL語(yǔ)句時(shí),更容易理解為什么不允許這樣做.

總結(jié)

以上是生活随笔為你收集整理的oracle不使用游标,oracle – 为什么我们不能在动态SQL语句中使用强引用游标?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。