Mysql 语法 "if length then" 语句

Mysql Syntax "if length then" statement

我对 mysql 的语法有疑问。 我有我的子选择:

(SELECT uniqueid AS uniqueid_idx, calldate, src, dst, dstchannel, billsec, 
 SUBSTR(CONVERT(IF(LENGTH(dst)>8,cdr.dst,CONCAT('67',cdr.dst)),UNSIGNED INTEGER),1,6) prefixo_normal 
FROM cdr)

你能看到吗:"if you have cdr.dst > 8 then concat.." 现在我要验证:"if cdr.dst have <5 then create virtual column name RAMAL"

我试过这个语法:IF(LENGTH(cdr.dst) <4, THEN cdr.dst AS ramal END

但不工作。

我该怎么做?

谢谢!

语法是:

SELECT uniqueid AS uniqueid_idx, calldate, src, dst, dstchannel, billsec, 
        SUBSTR(CONVERT(IF(LENGTH(dst)>8,cdr.dst,CONCAT('67',cdr.dst)),UNSIGNED INTEGER),1,6) prefixo_normal,
        IF(LENGTH(dst) < 4, dst, NULL) AS ramal
FROM cdr

使用IF函数时没有THENEND