2.Orcal中的SQL语句
1.插入语句:
① insert into dept(deptno,dname,loc)values(50,'销售部','北京');
②调用系统时间(sysdate):
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values(7196,'小山','部门经理',7782,sysdate,2000,null,10);
查看结果:select * from emp where empno=7196;
③插入指定时间值:
insert into emp values(2296,'xiaoshan','mananger',7782,To_Date('June 3,97','MON DD,YY'), 300,null,10)); insert into emp (empno,ename,hiredate) values(9000,'zhangqs',to_date('2008-8-30','YYYY-MM-DD'));
查看结果:select * from emp where empno=9000;
④设置显示格式:
set linesize 500
set pagesize 100
select * from emp;
⑤run命令或“/”重新执行最近执行的SQL语句;
⑥设置时间显示格式:alter session set NLS_date_format='YYYY-MM-DD';
⑦使用绑定变量:
insert into dept(depno,dname,loc)values(&department_id,'&department_name','&department_location')
insert into emp(empno,ename,sal)values(&employee_NO,'&employee_name',&employee_salary);
⑧从其他表中复制数据:
insert into managers(id,name,salary,hiredate)
select empno,ename,sal,hiredate from emp where job='MANAGER';
2.修改表中记录:
update emp
set deptno=20
where empno=9001;
3.删除表中数据:
delete from dept
where dname='DEVELOPMENT';
4.数据库事务:事务是数据库一组逻辑操作的集合;多个DML语句可以构成事务,单个DDL语句可以构成事务;单个DCL可以构成事务;
使用commit和rollback命令;
5.事务保存点:可以在需要的地方建立事务保存点;
savepoint Update_emp; --创建保存点;
rollback to Update_emp; --会退到指定保存点;