+ -
当前位置:首页 → 问答吧 → 这个语法用oracle怎么写

这个语法用oracle怎么写

时间:2011-09-08

来源:互联网

if ('wang' like '%赵栋%')
begin
print 'a'
end
else
begin
print 'b'
end 


这是一段msSQL的代码,oracle怎么写? 主要是判断一个变量中是否有特定值(这个是重点,如果要用到函数,帮忙把函数写一下,写具体点,因为查了很多资料都没有解决)
如果有执行有条件查询,没有 执行有条件查询(这个不是重点)

作者: a496393868   发布时间: 2011-09-08

case when 即可.

select case when 'wang' like '%赵栋%' then 'a' else 'b' end from dual;

作者: dawugui   发布时间: 2011-09-08

decode

作者: langxingcs   发布时间: 2011-09-08

提示无效字符串
引用 1 楼 dawugui 的回复:

case when 即可.

select case when 'wang' like '%赵栋%' then 'a' else 'b' end from dual;

作者: a496393868   发布时间: 2011-09-08

SQL code

if (instr('wang', '赵栋') > 0) then
    dbms_output.put_line('a');
else
    dbms_output.put_line('b');
end if;




作者: opps_zhou   发布时间: 2011-09-08

也是无效SQL语句,这东西应该在哪个窗口执行,SQL window 还是 Text Window,为什么我老报这个错误,我哪个打印 a,b 的以后是放sql语句的
引用 4 楼 opps_zhou 的回复:

SQL code

if (instr('wang', '赵栋') > 0) then
dbms_output.put_line('a');
else
dbms_output.put_line('b');
end if;

作者: a496393868   发布时间: 2011-09-08

select case when 'wang' like '%赵栋%' then 'a' else 'b' end from dual;
这个在SQL WINDOW执行不了?

作者: lnuwhy   发布时间: 2011-09-08

SQL code
SQL> with TAB as(
  2  select '赵栋' WANG from dual
  3  union all
  4  select '张三' WANG from dual
  5  union all
  6  select '李四' WANG from dual
  7  union all
  8  select '赵栋' WANG from dual)
  9  select case when WANG = '赵栋' then 'A' else 'B' end from TAB;
 
CASEWHENWANG='赵栋'THEN'A'ELSE
------------------------------
A
B
B
A
 
SQL> 

作者: xl_smlie   发布时间: 2011-09-08

引用 1 楼 dawugui 的回复:
case when 即可.

select case when 'wang' like '%赵栋%' then 'a' else 'b' end from dual;


这个在SQL WINDOW中测试通过,没有问题,楼主再试试

作者: rihyou   发布时间: 2011-09-08

引用 6 楼 lnuwhy 的回复:

select case when 'wang' like '%赵栋%' then 'a' else 'b' end from dual;
这个在SQL WINDOW执行不了?
没问题的。

作者: xl_smlie   发布时间: 2011-09-08

SQL code
SQL> with TAB as(
  2  select '赵栋' WANG from dual
  3  union all
  4  select '张三' WANG from dual
  5  union all
  6  select '李四' WANG from dual
  7  union all
  8  select '赵栋' WANG from dual)
  9  select case when WANG like '%赵栋%' then 'A' else 'B' end from TAB;
 
CASEWHENWANGLIKE'%赵栋%'THEN'A
------------------------------
A
B
B
A
 
SQL> 

--------WANG 加引号'WANG'
SQL> with TAB as(
  2  select '赵栋' WANG from dual
  3  union all
  4  select '张三' WANG from dual
  5  union all
  6  select '李四' WANG from dual
  7  union all
  8  select '赵栋' WANG from dual)
  9  select case when 'WANG' like '%赵栋%' then 'A' else 'B' end from TAB;
 
CASEWHEN'WANG'LIKE'%赵栋%'THEN
------------------------------
B
B
B
B
 
SQL> 

作者: xl_smlie   发布时间: 2011-09-08

SQL code

SQL> with TAB as(
  2  select '赵栋' WANG from dual
  3  union all
  4  select '张三' WANG from dual
  5  union all
  6  select '李四' WANG from dual
  7  union all
  8  select '赵栋' WANG from dual)
  9  select case when WANG like '%赵栋%' then 'A' else 'B' end from TAB;
 
CASEWHENWANGLIKE'%赵栋%'THEN'A
------------------------------
A
B
B
A
 
SQL> 
--WANG 加引号'WANG'
SQL> with TAB as(
  2  select '赵栋' WANG from dual
  3  union all
  4  select '张三' WANG from dual
  5  union all
  6  select '李四' WANG from dual
  7  union all
  8  select '赵栋' WANG from dual)
  9  select case when 'WANG' like '%赵栋%' then 'A' else 'B' end from TAB;
 
CASEWHEN'WANG'LIKE'%赵栋%'THEN
------------------------------
B
B
B
B
 
SQL> 

作者: xl_smlie   发布时间: 2011-09-08

热门下载

更多