我已經修改了你的程序輕微,因爲WHERE子句您發佈沒有任何意義,我...
SQL> create or replace procedure all_customer_postcode
2 (pPostcode in customer.postcode%type
3 ,pReport out SYS_REFCURSOR) is
4 begin
5 open pReport for
6 select c.id
7 , c.forename
8 , c.surname
9 ,c.address_1
10 ,c.address_2
11 ,c.postcode
12 , c.date_of_birth
13 , cf.id as cf_id
14 from customer c
15 , customer_friend cf
16 ,customer_friend_for cff
17 where c.id = cff.customer_id
18 AND cf.id = cff.customer_friend_id
19 AND c.postcode = pPostcode;
20 end;
21/
Procedure created.
SQL>
在SQL調用它* Plus中用於變量...
SQL> var rc refcursor
SQL> var pc varchar2(8)
SQL> exec :pc := 'ML1 4KJ'
PL/SQL procedure successfully completed.
SQL> exec all_customer_postcode(:pc, :rc)
PL/SQL procedure successfully completed.
SQL> print rc
ID FORENAME SURNAME ADDRESS_1 ADDRESS_2 POSTCODE DATE_OF_B CF_ID
---------- ---------- ---------- -------------------- -------------------- -------- --------- ----------
1 Joe Chip 1234 Telepath Drive Milton Lumpky ML1 4KJ 01-FEB-90 11
4 Ray Hollis 777 Telepath Drive Milton Lumpky ML1 4KJ 01-SEP-81 44
5 Pat Conley 1235 Telepath Drive Milton Lumpky ML1 4KJ 01-OCT-91 55
SQL>
那麼,我們該如何才能把它拋出ORA-1008呢?通過轉動查詢到一個字符串和更改參數聲明的方式......
SQL> create or replace procedure all_customer_postcode
2 (pPostcode in customer.postcode%type
3 ,pReport out SYS_REFCURSOR) is
4 begin
5 open pReport for
6 'select c.id
7 , c.forename
8 , c.surname
9 ,c.address_1
10 ,c.address_2
11 ,c.postcode
12 , c.date_of_birth
13 , cf.id as cf_id
14 from customer c
15 , customer_friend cf
16 ,customer_friend_for cff
17 where c.id = cff.customer_id
18 AND cf.id = cff.customer_friend_id
19 AND c.postcode = :pPostcode';
20 end;
21/
Procedure created.
SQL> exec all_customer_postcode(:pc, :rc)
BEGIN all_customer_postcode(:pc, :rc); END;
*
ERROR at line 1:
ORA-01008: not all variables bound
ORA-06512: at "APC.ALL_CUSTOMER_POSTCODE", line 5
ORA-06512: at line 1
SQL>
讓我們解決是 ...
SQL> create or replace procedure all_customer_postcode
2 (pPostcode in customer.postcode%type
3 ,pReport out SYS_REFCURSOR) is
4 begin
5 open pReport for
6 'select c.id
7 , c.forename
8 , c.surname
9 ,c.address_1
10 ,c.address_2
11 ,c.postcode
12 , c.date_of_birth
13 , cf.id as cf_id
14 from customer c
15 , customer_friend cf
16 ,customer_friend_for cff
17 where c.id = cff.customer_id
18 AND cf.id = cff.customer_friend_id
19 AND c.postcode = :pPostcode' using pPostcode;
20 end;
21/
Procedure created.
SQL> exec all_customer_postcode(:pc, :rc)
PL/SQL procedure successfully completed.
SQL>
所以我已成功地重新創建ORA- 1008;我不確定它是否符合你的ORA-1008情況。你的直覺是正確的,它是與如何pPostcode
值傳遞給查詢。只是你發佈的代碼實際上是正確的,所以不會失敗。
你是如何調用這個程序?因爲發佈的代碼沒有明顯的問題。 – APC 2010-02-01 12:10:16
耶程序被調用,洙會建議它的這個過程外的財產以後?爲應對 – user250643 2010-02-01 12:22:55