-- insert data
insert into emp values(123,'张si','','','');
insert into emp1(empno) values(234);
commit;
--delete data
delete from emp where empno = 222;
commit;
--update data
update emp set empno=2323, ename='zhangsan';
update emp1 set sal='111' where sal='1311';
--Query data
select * from emp1;--shift+home key, then press f8 to execute.
select distinct ename, sal from emp1; -- query unique (if it is two values, it is joint unique.)
select empno employee number, ename as employee name from emp; -- set an alias for the query result.
SELECT 'Number is: ' || empno || 'The name of the employee is: ' || ename || ', the basic salary is: ' || sal Employee information FROM emp ; -- The result is spliced out like this.
select empno , ename, (sal+200)*12 as annual salary from emp; --The query result can be set as a function.
select count(*) from emp;
select * from emp where empno in('112','211');
select * from emp where empno ='23' or empno ='222';
select * from emp where empno like '%222%';
select * from emp order by sal desc;
--left join .. on , right join ..on . Join left and right.
select t1.empno , t1.ename from emp t1 right join emp1 t2 on t1.empno=t2.empno;
--group by has a principle that among all the columns after select, columns that do not use aggregate functions must appear after group by. Group by group first, and then aggregate query.
--having is usually used in conjunction with group by to filter the record values returned by the group by statement. The existence of having makes up for the deficiency that the where keyword cannot be used in conjunction with aggregate functions.
select name , sum(number) from test group by name;
select id, count(course) as numcourse , avg(score) as avgscore from student group by id having avg(score)>80;
--Get a temporary column with the same number of rows as the number of rows in the p#fasp_T_pupcs021 table, and the column value of each row is 1;
select 1 from p#fasp_T_pupcs021;
--Query a tree, start with the guid of the first node, connect by prior condition is guid = superguid. Query this tree. prior is a top-down approach.
select * from p#FASP_T_PUBDEPARTMENT start with guid='90218F42D8491150E5D7892146E44FF9' connect by prior guid=superguid; --Query the number of all parent nodes with this value.
--rollback , commit ,
--Things are set to auto-commit.
set autocommit on;
--View database lock status.
select session_id,oracle_username,process from v$locked_object where oracle_username='FASP_14';
--Query v$session data dictionary
select sid,serial#,username,lockwait,status from v$session where sid in(152,394);
-- remove deadlock
alter system kill session '111';
CREATE TABLE department
AS
SELECT d.deptno deptno,d.dname dname,d.loc loc,
COUNT(e.empno) count, SUM(e.sal + NVL(e.comm,0))
ROUND(AVG(e.sal + NVL(e.comm,0)),2) avg, MAX(e.sal) max, MIN(e.sal) min
FROM dept d,emp e
WHERE d.deptno=e.deptno(+)
GROUP BY d.deptno,d.dname,d.loc
ORDER BY d.deptno ;