Oracle database operation and function command summary

1. Back up table data: create table emp as select * from scott.emp


2. Restore table data: insert into emp select * from scott.emp


3. /*Merge into Detailed introduction
MERGE statement is the new syntax of Oracle9i for Combine UPDATE and INSERT statements.
Use the MERGE statement to query another table based on the connection condition of a table or subquery. If the
connection condition matches, perform an UPDATE, and if the connection condition matches, perform an INSERT.
This syntax only needs a full table scan to complete all the work, and the execution efficiency is higher than INSERT+UPDATE. 
*/
/*Syntax:
MERGE [INTO [schema .] table [t_alias] 
USING [schema .] {table | view | subquery} [t_alias] 
ON (condition) 
WHEN MATCHED THEN merge_update_clause 
WHEN NOT MATCHED THEN merge_insert_clause;
*/
merge into users
using doctor
on (users.user_id = doctor.doctorid)
when matched then
  update set users.user_name = doctor.doctorname
when not matched then
  insert
  values
    (doctor.doctorid,
     doctor.doctorid,
     '8736F1C243E3B14941A59FF736E1B5A8',
     doctor.doctorname,
     sysdate,
     'T',
     '',
     doctor.deptid,
     'b319dac7 -2c5c-496a-bc36-7f3e1cc066b8');


4. In Oracle, 


you can use the instr function to judge a string to determine whether it contains the specified character. 


Find the specified character in a string and return the position of the specified character found. 


Syntax: 
instr(sourceString,destString,start,appearPosition) 


instr('source string','target string','start position','number of occurrences' 





destString represents the substring to be searched from the source string; 


start represents the starting position of the search, this parameter is optional, and the default is 1; 


appearPosition represents the number of occurrences of destString that you want to find from the source character, this parameter is also available Selected, the default is 1. 


If the value of start is negative, it means searching from right to left, but the position data is still calculated from left to right. 


The return value is: the position of the string found. 


-------------------------------------------------- ----------- 


For the instr function, we often use it like this: Find the position of a specified substring from a string. For example: 


SQL> select instr('abcdefgh','de') position from dual; 




POSITION 
---------- 
   4 
starts from 1 and counts d and ranks fourth, so return 4 


SQL>select instr('abcdefghbc' ,'bc',3) position from dual; 


POSITION 
---------- 
  9 
Starting from the third character, the third character is c, so the string after 3 is searched for bc, Return 9 


--------------------------- 
Starts from the first character to find the position of the second sub-string occurrence of 
the SQL> SELECT InStr ( 'qinyinglianqin', 'Qin',. 1, 2) from position Dual; 
the POSITION 
---------- 
  12 is 


- -------------------------------------------------- ------------------- 

Guess you like

Origin blog.csdn.net/u013804636/article/details/51970606