SELECT object_name, machine, s.sid, s.serial# ,o.ownerFROM gv$locked_object l, dba_objects o, gv$session s
WHERE l.object_id = o.object_id
AND l.session_id = s.sid;
select DEALERCODE,COUNT(spe_char)from(select PARTSCODE,
DEALERCODE,
regexp_replace(PARTSCODE,'[^!@#$%&*()+=:;",.?\|]','') spe_char
from A ) t
where t.spe_char isnotnullGROUPBY DEALERCODE
查询某表中有空格的数量
select DEALERCODE,count(1)from A
where PARTSCODE like' %'groupby DEALERCODE
查询某表中同一LOCANO>1的数量
SELECT T.DEALERCODE,COUNT(1)FROM(SELECT DEALERCODE, LOCANO,COUNT(1)FROM A
WHERE TRIM(LOCANO)ISNOTNULLGROUPBY DEALERCODE, LOCANO
HAVINGCOUNT(1)>1ORDERBY DEALERCODE DESC) T
WHERE T.LOCANO ISNOTNULLGROUPBY T.DEALERCODE
修复脚本
MERGEINTO A表 X
USING(SELECTDISTINCT TO_CHAR(A.ID)AS ID,C.QTY
FROM A表 A
JOIN C表 C
ON A.NO= TRIM(C.CODE)) Y ON(X.ID=Y.ID)WHENMATCHEDTHENUPDATESET X.QTY = Y.QTY;COMMIT;
获取修复数据语句
SELECT'UPDATE A表 SET QTY = '''|| QTY ||''' WHERE ID = '''|| ID ||''';'FROM A表
--数据为数值类型时SELECT'UPDATE A表 SET QTY = '|| QTY ||' WHERE ID = '''|| ID ||''';'FROM A表
--将所有A表数据复制进B表中DROPTABLE B--固化脚本名;CREATETABLE B ASSELECT*FROM A;GRANTSELECTON B TO BBASE;--将此表查询权限授权给另一数据库CREATEINDEX GH1 ON B(ORDERNO)TABLESPACE TACTINDEX01;--创建索引
固化脚本(例固化已结算与未结算的数据)
DROPTABLE S;CREATETABLE S ASSELECT*FROM A表 A
WHEREEXISTS(SELECT1FROM(SELECT C.DNO, C.DCODE, D.WNO
FROM(SELECT B.WNO, A.DCODE, A.DNO
FROM A表 A --申请主表JOIN B表 B ---结算明细表ON A.DCODE = B.DCODE
AND A.DNO = B.DNO) C --通过结算明细表关联到的单子JOIN D表 D ---结算主表ON C.WNO = D.WNO AND C.DCODE=D.DCODE
AND D.CTE ISNULL) E ---未结算的单子WHERE A.DCODE = E.DCODE
AND A.DNO = E.DNO)AND A.WTYPE='类型'UNIONALLSELECT A.*FROM A表 A
JOIN G表 G ---工单ON A.ORDERNO = G.ORDERNO
WHERE G.TTYPE IN('M')ANDNOTEXISTS(SELECT1FROM(SELECT C.DNO, C.DCODE, D.WNO
FROM(SELECT B.WNO, A.DCODE, A.DNO
FROM A表 A --申请主表JOIN B表 B ---结算明细表ON A.DCODE = B.DCODE
AND A.DNO = B.DNO) C --结算明细表关联到的单子JOIN D表 D ---结算主表ON C.WNO = D.WNO AND C.DCODE=D.DCODE
AND D.CTE ISNULL) E ---未结算的单子WHERE A.DCODE = E.DCODE
AND A.DNO = E.DNO)AND A.WTYPE='类型';GRANTSELECTON S TO S表;
模糊查询
where id like'%1'--查询id首位任意但后位为1的数据where id like' %'--查询首位为空格后位任意的数据where id like'%1%'--查询数据内有1的数据
--若ENO不为空或不等于null就将此数据赋值为1,否则赋值为0CASEWHEN ENO ISNOTNULLAND ENO <>'null'THEN'1'ELSE'0'END--例(查询ostatus为2的数量)
decode(SUM(CASEWHEN ostatus='2'THEN1END),null,0)已完成,
查询更新日期的年份,与每家店最大的自增序列
--例1SELECT substr(b.seq,-4)as seq , b.yyear ,T1.CODE
FROM T1表 T1
JOIN(selectmax(substr(TRIM(T1.TNO),-6))OVER(PARTITIONBY T1.CODE)as seq,--店_年份后两位_四位自增序号
T1.CODE,
T1.TNO,
TO_CHAR(T1.ATIME,'YYYY')as yyear
from T1表 T1
where substr(TRIM(T1.TNO),-4,1)<>'D') B
ON T1.TNO = B.TNO
WHERE substr(TRIM(T1.TNO),-6)= B.SEQ
--例2SELECTMAX(B.yyear),MAX(B.seq),T1.CODE
FROM T1表 T1
JOIN(selectmax(substr(TRIM(T1.TNO),-4))OVER(PARTITIONBY T1.CODE)as seq,
T1.CODE,
T1.TNO,
TO_CHAR(T1.ATIME,'YYYY')as yyear
from T1表 T1
where substr(TRIM(T1.TNO),-4,1)<>'D') B
ON T1.TNO = B.TNO
WHERE substr(TRIM(T1.TNO),-4)= B.SEQ GROUPBY T1.CODE
--例3:取最大创建时间的最大序列值SELECTMAX(B.SEQ)AS SEQ,substr(MAX(B.yyear),0,4)ASYEAR,T1.DCode AS DCode
FROM T1表 T1
JOIN(SELECTmax(TO_CHAR(T1.ATIME,'YYYYMMDD'))OVER(PARTITIONBY T1.DCODE)AS yyear,
substr(TRIM(T1.DNO),-4)AS SEQ,
T1.DCode ,
T1.DNO
FROM T1表 T1
where substr(TRIM(T1.DNO),-4,1)<>'D')B
on T1.DNO=B.DNO
WHERE substr(TRIM(T1.DNO),-4)= B.SEQ AND TO_CHAR(T1.ATIME,'YYYYMMDD')= B.yyear
GROUPBY T1.DCode ;
复制一张表,复制A表的表结构至B表
CREATETABLE B ASSELECT*FROM A
where1=1;--若条件成立复制表结构与数据,若不成立复制表结构(1=2)
更新语句
update A表 A
join(select C.po_no,C.p_no,C.d_code,MAX(p_qty)as p_qty from C表 C
groupby C.po_no,C.p_no,C.d_code
)C
on A.po_no = C.po_no
AND A.op_no = C.p_no
AND A.D_CODE = C.d_code
SET A.original_order_qty = C.p_qty