有一张表
VARCHAR UserName; //用户名 )、
NUMBER UserType; //类型 0普通用户 1是会员
需求:我有一个功能是(查询) 已知用户名,查询用户的类型Select case UserType where 0 then 普通用户 when 1 then 会员 end form 表 where UserName='用户名'(现在有个问题 如果随便写个用户名 查不出任何数据 那么这条查询语句没有结果的,如何进行空行的判断?)默认如果查询不到该用户的信息 我让UserType 为-1?
我发现使用: when UserType is null then -1 是无法得到数据的?该怎么写呢?表中只有2条数据:用户名为(张三,李四)
(如果实现如下的数据):
Select case UserType is null where -1 end form 表 where UserName='王二哥' --这条语句是错误的到底该怎么写呢?????????
VARCHAR UserName; //用户名 )、
NUMBER UserType; //类型 0普通用户 1是会员
需求:我有一个功能是(查询) 已知用户名,查询用户的类型Select case UserType where 0 then 普通用户 when 1 then 会员 end form 表 where UserName='用户名'(现在有个问题 如果随便写个用户名 查不出任何数据 那么这条查询语句没有结果的,如何进行空行的判断?)默认如果查询不到该用户的信息 我让UserType 为-1?
我发现使用: when UserType is null then -1 是无法得到数据的?该怎么写呢?表中只有2条数据:用户名为(张三,李四)
(如果实现如下的数据):
Select case UserType is null where -1 end form 表 where UserName='王二哥' --这条语句是错误的到底该怎么写呢?????????
form 表 where UserName='王二哥'
select case when v is not null then 'false' else 'true' end from (select 1 v from dual where 1=2)上面的语句根本不会返回false !!!怎么写能返回一个值呢?
select max(decode(UserType,null,UserName,王二哥) from tablename
select DCNAME,
case when type='0' then '普通用户'
when type='1' then '会员'
when type is null then '-1'
else 'False'
end
from
(
select '张三' as DCNAME,'0' as Type from dual
union all
select '李四','1' from dual
union all
select '王五','2' from dual
union all
select '赵钱',null from dual
)A
when 0 then 普通用户
when 1 then 会员
else -1 end
from 表
where UserName='用户名'
when 0 then 普通用户
when 1 then 会员
else -1 end
from 表
where UserName='用户名' 这里所填写的用户名在数据库根本不存在,所以运行后什么结果都没有 是个空的视图!我怎么让这个空的视图 默认返回一个 值呢?
select ???? from 表 where 1=2 怎么让这条语句 返回个-1 ????处到底怎么写 跪求啊
Microsoft Windows [版本 6.1.7600]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。C:\Users\Administrator>sqlplus test\passwordSQL*Plus: Release 10.2.0.1.0 - Production on 星期一 3月 19 13:30:32 2012Copyright (c) 1982, 2005, Oracle. All rights reserved.请输入用户名: test
输入口令:连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining optionsSQL> select nvl((select usertype from us where username = 'ls' ),-1) usertype fr
om dual; USERTYPE
----------
-1SQL>
14l正解,16l测试结果。ps:lz不做测试就说人家不行。
Microsoft Windows [版本 6.1.7600]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。C:\Users\Administrator>sqlplus test\passwordSQL*Plus: Release 10.2.0.1.0 - Production on 星期一 3月 19 13:30:32 2012Copyright (c) 1982, 2005, Oracle. All rights reserved.输入口令:连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining optionsSQL> select nvl((select usertype from us where username = 'ls' ),-1) usertype fr
om dual; USERTYPE
----------
-1
SQL> select * from us;USERNAME USERTYPE
---------- ----------
zs 1
zs 2SQL>