Oracle 中 decode使用详解 及在MySQL中如何实现
DECODE(value,if1,then1,if2,then2,if3,then3,...,else)oracle中准备数据
create table Test_decode (id int, tname varchar2(20));
insert into test_decode(id,tname) values(1,'oracle');
insert into test_decode(id,tname) values(2,'mysql');
insert into test_decode(id,tname) values(3,'sqlserver');
select * from Test_decode;
mysql中准备数据
create table test_decode (id int, tname varchar(20));
insert into test_decode(id,tname) values(1,'oracle');
insert into test_decode(id,tname) values(2,'mysql');
insert into test_decode(id,tname) values(3,'sqlserver');
select * from test_decode;
Oracle 语句
select tname, decode(tname,'oracle','this is oracle','mysql','this is mysql','other database') dbname
from Test_decode;
mysql 语句
select tname, case tname
when 'oracle' then 'this is oracle'
when 'mysql' then 'this is mysql'
else 'other database'
end dbname
from Test_decode;
本文来自投稿,不代表本人立场,如若转载,请注明出处:http://www.souzhinan.com/kj/284226.html