易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL select

--desc 表名 描述表的内容  
desc emp;
--加上数学表达式和列名  ""保持格式
select ename "name space", sal*12 year_sal from emp;   
select 2*3 from dual;
select sysdate from dual;
--空值的数学表达式 结果都是空值
select ename, sal*12 + comm from emp;  
--"||"字符串连接 单引号中的是字符串,字符串中的单引号,''表示
select ename||sal from emp;    
--distinct 修饰两个字段
select distinct deptno, job from emp;
select ename, sal from emp where sal between 800 and 1500;
select ename, sal from emp where sal >= 800 and sal <= 1500;
select ename, sal from emp where comm is null;
--一个事务开始于一条ddl语句,结束语rollback commit ddl数据定义语句 dcl数据控制语句语句
--正常断开连接 提交 非正常断开连接 回滚
select ename, sal from emp where sal not in (800 ,1500);
-- 模糊查询
select ename, sal from emp where ename like '_A%';
select ename, sal from emp where ename like '%\%%';
--转义字符
select ename, sal from emp where ename like '%$%%' escape '$';
--排序
select * from dept order by deptno desc;
select ename, sal from emp order by deptno asc, ename desc;
--函数
select lower(ename) from emp;
select substr(ename,1,3) from emp;
select round(23.652, 1) from dual;
select to_char(sal, '$99,999.999') from emp;
select to_char(sal, 'L000,000.000') from emp;
select to_char(hiredate, 'yyyy-mm-dd hh:mi:ss') from emp;
select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') from dual;
select ename, hiredate from emp
    where hiredate > to_date('1982-09-11 12:44:44', 'YYYY-MM-DD HH24:MI:SS');
select sal from emp where sal > to_number('$1,250.000', '$9,999.000');
select ename,sal*12 + nvl(comm, 0) from emp;
--组函数  多行输入,只有一行输出 select ename, max(sal) from emp; 结果不能保证只有一行
select max(sal) from emp;
select sum(sal) from emp;
select count(distinct deptno) from emp;
--分组函数
select deptno,avg(sal) from emp group by deptno;
select deptno, job, max(sal


相关文档:

ASP.NET防止SQL注入函数

ASP.NET防止SQL注入函数:
using System;
using System.Text.RegularExpressions;
using System.Web;
namespace FSqlKeyWord
......{
    /**//**//**//// <summary>
    /// SqlKey 的摘要说明。
    /// </summary>
    public class S ......

Access数据库字段类型说明以及与SQL之间的对照关系

文本 nvarchar(n)
备注 ntext
数字(长整型) int
数字(整型) smallint
数字(单精度) real
数字(双精度) float
数字(字节) tinyint
货币 money
日期 smalldatetime
布尔 bit
附:转换成SQL的脚本。
ALTER TABLE tb ALTER COLUMN aa Byte 数字[字节]
ALTER TABLE tb ALTER COLUMN aa Long 数字[长整型]
ALTER T ......

计算年资的SQL语句

1.bzscs(沙虫 我爱小美)用函數的好辦法:
CREATE    function [dbo].[calc_date](@time smalldatetime,@now smalldatetime)
returns nvarchar(10)
as
begin
declare @year int,@month int,@day int
select @year = datediff(yy,@time,@now)
if  (month(@now)=month(@time)) and (day ......

SQL分页查询

/*第几页必须大于1
select top 每页数量 * id
 from @t a
 where id not in
 (select top (第几页-1)*每页数量 id
  from @t b
 )
*/
declare @lcSqlCommand nvarchar(100)
declare @t table (id int IDENTITY,orderDate datetime)
insert into @t
 select orderDate
&nb ......

用SQL建立索引

  假设你想找书中的某一个句子。你可以一页一页地逐页搜索,但这会花很多时间。而通过使用索引,你可以很快地找到你要搜索的主题。
  表的索引与附在一本书后面的索引非常相似。它可以极大地提高查询的速度。对一个较大的表来说,通过加索引,一个通常要花费几个小时来完成的查询只要几分钟就可以完成。因此没有理由对 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号