SQLite near “(“: syntax error causes and solutions

Try to execute the following SQL in SQLite and report an error: near "(": syntax error

select name,CASE 
WHEN LEFT(name,2)='美团' then '美团'  
WHEN LEFT(name,2)='京东' then '京东'  
WHEN LEFT(name,2)='淘宝' then '淘宝' 
WHEN LEFT(name,3)='拼多多' then '拼多多' 
WHEN LEFT(name,2)='超市' then '线下'  ELSE '其他' end  as platform from PayInfo_B

After verification, there is no problem with the grammar. The problem comes from the fact that Left is an internal function of SQL Server. SQLite does not support Left. After several debugging, it is found that left is a reserved word (LEFT JOIN) of SQLite. The function of left can be used in SQLite. substr function instead.

select name,CASE 
WHEN SUBSTR(name,1,2)='美团' then '美团'  
WHEN SUBSTR(name,1,2)='京东' then '京东'  
WHEN SUBSTR(name,1,2)='淘宝' then '淘宝' 
WHEN SUBSTR(name,1,3)='拼多多' then '拼多多' 
WHEN SUBSTR(name,1,2)='超市' then '线下'  ELSE '其他' end  as platform from PayInfo_B

or INSTR instead

select name,CASE 
WHEN INSTR(name,'美团')>0 then '美团'  
WHEN INSTR(name,'京东')>0 then '京东'  
WHEN INSTR(name,'淘宝')>0 then '淘宝' 
WHEN INSTR(name,'拼多多')>0 then '拼多多'
WHEN INSTR(name,'超市')>0 or INSTR(name,'购物')>0 then '线下'  ELSE '其他' end  as platform from PayInfo_B

Confirm that the syntax in SQLite is basically = Oracle syntax. For example, in SQL, you can use Select * into xxx from xxx to create a table and copy the table structure or data, but Oracle, SQLite, and mysql cannot, and you need to use Create table xxx as select xxx to complete the corresponding operation.

Guess you like

Origin blog.csdn.net/wh445306/article/details/130201660