¡á¿¹ 9_2_1 || ä¹ø Å×ÀÌºí »ý¼º
CREATE TABLE NUMSEQ (
TAB_NO VARCHAR2(10) PRIMARY KEY,
SEQ NUMBER
);
¡á¿¹ 9_2_2 || ä¹ø ´ë»ó Å×ÀÌºí »ý¼º
____CREATE TABLE____ TEST_1(
NO VARCHAR2(10) PRIMARY KEY
);
¡á¿¹ 9_2_3 || ä¹ø Å×À̺í ÃʱâÈ
INSERT INTO NUMSEQ VALUES('TEST_1', 0);
¡á¿¹ 9_2_4 || ä¹ø ´ë»ó Å×À̺í INSERT
INSERT INTO TEST_1(NO)
VALUES ((SELECT SEQ + 1
FROM NUMSEQ
WHERE TAB_NO='TEST_1'));
¡á¿¹ 9_2_5 || ä¹ø Å×À̺í UPDATE
UPDATE NUMSEQ SET SEQ = SEQ + 1;
¡á ¿¹ 9_2_6 || ä¹ø Å×À̺í UPDATE
CREATE TABLE TAB01_INSA( --TAB01_INSA TABLE
SABUN VARCHAR2(15) PRIMARY KEY,
NAME VARCHAR2(10),
JOIN_DAY VARCHAR2(8),
JOIN_GBN_CODE VARCHAR2(3)
);
CREATE TABLE TAB05_PRODUCT( --TAB05_PRODUCT TABLE
p_NO VARCHAR2(15) PRIMARY KEY,
p_CODE VARCHAR2(3),
p_COLOR VARCHAR2(3),
p_NAME VARCHAR2(10),
p_PROD_D VARCHAR2(8)
);
¡á¿¹ 9_2_7 || NUMSEQ ä¹ø Å×À̺í ÃʱâÈ
INSERT INTO NUMSEQ
VALUES ('TAB01', (SELECT TO_CHAR(SYSDATE, 'YYYYMMDD') || '00'
FROM DUAL));
INSERT INTO NUMSEQ VALUES('TAB05', 0);
¡á¿¹ 9_2_8 || µÎ °³ÀÇ Å×ÀÌºí µ¥ÀÌÅÍ ÀÔ·Â
INSERT INTO TAB01_INSA(SABUN, NAME, JOIN_DAY, JOIN_GBN_CODE)
VALUES ((SELECT DECODE(SUBSTR(MAX(SEQ), 1,8)
,TO_CHAR(SYSDATE, 'YYYYMMDD'), MAX(SEQ) + 1
,TO_CHAR(SYSDATE, 'YYYYMMDD')||'01')
FROM NUMSEQ
WHERE TAB_NO = 'TAB01'
AND SEQ < TO_CHAR(SYSDATE,'YYYYMMDD')||'99'),
:NAME, TO_CHAR(SYSDATE,'YYYYMMDD'), :JOIN_GBN_CODE);
INSERT INTO TAB05_PRODUCT (p_NO, p_CODE, p_COLOR, p_NAME, p_PROD_D)
VALUES((SELECT :CODE || :COLOR || :p_KIND || (SELECT SEQ + 1
FROM NUMSEQ
WHERE TAB_NO='TAB05')
FROM DUAL),
:p_CODE, :p_COLOR, :p_NAME, TO_CHAR(SYSDATE,'YYYYMMDD'));
¡á¿¹ 9_2_9 || µÎ °³ÀÇ Å×ÀÌºí µ¥ÀÌÅÍ ÀÔ·Â
UPDATE NUMSEQ
SET SEQ = ((SELECT DECODE(SUBSTR(MAX(SEQ), 1,8)
,TO_CHAR(SYSDATE, 'YYYYMMDD'), MAX(SEQ) + 1
,TO_CHAR(SYSDATE, 'YYYYMMDD')||'01')
FROM NUMSEQ
WHERE SEQ < TO_CHAR(SYSDATE,'YYYYMMDD')||'99'))
WHERE TAB_NO = 'TAB01';
UPDATE NUMSEQ SET SEQ = SEQ + 1 WHERE TAB_NO = 'TAB05';
¡á¿¹ 9_2_10 || °¢ Å×ÀÌºí µ¥ÀÌÅÍ È®ÀÎ
SELECT * FROM NUMSEQ;
SELECT * FROM TAB01_INSA;
SELECT * FROM TAB05_PRODUCT;
¡á¿¹ 9_2_11 || Å×À̺íÀÇ Áߺ¹¿¡·¯¸¦ ¹æÁö¸¦ À§ÇÑ PL-SQL¿¹Á¦
--»óÀ§·ÎÁ÷ »ý·«
UPDATE NUMSEQ SET SEQ = SEQ + 1
WHERE TAB_NO = 'TAB01';
SELECT SEQ INTO :seq FROM NUMSEQ WHERE TAB_NO = 'TAB01';
COMMIT;
INSERT INTO TAB01_INSA (SABUN, NAME, JOIN_DAY, JOIN_GBN_CODE)
VALUES (:seq, :NAME, SYSDATE, :JOIN_GBN_CODE);
--ÇÏÀ§·ÎÁ÷ »ý·«
¡á¿¹ 9_3_1 || ä¹ø Å×ÀÌºí »ý¼º
____CREATE TABLE____ COUNT_TAB(
NO_COL VARCHAR2(3) CONSTRAINT COUNT_TAB_PK PRIMARY KEY
);
¡á¿¹ 9_3_2 || PK¸¦ ÀÌ¿ëÇÑ Ã¤¹ø
INSERT INTO COUNT_TAB( NO_COL)
VALUES ((SELECT /*+ INDEX_DESC(COUNT_TAB COUNT_TAB_PK) */
DECODE(MAX(NO_COL),NULL,0,MAX(NO_COL)+1)
FROM COUNT_TAB
WHERE ROWNUM =1));
¡á¿¹ 9_3_3 || INSA Å×À̺í SABUN »ý¼º ¿¹
SELECT /*+ INDEX_DESC(INSA INSA_PK) */
DECODE(SUBSTR(MAX(SABUN), 1,8)
,TO_CHAR(SYSDATE, 'YYYYMMDD'), MAX(SABUN) + 1
,TO_CHAR(SYSDATE, 'YYYYMMDD')||'01') SABUN
FROM INSA
WHERE SABUN < TO_CHAR(SYSDATE, 'YYYYMMDD')||'99'
AND ROWNUM =1;
¡á¿¹ 9_3_4 || À妽º¸¦ ÀÌ¿ëÇÑ Ã¤¹ø »ý¼º
INSERT INTO INSA(SABUN, JOIN_DAY, NAME, ENG_NAME, SEX, HP, JOIN_GBN_CODE)
SELECT /*+ INDEX_DESC(INSA INSA_PK) */
DECODE(SUBSTR(MAX(SABUN), 1,8)
,TO_CHAR(SYSDATE, 'YYYYMMDD'), MAX(SABUN) + 1
,TO_CHAR(SYSDATE, 'YYYYMMDD')||'01') SABUN
,TO_CHAR(SYSDATE,'RRRRMMDD')
,:IN_NAME
,:IN_ENG_NAME
,:IN_SEX
,:IN_HP
,:IN_JOIN_GBN_CODE
FROM INSA
WHERE SABUN < TO_CHAR(SYSDATE,'YYYYMMDD')||'99'
AND ROWNUM =1;