--  1,2 컬럼값이 서로 같고 3컬럼값만 다른경우
SELECT * FROM A, B
WHERE (A.1 = B.1 AND A.2 = B.2)
AND A.3 <> B.3;

--  1,3컬럼값은 같고  2컬럼값만 다른 경우
SELECT * FROM A, B
WHERE (A.1 = B.1 AND A.3 = B.3)
AND A.2 <> B.2;

--  2,3컬럼값은 같고  1컬럼값만 다른 경우
SELECT * FROM A, B
WHERE (A.2 = B.2 AND A.3 = B.3)
AND A.1 <> B.1;


--  1,2,3 컬럼이 전부 다른 경우
SELECT * FROM A, B
WHERE A.1 <> B.1 AND A.2 <> B.2
AND A.3 <> B.3;

 

출처 - http://www.gurubee.net/article/59245

 

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

 

SELECT A.TIMS_DATE,
       A.FUND_CODE,
       A.FUND_NAME,
       A.BM_INDEX,
       B.BM_INDEX,
       A.BM_RATE,
       B.BM_RATE
  FROM IFT_FUND_STANDARD_PRICE_RESULT A, IFT_FUND_STANDARD_MODIFY B
 WHERE     (A.BM_INDEX <> B.BM_INDEX OR A.BM_RATE <> B.BM_RATE)
       --AND A.TIMS_DATE = '20171104'
       AND A.TIMS_DATE = TO_CHAR(SYSDATE-3, 'YYYYMMDD')
       AND A.TIMS_DATE = B.TIMS_DATE
       AND A.FUND_CODE = B.FUND_CODE

[ORACLE]CLOB DATA Export Excel(DBMS_LOB.SUBSTR)

Database 2016.03.28 15:09 Posted by 애플자라

CLOB 데이터가 원하는데로 안나와서 일단 미련하게 추출; 


 SELECT 

   BOARD_SEQ,

         SEQ,

         TITLE,

         DBMS_LOB.SUBSTR(CNTNT, 2000, 1)  AS CONTENTS1,

         DBMS_LOB.SUBSTR(CNTNT, 2000, 2001)     AS CONTENTS2,

         DBMS_LOB.SUBSTR(CNTNT, 2000, 4001)     AS CONTENTS3,

         DBMS_LOB.SUBSTR(CNTNT, 2000, 6001)     AS CONTENTS4,

         DBMS_LOB.SUBSTR(CNTNT, 2000, 8001)     AS CONTENTS5,

         DBMS_LOB.SUBSTR(CNTNT, 2000, 10001)    AS CONTENTS6,

         DBMS_LOB.SUBSTR(CNTNT, 2000, 12001)    AS CONTENTS7,

         DBMS_LOB.SUBSTR(CNTNT, 2000, 14001)    AS CONTENTS8,

         DBMS_LOB.SUBSTR(CNTNT, 2000, 16001)    AS CONTENTS9

         --dbms_lob.getlength(CNTNT) -- 15801

    FROM TBD_BOARD

   WHERE BOARD_SEQ = '3'

ORDER BY SEQ DESC

[ORACLE] 없는 데이터 강제로 만들기

Database 2014.09.16 11:58 Posted by 애플자라

없는 데이터 강제로 만들기 및 정해진 데이터 표로 리스트 뿌리기

미련하면서도 억지로 만든쿼리

 

SELECT * FROM
(
SELECT SUBSTR(MARKETING_DATE,0,7) AS DAYS, G_CATE, COUNT(G_CATE) AS CNT 
FROM TB_MARKETING   
WHERE SUBSTR(MARKETING_DATE,0,4) = SUBSTR(TO_CHAR(SYSDATE,'YYYYMMDD'),0,4) 
AND G_CATE IN  ('공제회','국가기관','생손보사','은행(중앙회)','금융기관','기타')  
GROUP BY SUBSTR(MARKETING_DATE,0,7),G_CATE
UNION ALL
SELECT DAYS,G_CATE,CNT FROM APLUS_V_TB_MARKETING_ANNUAL
)
ORDER BY DAYS DESC, DECODE(G_CATE,'국가기관',1,'공제회',2,'생손보사',3,'은행(중앙회)',4,'금융기관',5,'기타',6)

 

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

APLUS_V_TB_MARKETING_ANNUAL DDL

 

 

