Oracle - 数据更新 - 增删改
/* 数据的更新 增加 删除 修改 */ -----------------------------------增加(一次只能插入一条数据) --自定义插入数据列的顺序 INSERT INTO EMP(EMPNO,ENAME,SAL,DEPTNO) VALUES(8888,'DFBB',2666,10); --按照数据库默认的顺序插入 INSERT INTO EMP VALUES(9999,'RWX','JIAOZHU',7788,SYSDATE,3333,NULL,10); --插入查询的结果 INSERT INTO EMP(EMPNO,ENAME) SELECT DEPTNO,DNAME FROM DEPT; CREATE TABLE EMPCOPY AS SELECT * FROM EMP WHERE 1=2; --SQL注入(将来写代码的时候要防止sql注入) SELECT * FROM EMP WHERE JOB = 'CLERK' OR 1 = 1; --错误的示范 INSERT INTO EMP(EMPNO,ENAME,SAL,DEPTNO) VALUES(8888,'DFBB',2666); INSERT INTO EMP(EMPNO,ENAME,SAL,DEPTNO) VALUES(8888,'DFBB',2666,10,2); INSERT INTO EMP(EMPNO,ENAME,SAL,DEPTNO) VALUES('abcd','DFBB',2666,10); INSERT INTO EMP(EMPNO,ENAME,SAL,DEPTNO) VALUES(56789,'DFBB',2666,10); INSERT INTO EMP(EMPNO,ENAME,SAL,DEPTNO) VALUES('1234','DFBB',2666,10); INSERT INTO EMP(EMPNO,ENAME,SAL,DEPTNO) VALUES(567,'DFBB',2666,10); -----------------------------------删除 DELETE FROM EMP; DELETE FROM EMP WHERE EMPNO = '7788'; DELETE FROM EMP WHERE ENAME LIKE '%S%' AND SAL>2000; --有毒 慎用 CREATE TABLE EMPCOPY AS SELECT * FROM EMP TRUNCATE TABLE EMPCOPY; -----------------------------------修改 UPDATE EMP SET SAL = SAL+1000 ,COMM = 800,JOB = 'CODER'; UPDATE EMP SET SAL = SAL*1.2 WHERE EMPNO = 7788; UPDATE EMP SET SAL = SAL*1.2 WHERE ENAME LIKE '%A%' AND SAL<2000; ROLLBACK;