前言: 1.为什么要封装lambda表达式数据库查询,原因有一下几点: 1.1.在以往的开发中进行数据库表查询时,其实所需要的字段就是其中几个,但是在开发中,开发者往往习惯select * 进行查询,当数据多和用户量多时,查询的效率会降低. 1.2.在写查询where条件的时候,总是用string.format去拼接字符串,开发效率低. 1.3.代码不够优雅,代码中嵌套和多sql语句,如果是表字段发生改变时编译器检查不出来,代码出错的概率大. 1.4.本着 write less do more
表 table的结构如下: id title 1 12,21 2 21,32 3 45,21,78 4 221,45,74 5 34,421,121 6 52,21,321 现在用sql语句查出来字段里包含21的所有记录怎么办? select * from table where title=21 or title like ’%,21’ or title like ’%,21,%’ or title like ’21,%’ 这样查看看有问题吗? 肯定这样会把421 221 这样信息查出来的!
/*以下代码是对emp表/dept表/salgrade表进行显示宽度设置 */col empno for 9999;col ename for a10;col job for a10;col mgr for 9999;col hiredate for a12;col sal for 9999;col comm for 9999;col deptno for 99;col dname for a14;col loc for a14;col grade for 9999;col tname for
/*--以下代码是对emp表进行显示宽度设置col empno for 9999;col ename for a10;col job for a10;col mgr for 9999; col hiredate for a12;col sal for 9999;col comm for 9999;col deptno for 99;set pagesize 20; --创建新表new_emp,复制emp表中的结构和数据到new_emp表中create table xxx as select *