Related Operations in Oracle

How to query the ip address of this machine?

 

select sys_context('userenv','ip_address') from dual;

 

Use functions to add custom formatted dates

 

Using the o_date function

This is how to add custom date data to the table, use to_date('date','yyyy-mm-dd'), the date to be entered in front of the brackets, and the format of the input after.

Example 1
SQL> insert into emp values(9998,'Xiaohong','MANAGER',7782,to_date('1998-11-11','yyyy-mm-dd'),78.9,55.3,10);

Example 2
SQL> insert into emp values(9998,'Xiaohong','MANAGER',7782,to_date('1998/11/11','yyyy/mm/dd'),78.9,55.3,10);

 

Use subqueries:

 

Introduction to inserting data using subqueries

:
When using the values ​​clause, only one row of data can be inserted at a time. When using subqueries to insert data, an insert statement can insert a large amount of data, when processing row migration or loading data from external tables to the database , you can use subqueries to insert data.


Example: Import

the data in the old table to the new table, such as importing the data with department number 10 in the old table to the new table

SQL> insert into kkk (myId,myname,myDept) select empno,ename ,deptno from emp where deptno=10;

where the structure of the new table kkk is

Name Type Nullable Default Comments
------ ------------ -------- ------- --------
MYID NUMBER(4) Y                        
MYNAME VARCHAR2(10) Y                        
MYDEPT NUMBER(5) Y     


special usage:
SQL> insert into table A select * from table B where deptno=10;
this usage can only The structure used for table A and table B is exactly the same

 

 



Introduction to updating data with subqueries
: When updating data with the update statement, you can either use expressions or values ​​to directly modify the data, or you can use subqueries to modify the data.

? I hope that the position, salary, and subsidies of the employee scott are the same as those of the smith employee.

kkkk is the same table as the emp table.

SQL> update kkkk set (job,sal,comm)=(select job,sal,comm from emp where ename='SMITH' ) where ename='SCOTT';
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327039651&siteId=291194637