日期:2014-05-16 浏览次数:20491 次
一、访问方式:
????? (1)命令行
??? ??(2)sqlplus客户端
????? (3)浏览器(http://127.0.0.1:5560/isqlplus/,如果不能访问,则isqlplusctl start)
二、用户解锁:
???? ?登录:sqlplus sys/密码 as sysdba;
????? 解锁:alert user scott account unlock;
三、sql语言:????
??? ? sql1992 structured query language 结构化查询语言
???? ?sql1999两套不同的语言
????? 机器(第一代语言),汇编(第二代语言),java c++(第三代语言)? sql语言(第四代语言,无条件,循环,分支)
四、scott中的表
???? emp(雇员信息): comm津贴? job工种? mgr经理人?
???? dept(部门信息)
???? salgrade(薪水等级信息):grade local hisal
五、select语句
????? 1、基本的sql语句
?????????
select *from emp; select ename,sal*12 from emp; dual表:只有一个字段 select 2*3 from dual:算出的只有一个结果 select sysdate from dual:系统日期 select ename, sal*12 anuual_sal from emp; //起别名,别名中有特殊字符,则加双引号,双引号保持住原有的格式 select enmae,comm from emp;好多人没有津贴,0和空值不一样。0是有值 select ename,sal*12+comm from emp;//算出有的是空值,任何含有空值的表达式结果都是空值 select ename||sal from emp; 相当于java中的字符串+ select ename||'asfasdfasdf' from emp; select ename|| 'asfasdfa''asdfasdf' from emp 正确语句 select distinct deptno from emp; select distinct deptno,job from emp; 这两个在一起的组合是重复的,就把它去掉
??? 2、带where的sql语句
??????????
select *from emp where deptno=10; select *from emp where ename='CLARK' select ename,sal from emp where sal>1500; select ename,sal,deptno from emp where deptno<>10;不等于 select ename,sal from emp where ename>'CBA' 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,comm from emp where comm is (not) null; select ename,sal comm from emp where sal in (800,1500,2000); select ename,sal,comm from emp where ename in ('smith','king','abc'); select ename,sal,hiredate from emp where hiredate>'20-2月-81'; select ename,sal from emp where deptno=10 and sal>1000; select ename,sal from emp where deptno=10 or sal>1000; select ename,sal from emp where sal not in (800,1500); select ename from emp where ename like '%ALL%'; %多个 select ename from emp where ename like '_A%'; _一个 select ename from emp where ename like '%\%%'; 转义字符 select ename from emp where ename like '%$%%' escape '$'; //$是转义字符 select *from dept;//见这个表的顺序 select *from dept order by deptno desc; select empno,ename from emp order by empno asc;不写默认按升序排列 select empno,enmae form emp where deptno<>10 order by empno asc; select ename,sal,deptno from emp order by deptno asc,ename desc; deptno相同的情况下排列ename select ename,sal*12 annal_sal form emp where ename not like '_A%' and sal>800 order by sal desc;
?? 3、sql函数
????????? 3.1单行函数
???????????
select lower(ename) from emp; select ename from emp where lower(emane) like '_a%' select ename from emp where ename like '_a%' or ename like '_A%'; select substring(ename,1,3) from emp select char(65) from dual;//acsci转换为字符 select asci('A') form dual; select round(23.652) from dual 24 select round(23.652,2) from dual 23.65 select round(23.652,-1) from dual 20 select to_char(sal,'$99,999.9999') from emp; //9代表一位数字,没有就不显示 select to_char(sal,'L99,999.9999') from emp; select to_char(sal,'$00,000.0000') from emp;没有就显示0 select to_char(hiredate,'YYYY-MM-DD HH:MI:SS') from emp; select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') from emp; select ename,hiredate from emp where hiredate>to_date('1981-2-20 12:34:56','YYYY-MM-DD HH24:MI:SS'); select sal from emp where sal>to_number('$1,250.00','$9,999.99'); select