2017-05-05 58 views
-1

準備查詢我已用盡試圖通過任一陣列,其ref和其接合串在Oracle 11.2 IN子句的所有選項。我大多得到「無證轉換」或「錯誤可能接近< *>」所有指標誤差審判的案件。傳遞Perl數組到Oracle爲IN子句

什麼可能是一個數組傳遞到Oracle數據庫中一個準備語句的IN子句的最佳方法是什麼?

準備好的查詢是類似於:

$query = "select * from xyz join abc on xyz.t=abc.t where xyz.a IN ?"; 
$query_stmt = $dbh->prepare($query); 
$query_stmt->execute(ARRAY(0x11223344) ||(other tried option) 'string0,string1,...'); 

錯誤:

DBD::Oracle::st execute failed: ORA-01460: unimplemented or unreasonable conversion requested (DBD ERROR: OCIStmtExecute) [for Statement "select 
       distinct cast(vt.a as varchar2(30)) 
        as a, 
       trim(to_char(value)) as b 
      from xyz vt 
      join abc vtc on vt.c 
      = vtc.c join w offer 
       on vt.d = offer.d 
       and vt.is_valid = 'Y' 
      where vt.a IN (?)" with ParamValues: :p1=''6778168456141','6778179729141','6778200266141','6778203754141','6778208407141','6778224280141','6778224419141','6778236126141','6778249749141','6778256663141','6778260054141','6778276276141','6778285860141','6778317622141','32141','6778341014141','6778347921141','6778365313141','6778370737141','6778404039141','6778405686141','6778424024141','6778443116141','6778481089141','6778529277141','6778538345141','6778591334141','6778595317141','6778619981141','6778692874141','6778767142141','6778778071141','6778797829141','6778816085141','6778867467141','6778883297141','6778895665141','6778978652141','6778996314141','6779024581141','6779081179141','6779119698141','6779125079141','6779128574141','6779128584141','6779128649141','6779128662141','6779128724141','6779142735141','6779146125141','6779146399141','6779152708141','6779153278141','6779163438141','6779164599141','6779168905141','6779187230141','6779210491141','6779278671141','6779288166141','6779304879141','6779328703141','67...'] 

回答

5

除非Oracle數據庫驅動程序提供了一些其他的方式來做到這一點,我不知道,你需要爲每個元素使用單獨的佔位符:

$query = sprintf 'select * from xyz join abc on xyz.t=abc.t where xyz.a in (%s)', 
    join ',', ('?') x @array; 
$query_stmt = $dbh->prepare($query); 
$query_stmt->execute(@array); 
+0

我會試試這個。雖然,我之前嘗試過類似的東西,但沒有奏效。 –

+0

現在,他們都被設置爲「民主基金」的所有替代值[:p997 =民主基金,:p998 =民主基金,:P999 =民主基金] –

+5

更新您的實際代碼 – ysth