1 | sqlplus 用户名/密码@主机:端口号/SID 可选as sysdba |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
LISTENER2 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = iZbp1d4tisi44j6vxze02fZ)(PORT = 1522)) ) SID_LIST_LISTENER2 = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = gdn1400) (ORACLE_HOME = /fdisk1/oracle1400/base/dbhome_1) (SID_NAME = orcl1400) ) ) ADR_BASE_LISTENER2 = /fdisk1/oracle1400/base LISTENER1 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = iZbp1d4tisi44j6vxze02fZ)(PORT = 1521)) ) ADR_BASE_LISTENER1 = /fdisk1/oracle1400/base |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
lsnrctl status listener1 ... Services Summary... Service "orcl1400" has 1 instance(s). Instance "orcl1400", status READY, has 1 handler(s) for this service... Service "orcl1400XDB" has 1 instance(s). Instance "orcl1400", status READY, has 1 handler(s) for this service... The command completed successfully lsnrctl status listener2 ... Services Summary... Service "gdn1400" has 1 instance(s). Instance "orcl1400", status UNKNOWN, has 1 handler(s) for this service... The command completed successfully |
1 | sqlplus sys/password@iZbp1d4tisi44j6vxze02fZ:1521/orcl1400 as sysdba |
1 2 3 4 5 |
SQL> show parameter service NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ service_names string orcl1400 |
1 2 3 4 5 6 7 8 9 10 11 12 |
sqlplus sys/password@iZbp1d4tisi44j6vxze02fZ:1522/gdn1400 as sysdba SQL*Plus: Release 12.1.0.2.0 Production on Thu May 30 20:51:00 2019 Copyright (c) 1982, 2014, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options SQL> |
1 | sqlplus sys/password@iZbp1d4tisi44j6vxze02fZ:1521/orcl1400 as sysdba |
1 | sqlplus sys/password@tns1400 as sysdba |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
NSN1522 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = iZbp1d4tisi44j6vxze02fZ)(PORT = 1522)) ) (CONNECT_DATA = (SERVICE_NAME = gdn1400) ) ) NSN1521 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = iZbp1d4tisi44j6vxze02fZ)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl1400) ) ) |
1 2 |
NSN1522, iZbp1d4tisi44j6vxze02fZ, 1522, gdn1400 -----> listener2 NSN1521, iZbp1d4tisi44j6vxze02fZ, 1521, orcl1400 -----> listener1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# sqlplus sys/password@nsn1521 as sysdba SQL*Plus: Release 12.1.0.2.0 Production on Thu May 30 20:58:51 2019 Copyright (c) 1982, 2014, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options SQL> # sqlplus sys/password@nsn1522 as sysdba SQL*Plus: Release 12.1.0.2.0 Production on Thu May 30 20:58:55 2019 Copyright (c) 1982, 2014, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options SQL> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
--创建部门表 dept: CREATE TABLE dept ( deptno NUMBER(2) CONSTRAINT PK_DEPT PRIMARY KEY, dname VARCHAR2(14) , loc VARCHAR2(13) , CREATEDTIME DATE, UPDATEDTIME DATE, CREATEDBY NUMBER(7,0), UPDATEDBY NUMBER(7,0) ) ; --创建员工表 emp: CREATE TABLE emp ( empno NUMBER(4) CONSTRAINT PK_EMP PRIMARY KEY, ename VARCHAR2(10), job VARCHAR2(15), mgr NUMBER(4), hiredate DATE, sal NUMBER(7,2), comm NUMBER(7,2), deptno NUMBER(2) CONSTRAINT FK_DEPTNO REFERENCES DEPT, CREATEDTIME DATE, UPDATEDTIME DATE, CREATEDBY NUMBER(7,0), UPDATEDBY NUMBER(7,0) ); --创建员工表 emp_copy: CREATE TABLE emp_copy ( empno NUMBER(4), ename VARCHAR2(10), job VARCHAR2(15), mgr NUMBER(4), hiredate DATE, sal NUMBER(7,2), comm NUMBER(7,2), deptno NUMBER(2), CREATEDTIME DATE, UPDATEDTIME DATE, CREATEDBY NUMBER(7,0), UPDATEDBY NUMBER(7,0) ); --自定义一个序列 create sequence emp_sequence increment by 1 --每次增加几个,我这里是每次增加1 start with 1 --从1开始计数 nomaxvalue --不设置最大值 nocycle --一直累加,不循环 nocache --不建缓冲区 --插入dept表数据: INSERT INTO dept VALUES(10,'ACCOUNTING','NEW YORK',sysdate,sysdate,123123,123123); INSERT INTO dept VALUES (20,'RESEARCH','DALLAS',sysdate,sysdate,123123,123123); INSERT INTO dept VALUES(30,'SALES','CHICAGO',SYSDATE,SYSDATE,123123,123123); INSERT INTO dept VALUES(40,'OPERATIONS','BOSTON',sysdate,sysdate,123123,123123); --插入emp表数据: INSERT INTO emp VALUES(7369,'SMITH','CLERK',7902,to_date('17-12-1980','dd-mm-yyyy'),800,NULL,20,sysdate,sysdate,123123,123123); INSERT INTO emp VALUES(7499,'ALLEN','SALESMAN',7698,to_date('20-2-1981','dd-mm-yyyy'),1600,300,30,sysdate,sysdate,123123,123123); INSERT INTO emp VALUES(7521,'WARD','SALESMAN',7698,to_date('22-2-1981','dd-mm-yyyy'),1250,500,30,SYSDATE,SYSDATE,123123,123123); INSERT INTO emp VALUES(7566,'JONES','MANAGER',7839,to_date('2-4-1981','dd-mm-yyyy'),2975,NULL,20,sysdate,sysdate,123123,123123); INSERT INTO emp VALUES(7654,'MARTIN','SALESMAN',7698,to_date('28-9-1981','dd-mm-yyyy'),1250,1400,30,SYSDATE,SYSDATE,123123,123123); INSERT INTO emp VALUES(7698,'BLAKE','MANAGER',7839,to_date('1-5-1981','dd-mm-yyyy'),2850,NULL,30,sysdate,sysdate,123123,123123); INSERT INTO emp VALUES(7782,'CLARK','MANAGER',7839,to_date('9-6-1981','dd-mm-yyyy'),2450,NULL,10,SYSDATE,SYSDATE,123123,123123); INSERT INTO emp VALUES(7788,'SCOTT','ANALYST',7566,to_date('19-4-87','dd-mm-yyyy'),3000,NULL,20,SYSDATE,SYSDATE,123123,123123); INSERT INTO emp VALUES(7839,'KING','PRESIDENT',NULL,to_date('17-11-1981','dd-mm-yyyy'),5000,NULL,10,sysdate,sysdate,123123,123123); INSERT INTO emp VALUES(7844,'TURNER','SALESMAN',7698,to_date('8-9-1981','dd-mm-yyyy'),1500,0,30,SYSDATE,SYSDATE,123123,123123); INSERT INTO emp VALUES(7876,'ADAMS','CLERK',7788,to_date('23-5-87','dd-mm-yyyy'),1100,NULL,20,sysdate,sysdate,123123,123123); INSERT INTO emp VALUES(7900,'JAMES','CLERK',7698,to_date('3-12-1981','dd-mm-yyyy'),950,NULL,30,sysdate,sysdate,123123,123123); INSERT INTO emp VALUES(7902,'FORD','ANALYST',7566,to_date('3-12-1981','dd-mm-yyyy'),3000,NULL,20,SYSDATE,SYSDATE,123123,123123); INSERT INTO emp VALUES(7934,'MILLER','CLERK',7782,to_date('23-1-1982','dd-mm-yyyy'),1300,NULL,10,sysdate,sysdate,123123,123123); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
INSERT INTO emp_copy SELECT emp_sequence.nextVal,C.* FROM ( SELECT e.ename , e.JOB , e.mgr , e.hiredate, e.sal , e.comm , e.deptno, SYSDATE AS CREATEDTIME, SYSDATE AS UPDATEDTIME, 123124 AS CREATEDBY, 123124 as UPDATEDBY FROM emp e, dept d WHERE e.deptno = d.deptno AND d.loc='CHICAGO' and e.sal>=1500 )C; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
MERGE INTO emp e USING ( SELECT e1.job, e1.ename,e1.comm FROM emp e1, dept d1 WHERE e1.deptno = d1.deptno AND d1.loc='CHICAGO' and e1.job='SALESMAN' )t ON ( e.job = t.job and e.ename = t.ename ) WHEN MATCHED THEN UPDATE set e.comm= t.comm+200 |
1 2 3 4 5 6 7 |
DELETE FROM ( SELECT c.* FROM emp c,dept d WHERE d.deptno = c.deptno AND d.loc = 'CHICAGO' and c.sal < 1500 ); |
相关文章