时间:2023-10-31来源:系统城装机大师作者:佚名
1.首先创建两个表emp,emp_bonus如下:
(1)emp_bonus:
>
(2)emp:

2.首先对emp_bonus表进行操作:
| 1 2 3 |
select emp_bonus.*,(case when empno=7934 then 0 when empno=7839 then 1 else -1 end) as asd from emp_bonus |
效果:

可见case when then 的作用或者效果是根据条件重新添加了一列!其实这一列可以的多表关联中进行其他有效的操作。
3.如,员工的奖金根据emp_bonus中的type来计算,type=1则工资的10%作为奖金,type=2则工资的20%作为奖金,以此类推……现在要求返回10号部门的员工工资及奖金:
| 1 2 3 4 5 |
select e.deptno,e.deptno,e.ename,e.sal, (e.sal*case when eb.type=1 then 0.1 when eb.type=2 then 0.2 when eb.type=3 then 0.3 end) as bonus from emp e inner join emp_bonus eb on(e.empno=eb.empno) and e.deptno=10 |

可见,两表关联后的bonus列进行了操作……
配合前端框架,前后台查出来的数据是经常配合的,比如一个党员信息列表,针对性别字段,后台查出来的是0或者1代表男和女,一种方式是前台针对0,1进行文字转换,像easyui和layui等都提供相应的js写法。
easyui 在datagrid 的columns:数组里面使用formatter函数实现。
| 1 2 3 4 5 6 7 8 9 10 |
{width : '5%',title : '性别',field : 'sex',sortable : true,formatter:function(value,row,index){ switch (value) { case '1': return '<font >男</font>'; break; default: return '<font >女</font>'; break; } }}, |
在layui里可以使用layui模板语法实现。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
window.demoTable = table.render({ elem : '#idTest', id : 'idTest', url : '<%=path%>/partyMember/getPartyMembersByOrgCode', width : 1500, height : 650, cols : [ [ //标题栏 {checkbox : true,LAY_CHECKED : false,filter : 'test'}, {field : 'PM_CODE',title : '党员编号',width : 220,sort : true,align : 'center'}, {field : 'NAME',title : '党员姓名',width : 120,sort : true,align : 'center'}, {field : 'SEX',title : '性别',width : 80,sort : true,align : 'center',templet:'#sexTpl'}, {field : 'MOBILE_NO',title : '手机号码',width : 220,sort : true,align : 'center'}, {field : 'CODE',title : '组织编码',width : 220,sort : true,align : 'center'}, {field : 'ORG_NAME',title : '所在支部',width : 200,sort : true,align : 'center'}, {fixed : 'right',title : '操作',width : 200,align : 'center',toolbar : '#barDemo'} ] ], page : true //是否显示分页 , limits : [ 15, 20,50, 100 ], limit : 15 //每页默认显示的数量 });<script type="text/html" id="sexTpl">{{# if(d.SEX ==0){ }} 女{{# } else { }} 男{{# } }}</script> |
第二种方法:直接数据库里返回文字信息。
在这种情况下遇到了case when 语句别名的问题,在此博客记录下,希望各位也留意。
刚开始写的语句
| 1 | select name,case sex when '0' then '男' else '女' end as '性别' from t_member_base where mobile_tel='13707979894' |
报如下错误:
ORA-00923: 未找到要求的 FROM 关键字
00923. 00000 - "FROM keyword not found where expected"
*Cause:
*Action:
行 1 列 60 出错
查了相关资料才知道,oracle case when 取别名是不能带as的,去掉as即可。

而且性别还不能带单引号,一般程序里都是取英文,如果是汉子,还不能带单引号,直接汉子即可,说明下。
2023-10-31
Oracle如何编写一个sqlldr实例2023-10-31
Oracle的SQLLDR用法简介2023-10-31
Oracle中的高效SQL编写PARALLEL解析1.Oracle数据库系统结构概述 2.Oracle数据库存储结构 物理存储结构 控制文件 数据文件 重做日志文件 归档日志文件 Oracle数据库逻辑结构 数据块(Data Block) (盘)区(Extent) 段(Segment) 表空间(Tablespace) 本地管...
2023-10-31
windows下的Oracle19c 一、官网下载Oracle19c数据库 二、安装Oracle数据库 1.解压安装包 2.运行setup.exe安装 三、配置 四、安装完Oracle数据库,给scott用户解锁 1.解决Oracle数据库中没有scott账户的问题 2.给scott...
2023-10-31