2017-03-15 31 views
0

第四屆角色,我需要我的查詢過濾器只到第4字符的字符串「H」如:CM1H8A6搜索在Oracle

我試圖​​但它不允許非數值。

ORA-01722: invalid number 
01722. 00000 - "invalid number" 
*Cause:  
*Action: 

感謝, 阿魯娜

+4

看起來像是在追蹤substr。如果我已經正確地理解了你的需求,那麼你是在類似於:'where substr(m_reference,4,1)='H'' – Boneist

+0

非常感謝。這樣可行!!! –

回答

1

INSTR函數查找某個字符串在另一字符串。

INSTR(string , substring [, position [, occurrence]]) 

這就是爲什麼當你1把它作爲第二個參數,你得到這個ORA-01722: invalid number

如果你正在尋找一個字符串中的特定位置,使用SUBSTR

SUBSTR(string, position [, substring_length]) 

對於你這是

SUBSTR(m_reference, 4, 1) -- gives you the 4th char in m_reference 
1

對於它的樂趣,解決使用REGEXP_LIKE(3任何字符後跟大寫字母「H」的情況):

SQL> with tbl(m_reference) as (
     select 'CM1H8A6' from dual 
    ) 
    select m_reference 
    from tbl 
    where regexp_like(m_reference, '.{3}H'); 

M_REFER 
------- 
CM1H8A6 

SQL>