2016-06-19 8 views
0

私は、節でそれを使用するために、最初の引用符と最後の引用符を削除する必要があるクエリがあります。私は次のクエリ::oracle translate関数が数値に変換するエラーを出しています

with t as (
    select '1,2,3' x from dual) 
select translate(x, ' '||chr(39)||chr(34), ' ') from t 

を実行すると、それは結果> 1,2,3

を与えるしかし、私は次のクエリ::

select * from care_topic_templates where care_topic_id in (
with t as (
     select '1,2,3' x from dual) 
    select translate(x, ' '||chr(39)||chr(34), ' ') from t 
); 

を実行すると、このエラーが発生します>ORA-01722: invalid number

答えて

2

整数id'1,2,3'のような文字列と比較しているため、translate()を使用して奇妙な置換を行った後でも、この文字列を整数に変換することはできません。文字列はリストではありません。

はあなたがlikeと相関サブクエリを使用してやりたいことができます。

select * 
from care_topic_templates 
where exists (select 1 
       from (select '1,2,3' as x from dual) x 
       where ',' || x || ',' like '%,' || care_topic_id || ',%' 
      ); 

それとも、あなたのケースで:

select * 
from care_topic_templates 
where exists (select 1 
       from (select '1,2,3' as x from dual) x 
       where ',' || translate(x, ' '||chr(39)||chr(34), ' ') || ',' like '%,' || care_topic_id || ',%' 
      ); 

これは、クエリのロジック以下の通りです。このロジックを表現する他の方法があります。

+0

ありがとうございました。これは大きな助けです。 –

+0

あなたは同じ結果のために何をするべきかを示唆することができますが、単一の –

+0

@SumonBappiの代わりに二重引用符を使用してください。 。 。別の質問をする必要があります。 –

関連する問題