CREATE OR REPLACE FORCE VIEW APLUSORA.APLUS_V_TB_MARKETING_ANNUAL
(
   DAYS,
   G_CATE,
   CNT
)
AS
SELECT TO_CHAR(SYSDATE,'YYYY-MM') AS DAYS, '공제회' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(SYSDATE,'YYYY-MM') AND G_CATE = '공제회'
)
UNION ALL
SELECT TO_CHAR(SYSDATE,'YYYY-MM') AS DAYS, '국가기관' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(SYSDATE,'YYYY-MM') AND G_CATE = '국가기관'
)
UNION ALL
SELECT TO_CHAR(SYSDATE,'YYYY-MM') AS DAYS, '생손보사' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(SYSDATE,'YYYY-MM') AND G_CATE = '생손보사'
)
UNION ALL
SELECT TO_CHAR(SYSDATE,'YYYY-MM') AS DAYS, '은행(중앙회)' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(SYSDATE,'YYYY-MM') AND G_CATE = '은행(중앙회)'
)
UNION ALL
SELECT TO_CHAR(SYSDATE,'YYYY-MM') AS DAYS, '금융기관' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(SYSDATE,'YYYY-MM') AND G_CATE = '금융기관'
)
UNION ALL
SELECT TO_CHAR(SYSDATE,'YYYY-MM') AS DAYS, '기타' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(SYSDATE,'YYYY-MM') AND G_CATE = '기타'
)
UNION ALL
SELECT TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AS DAYS, '공제회' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AND G_CATE = '공제회'
)
UNION ALL
SELECT TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AS DAYS, '국가기관' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AND G_CATE = '국가기관'
)
UNION ALL
SELECT TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AS DAYS, '생손보사' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AND G_CATE = '생손보사'
)
UNION ALL
SELECT TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AS DAYS, '은행(중앙회)' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AND G_CATE = '은행(중앙회)'
)
UNION ALL
SELECT TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AS DAYS, '금융기관' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AND G_CATE = '금융기관'
)
UNION ALL
SELECT TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AS DAYS, '기타' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AND G_CATE = '기타'
)

 

 

APLUS_V_TB_MARKETING_ANNUAL.SQL

 

 

1. 데이터를 옮길 대상 테이블을 생성한다. : "TEMP_20130607" 라하자.;

 

CREATE TABLE TEMP_20130607
(
  TXDATE               VARCHAR2(8 BYTE)         NOT NULL,
  WRAP_ACCOUNT_NO      VARCHAR2(20 BYTE)        NOT NULL,
  WRAP_ACCOUNT_AMOUNT  VARCHAR2(4000 BYTE)
)
TABLESPACE APLUS_DATA_TS
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           )
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;

 

2. FUNCTION 생성

 

CREATE OR REPLACE FUNCTION APLUSORA.FNC_LONG2CHAR (  
    ori_rowid        ROWID,  
    ori_column       VARCHAR2,
    ori_table        VARCHAR2  
)  
    RETURN VARCHAR
AS  
    longCont   VARCHAR2 (32767);  
    sqlQuery   VARCHAR2 (2000);
BEGIN  
    sqlQuery :=         'select ' || ori_column || ' from '|| ori_table ||         ' where rowid = '|| CHR (39)|| ori_rowid|| CHR (39);    EXECUTE IMMEDIATE sqlQuery                INTO longCont;        longCont := SUBSTR (longCont, 1, 4000);   RETURN longCont;END;
/

 

3. 실제 사용 쿼리

INSERT INTO TEMP_20130607
(TXDATE,WRAP_ACCOUNT_NO,WRAP_ACCOUNT_AMOUNT)
(SELECT TXDATE,WRAP_ACCOUNT_NO,FNC_LONG2CHAR(ROWID,'WRAP_ACCOUNT_AMOUNT','IFK_CUSTOMER') FROM IFK_CUSTOMER
WHERE  TXDATE = (SELECT MAX(TXDATE) DT FROM IFK_CUSTOMER)
AND     ACCOUNT_STATUS_DESC = '활동')

 

 테이블 복사하기 스키마 데이터

CREATE TABLE 새로만들테이블명 AS

SELECT * FROM 복사할테이블명 [WHERE 절]

 

 테이블 구조만 복사하기

CREATE TABLE 새로만들테이블명 AS

SELECT * FROM 복사할테이블명 WHERE 1=2 [where에다가 참이 아닌 조건을 넣어줌]

 

 테이블은 이미 생성되어 있고 데이터만 복사

INSERT INTO 복사할테이블명 SELECT * FROM 복사할테이블명 [WHERE 절]

 

테이블 이름 변경

ALTER TABLE 구테이블명 RENAME TO 신테이블명

주의할 점은, Primary Key 나 Index 등 Constraint 는 복제되지 않습니다. 당연한 것이, 복제된다면 동일한 이름의 Object 가 이미 존재한다는 에러를 만나게 되겠죠. 데이터를 잠시 옮겨놓기 위한 용도의 테이블 복제에선 불필요하다고 봅니다.

