您的位置:首页 > 数据库 > Oracle

【Oracle 学习笔记】Day 1 常用函数整理(转换、DeCode),表的外键

2012-04-25 17:56 706 查看
select Convert(varchar,Convert(money,TaxExValue),1) from A

--Result
2,794.87
58,119.66
1,367.52


对于SQL Server来说,进行金额的转换,可以按照上面的操作那样,会自动将金额处理为两位小数,并用逗号分隔小数点前面的数字。

当然可以用字符串拼接的方式,将金额符号加上去。

对于项目中,客户需要将金额转换的时候,这样处理显示出来的效果会好一些。

一下是用ORACLE的显示结果。

Select to_char(hisal,'L9,999') as Value from SALGRADE

--result
¥1,200
¥1,400
¥2,000
¥3,000
¥9,999


--Decode()函数

//SQL Server 下,用case 实现

select case '2' when '1' then '内容1' when '2' then '内容2' when '3' then '内容3' End
Union all
select case '4' when '1' then '内容1' when '2' then '内容2' when '3' then '内容3' End

--Result

内容2
NULL


//Oracle 下,Decode和Case都可以

select Decode('2','1','内容1','2','内容2','3','内容3') from dual
Union all
select case '2' when '1' then '内容1' when '2' then '内容2' when '3' then '内容3' End from dual
Union all
select Decode('4','1','内容1','2','内容2','3','内容3') from dual
Union all
select case '4' when '1' then '内容1' when '2' then '内容2' when '3' then '内容3' End from dual;

--Result
内容2
内容2


Oracle后面两个SQL执行出来的结果不是NULL而是''

外键约束。

删除时同时删除子表数据

View Code

delete from Materials where MaterialID='0001'

select * from Materialcomlinks
--Reuslt
01    0002    库存计量单位2    采购计量单位2
02    0002    库存计量单位3    采购计量单位3
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: