sql 数据操作片段

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 数据操作片段相关的知识,希望对你有一定的参考价值。

--  Regex replace
UPDATE TABLE T SET T.FIELD = REGEXP_REPLACE (T.FIELD, 'Search', 'Replace')

--  Update based on another table
UPDATE COMPOUND_INVENTORY t
SET T.PUBCHEM_CID = (
SELECT C.PUBCHEM_CID
FROM COMPOUND C
WHERE T.CID = C.CID)

--  Check for missing against another table
SELECT L.CID 
FROM COMPOUND L 
LEFT JOIN COMPOUND_INVENTORY I ON L.CID = I.CID
WHERE I.CID IS NULL

--  Count repeats
SELECT   col,
         COUNT(dupe_col) AS dupe_cnt
FROM     TABLE
GROUP BY col
HAVING   COUNT(dupe_col) > 1
ORDER BY COUNT(dupe_col) DESC

--  Select row range
SELECT *
FROM (SELECT T1.*, ROWNUM AS ROWNUMBER
FROM COMPONENT_LIBRARY T1)
WHERE ROWNUMBER BETWEEN 10 AND 18

-- Create database link 
CREATE DATABASE LINK UADEVORADB
  CONNECT TO user IDENTIFIED BY password 
  USING '(DESCRIPTION=
  (ADDRESS=(PROTOCOL=TCP)(HOST=uadevorahost1)(PORT=1521))
  (CONNECT_DATA=(SERVICE_NAME=uadevoradb.domaindb)))'
  

以上是关于sql 数据操作片段的主要内容,如果未能解决你的问题,请参考以下文章

MySQL触发器

使用 with as 优化SQL

使用触发器对学生表操作进行日志记录

MySql触发器使用

spark关于join后有重复列的问题(org.apache.spark.sql.AnalysisException: Reference '*' is ambiguous)(代码片段

Mybaits的批量操作包括批量删除 批量增加和批量更新