2012-09-06 87 views
1

charcters我有這樣僅提取從字符串

lut00006300.txt 
sand2a0000300.raw 

我需要從上面給出的列值僅提取字符數據的列的值。我嘗試了下面的查詢,並能夠得到前三個字符。

select filesize, 
substring(Filename FROM 1 FOR 3) AS Instrument from Collection; 

是否有任何的方法來提取只留下擴展

的從列值字符的結果應該是:

LUT 
SAND2A 
+2

「* only characters *」是什麼意思? ''''''''','''''''''''''''''''''''''' ','r'和'w'都是角色! – eggyal

+0

我認爲*只有字母字符*。 – hims056

+0

@ hims056:所以結果應該是'luttxt'和'sandaraw'?對我來說似乎很奇怪。 – eggyal

回答

0

我想下面的查詢將幫助你。

select filesize,Filename from Collection where Filename REGEXP '[:alpha]'; 

參見: - http://dev.mysql.com/doc/refman/5.1/en/regexp.html

+0

thnks很多,但是當我激發上面給出的查詢我得到了輸出爲1 – user1633295

+0

@ user1633295看這個鏈接將幫助你http://stackoverflow.com/questions/1007697/how-to-strip-all-non-alphabetic-characters-from-string-in-sql-server –

0
SELECT 
filesize, 
UPPER(SUBSTRING_INDEX(SUBSTRING_INDEX(Filename, '.', 1), '0', 1)) AS Instrument 
FROM Collection; 

這是一個解決方案,因爲你想在SAND2A2

閱讀更多關於功能here