create table stuInfo(stuNO char(6) not null,stuName varchar2(20) not null,stuAge number(3,0) not null ,stuID number(18,0), stuSeat number(2,0))
INSERT INTO “SCOTT”.”STUINFO” (STUNO, STUNAME, STUAGE, STUSEAT) VALUES (‘1’, ‘张三’, ‘18’, ‘1’)
INSERT INTO “SCOTT”.”STUINFO” (STUNO, STUNAME, STUAGE, STUSEAT) VALUES (‘2’, ‘李四’, ‘20’, ‘2’)
INSERT INTO “SCOTT”.”STUINFO” (STUNO, STUNAME, STUAGE, STUSEAT) VALUES (‘3’, ‘王五’, ‘15’, ‘3’)
INSERT INTO “SCOTT”.”STUINFO” (STUNO, STUNAME, STUAGE, STUSEAT) VALUES (‘4’, ‘张三’, ‘18’, ‘4’)
INSERT INTO “SCOTT”.”STUINFO” (STUNO, STUNAME, STUAGE, STUSEAT) VALUES (‘5’, ‘张三’, ‘20’, ‘5’)
select distinct stuName,stuAge from stuINfo
select stuNo,stuName,stuAge from stuinfo where stuage > 17 order by stuname asc, stuage desc
select stuname as “姓名” , stuage as “年 龄”,stuid as 身份证号 from stuinfo
create table newStuInfo1 as > select * from stuinfo
create table newStuInfo2 as > select stuage from stuinfo
create table newStuInfo3 as > select * from stuinfo where 1 > 2
select count(*) from stuinfo ###效率低
select count(1) from stuinfo ###效率高
select stuName,stuAge from stuinfo group by stuName,stuAge having(count(stuName || stuAge) < 2)
delete from stuinfo
where rowId Not in(
select Max(rowid) from stuinfo GROUP by stuname, stuage having (count(stuage || stuname) > 1)
union
select max(rowid) from stuinfo GROUP by stuname,stuage having (count(stuAge || stuname) = 1)
)
select table_name from user_all_tables a where a.num_rows > 1000000
create table dept(
deptno number(2) primary key, ###部门编号
dname varchar2(14), ###部门名称
loc varchar2(13) ###地址
);
INSERT into dept values(50,’a’,null);
INSERT into dept values(60,’b’,null);
savepoint a; ###设置保存点
INSERT into dept values(70,’c’,null);
ROLLBACK to SAVEPOINT a; ### 回滚至 a 保存点
select * from dept
rollback; ###没有50,60号部门
select * from dept;
create table employee(
empmp number(4) not null, ###员工编号
ename varchar(10), ###员工姓名
job varchar2(9), ###员工工种
mgr number(4), ###上机经理编号
hredate date, ###受雇日期
sal number(7,2), ###受雇薪水
comm number(7,2), ###福利
depton number(2) ###部门编号
)
INSERT into employee > select * from scott.emp
alter table employee add constraint FK_depton FOREIGN KEY(DEPTON) REFERENCES dept(DEPTNO)
alter table employee add(empTel_no varchar2(12) , empAddress varchar2(20));
select * from employee
alter table employee drop column emptel_no
alter table employee drop column empAddress
select * from employee order by sal desc
select * from (> select e.,rownum rn from (> select from employee order by sal) e ) where rn >= 5 and rn < 10
select empno from employee
UNION
select empno from Emp
select empno from employee
UNION
select empno from emp
order by empno
select empno FROM employee
intersect
select empno from emp
select empno from employee
minus
select empno from emp
select job||’_’||ename from employee
select job from employee
select ename from employee
select to_char (sysdate,’YYYY”年”fmMM”月”fmDD”日” HH24:MI:SS’) from dual
select to_char(1210.7,’$9,999,00’) from dual
select to_Date(‘2013-02-13’,’YYYY-MM-DD’) from dual
select sqrt(to_number(‘100’)) from dual
select ename,
sal+NVL(comm,0) sall,
nvl2(comm,sal+comm,sal) sal2,
decode(to_char(hiredate,’MM’),’01’,’一月’,’02’,’二月’,’03’,’三月’,’04’,’四月’,’05’,’五月’,’06’,’六月’,’下半年’) mon from employee
select ename,deptno,sal,
rank() over(partition by deptno order by sal desc) “rank”,
dense_rank() over(partition by deptno order by sal desc) “dense_rank”,
row_number() over(partition by deptno order by sal desc) “row_number”
from employee