MSSQL 데이터 백업

Database 2010.06.07 20:41 Posted by 애플자라

USE master
GO

--EXEC sp_addumpdevice 'disk', 'AMAILCS_MSSQL_Backup', 'D:\CS_Amail_Backup\AMAILCS_MSSQL_Backup.bak'
--EXEC sp_addumpdevice 'disk', 'AMAILCS_DEV_MSSQL_Backup', 'D:\CS_Amail_Backup\AMAILCS_DEV_MSSQL_Backup.bak'
--EXEC sp_addumpdevice 'disk', 'AMAILCSNEW_MSSQL_Backup', 'D:\CS_Amail_Backup\AMAILCSNEW_MSSQL_Backup.bak'
--EXEC sp_addumpdevice 'disk', 'CS_MSSQL_Backup', 'D:\CS_Amail_Backup\CS_MSSQL_Backup.bak'
--EXEC sp_addumpdevice 'disk', 'EMS_BMT_MSSQL_Backup', 'D:\CS_Amail_Backup\EMS_BMT_MSSQL_Backup.bak'
--EXEC sp_addumpdevice 'disk', 'EMS51_BMT_MSSQL_Backup', 'D:\CS_Amail_Backup\EMS51_BMT_MSSQL_Backup.bak'
--EXEC sp_addumpdevice 'disk', 'EMS52_TEST_MSSQL_Backup', 'D:\CS_Amail_Backup\EMS52_TEST_MSSQL_Backup.bak'
--EXEC sp_addumpdevice 'disk', 'EMS61_MSSQL_Backup', 'D:\CS_Amail_Backup\EMS61_MSSQL_Backup.bak'
--EXEC sp_addumpdevice 'disk', 'EMS61_1_MSSQL_Backup', 'D:\CS_Amail_Backup\EMS61_1_MSSQL_Backup.bak'
--EXEC sp_addumpdevice 'disk', 'MobileEms52_MSSQL_Backup', 'D:\CS_Amail_Backup\MobileEms52_MSSQL_Backup.bak'
--EXEC sp_addumpdevice 'disk', 'ROUGH_MSSQL_Backup', 'D:\CS_Amail_Backup\ROUGH_MSSQL_Backup.bak'

DBCC SHRINKDATABASE(AMAILCS)
DBCC SHRINKDATABASE(AMAILCS_DEV)
DBCC SHRINKDATABASE(AMAILCSNEW)
DBCC SHRINKDATABASE(CS)
DBCC SHRINKDATABASE(EMS_BMT)
DBCC SHRINKDATABASE(EMS51_BMT)
DBCC SHRINKDATABASE(EMS52_TEST)
DBCC SHRINKDATABASE(EMS61)
DBCC SHRINKDATABASE(EMS61_1)
DBCC SHRINKDATABASE(MobileEms52)
DBCC SHRINKDATABASE(ROUGH)

BACKUP DATABASE AMAILCS      TO AMAILCS_MSSQL_Backup WITH INIT;
BACKUP DATABASE AMAILCS_DEV   TO AMAILCS_DEV_MSSQL_Backup WITH INIT;
BACKUP DATABASE AMAILCSNEW   TO AMAILCSNEW_MSSQL_Backup WITH INIT;
BACKUP DATABASE CS           TO CS_MSSQL_Backup WITH INIT;
BACKUP DATABASE EMS_BMT      TO EMS_BMT_MSSQL_Backup WITH INIT;
BACKUP DATABASE EMS51_BMT     TO EMS51_BMT_MSSQL_Backup WITH INIT;
BACKUP DATABASE EMS52_TEST   TO EMS52_TEST_MSSQL_Backup WITH INIT;
BACKUP DATABASE EMS61        TO EMS61_MSSQL_Backup WITH INIT;
BACKUP DATABASE EMS61_1      TO EMS61_1_MSSQL_Backup WITH INIT;
BACKUP DATABASE MobileEms52   TO MobileEms52_MSSQL_Backup WITH INIT;
BACKUP DATABASE ROUGH        TO ROUGH_MSSQL_Backup WITH INIT;

'Database' 카테고리의 다른 글

[MSSQL] MSSQL2000 ->2005 마이그레이션 attach  (0) 2010.07.05
[MSSQL]일별,주별,월별 통계  (0) 2010.06.29
MSSQL 데이터 백업  (0) 2010.06.07
Oracle DELETE_TRIGGER  (0) 2010.05.31
Oracle 짝수,홀수 구별  (0) 2010.05.26
[ORACLE] 구분자_LIST형_맵핑형_조합형쿼리  (0) 2009.11.04