SQL表达式类型错误

时间:2017-12-26 09:40:18

标签: sql plsql oracle-sqldeveloper plsqldeveloper

尝试在SQL开发人员上运行以下命令

declare
    type hType is table of number not null
        index by BINARY_INTEGER;
    items_v hType;
    references_v hType;
    keyId number;

begin   
    keyId := 1234567;

    select i.item bulk collect into items_v
    from items i
    where i.item_id = ...;

    select j.reference bulk collect into references_v
    from references j
    where j.reference = ..
        and j.item in items_v;
end;
  

我得到ORA-06550:第23行,第31栏:PLS-00382:表达式是   错误的类型

即使j.itemi.item也属于NUMBER类型,

2 个答案:

答案 0 :(得分:1)

在11g之前,您无法在TYPE范围内声明PLSQL并在PLSQL块中的SQL语句中使用它。如果要在TYPE块下使用SQL,则需要在PLSQL范围内声明IN。此外,当您想在MEMBER OF子句中使用一个集合时,可以使用SQL> CREATE OR REPLACE TYPE HTYPE IS TABLE OF NUMBER NOT NULL ; / Type created. 。见下文:

在SQL范围中创建的类型。

SQL> DECLARE   
  2       ITEMS_V                       HTYPE;
  3       REFERENCES_V                  HTYPE;
  4       KEYID                         NUMBER;
  5  BEGIN
  6       KEYID := 1234567;
  7  
  8       SELECT I.ITEM
  9       BULK COLLECT INTO ITEMS_V
 10         FROM ITEMS I
 11        WHERE I.ITEM_ID = 1;
 12  
 13       SELECT J.REFERENCE
 14       BULK COLLECT INTO REFERENCES_V
 15         FROM REFERENCES J
 16        WHERE J.REFERENCE = 1
 17        AND J.ITEM MEMBER OF ITEMS_V;--<--Used Member of to check elements of colection
 18  END;
 19  /

PL/SQL procedure successfully completed.

匿名阻止

IN

您可以使用use SQL> DECLARE 2 ITEMS_V HTYPE; 3 REFERENCES_V HTYPE; 4 KEYID NUMBER; 5 BEGIN 6 KEYID := 1234567; 7 8 SELECT I.ITEM 9 BULK COLLECT INTO ITEMS_V 10 FROM ITEMS I 11 WHERE I.ITEM_ID = 1; 12 13 SELECT J.REFERENCE 14 BULK COLLECT INTO REFERENCES_V 15 FROM REFERENCES J 16 WHERE J.REFERENCE = 1 17 AND J.ITEM IN (SELECT COLUMN_VALUE FROM TABLE(ITEMS_V)); --<-- Used IN Clause. 18 END; 19 / PL/SQL procedure successfully completed. 子句:

import dns.resolver
from multiprocessing.pool import ThreadPool as Pool
pool_size =4
pool = Pool(pool_size)
dnsResolver = dns.resolver.Resolver()
dnsResolver.timeout = 1
dnsResolver.lifetime = 1
dnsResolver.nameservers = ['172.31.0.2']

#domain_list = ['google.com','facebook.com', 'amazon.com']
#for domain in domain_list:
# Query results for the dig operations from a file that contains less than 1024 domains in it 

def fetch_dig_no_blast_results(no_blast_domains):
 try:
  no_blast_domains = no_blast_domains.strip()
  dnsAnswer = dnsResolver.query(no_blast_domains)
  for rdata in dnsAnswer:
   print (no_blast_domains, "resolved to",str(rdata))
 except dns.resolver.NXDOMAIN:
  print ("No records exists for", no_blast_domains)
 except dns.resolver.Timeout:
  print ("Timeout in querying",no_blast_domains)

with open("no-blast-domains.txt",'r') as fd1:
 for no_blast_domains in fd1:
  pool.apply_async(fetch_dig_no_blast_results, (no_blast_domains,))

pool.close()
pool.join()

答案 1 :(得分:0)

在查询的REFERENCES部分,您不能像这样使用ITEMS_V集合;考虑使用这样的东西:

for i in items_v.first .. items_v.last loop
  select j.reference bulk collect into references_v
    from references j
    where j.reference = ..
        and j.item_id = items_v(i);
end loop;

可能有一种更聪明的方法(希望其他人会告诉你如何),但这也应该有效。