高分有關問題一枚

來源:互聯網
上載者:User
高分問題一枚
資料庫表中一個來電欄位caller
caller有普通的手機號,也有帶0的手機號,還有010-1234567這樣的有線電話號碼等等
請問如何去掉那些前面帶0的手機號?
求高效實現

------解決方案--------------------
手機號和有線電話號有如下區別

長度
號碼內是否存在"-"

區別出手機號 過濾首位 為0的手機號碼

是這樣吧?正則咯...


------解決方案--------------------
select ... where left(caller,1)!='0';
------解決方案--------------------
有線電話號加區號是11位把。手機號還有前置0的話就大於11位了。根據這個規則來替換。
------解決方案--------------------
SQL code
SELECT * FROM `tbl` WHERE `calller` REGEXP '^01[3458]+';
------解決方案--------------------
手機號碼前段沒幾個,可以根據這個來判斷

PHP code
$tel = << $val){    if($val[0] == '0' && in_array("$val[1]$val[2]", $tel_arr))        $tel[$key][0] = '';}print_r($tel);
------解決方案--------------------
手機號都是 1 打頭
只要排除掉 010 北京區號就可以了

$caller = preg_replace('/^0(1[^0])/', '$1', $caller);
------解決方案--------------------
探討
如果要在資料庫裡直接把手機號碼前面的0去掉可以這樣做

SQL code


update `user`
set `tel`= substring(tel,2,length(tel))
where
length(`tel`)=12


如果只是想在查詢出來的結果裡把0去掉 可以這樣

SQL code


select
case when length(tel……

------解決方案--------------------
直接 mysql 操作
SQL code
update tbl_name set caller=substr(caller,2) where caller regexp '^01[^0]'
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.