sqlite 是否支持选择中的任何类型的 IF(condition) 语句 [英] Does sqlite support any kind of IF(condition) statement in a select

查看:22
本文介绍了sqlite 是否支持选择中的任何类型的 IF(condition) 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sqlite是否支持select语句中的sql函数if"?

Does sqlite support the sql function "if" in the select statement?

例如

select if( length( a ) > 4 , a , ' ') as b
from foo

如果长度超过 4 个字符,它将返回 a.否则它会返回 ' ' 作为 b

which would return a if the length was over 4 chars long. or else it would return ' ' as b

如果它确实支持 select 中的条件,应该使用什么语法?

If it does support a condition in the select what is the syntax is should be using?

我已经检查了 http://sqlite.org/lang_corefunc.html,但我看不到它.

I have checked http://sqlite.org/lang_corefunc.html but I can't see it.

推荐答案

查看案例 表达.

CASE 表达式的作用类似于其他编程语言中的 IF-THEN-ELSE.

A CASE expression serves a role similar to IF-THEN-ELSE in other programming languages.

以你为例

select case when length(a) > 4 then a else '' end as b
from foo

这篇关于sqlite 是否支持选择中的任何类型的 IF(condition) 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