한국어

About_LINUX

오라클 PL/SQL

2003.11.06 12:53

jun 조회 수:302841

Introduction to Oracle : SQL & PL/SQL 정리 및 출제예상문제

제 1 장

1. SQL 문장 중 error가 발생했다. 어떤 부분을 고쳐야 하는가
   * SELECT a,b,c
     FROM xxx
     where a = NULL;
     ->  = NULL 을 IS NULL로

2. name column을 select 할때 사용할 수 있는 function 3가지를 골라라   이때 name은 char(25)형식
   substr, length, nvl(2-8)
   TRUNC, ROUND, SYSDATE  총 6개의 예문중

3. 다음 중 number를 return 하는 function은? (2)
   1) ADD_MONTH(...
   2) MONTHS_BETWEEN(...
   ...

4. TRUNC('22-JUL-95','YEAR')의 결과는 ? '01-JAN-95' (2-30)

5. Cartesian Product를 만들기 위해서는 WHere 절의 JOIN Condition을 삭제하면 된다. (3-6)

6. 다음 sql 문에서 틀린 부분은? (1)
   1. SELECT emp.ename, emp.id, dept.deptname
   2. FROM emp e, dept d
   3. WHERE e.deptid = d.id
   4. AND sal > 3000;
Table Alias가 정해지면 SQL 문장 전체에서 적용해야 된다. (3-17)

7. emp 테이블과 sales 테이블을 Out Join 할때
   - emp 테이블과 sales 테이블에 대응하는 column이 있고 null 값을 갖는 row까지 display하고자 할때 사용

8.. Self JOIN의 예를 선택하기 (3-24) : in order to simulate two tables in the From clause.
        SQL> SELECT worker.last_name||' works for '|| manager.last_name
                 FROM s_emp worker, s_emp mansger
                 WHERE worker.manager_id = manager.id;

10. SUBQUERY시 single row comparision operator는 multi row를 만나면 error 2문제(5-16)
    SELECT ename, salary
    FROM  emp
    WHERE dept_no = (SELECT deptno FROM emp WHERE deptno IN (3,5));
    문장에서 에러가 발생하는 이유는?

11. 대소문자와 관계 없는 SQL 문 :  Where UPPER(d.name) = UPPER('&p_dname') (7-19)

12.  Naming Rule (Must Begin with a letter, ? 안됨, comment 는 예약어) (9-10)
        - 1~30 characters long, contain A-Z,a-z,0-9,_,$,#, not duplicate the name
    1 CREATE TABLE data_3000
    2 ( 3000_id   number(3)  constraint data_3000_pk PRIMARY KEY,
    3   name   varchar2(10)  constraint data_3000_name_nn NOT NULL,
    4   deptno  number(4)    constraint data_3000_deptno_fk FOREIGN KEY );
     문장에서 에러가 발행하는 곳은? (2)

13. number의 default precision 은 38 (9-13)

14. 어떤 column이 number값을 갖고 소숫점 오른쪽은 항상 2자리이나 왼쪽은 유동적일때 어떤 형식으로
    선언해야 하는가.
   1) NUMBER   2) NUMBER(p)   3)DATE...

15. 어떤 column이 number값을 갖고 3.2, 2.345, 12.23 와 같이 형식이 유동적일때 어떤 형식으로 선언
    해야 하는가?
   1) NUMBER   2) NUMBER(p,s) ...

14.15의 예문은 확실하지 않으나 답은 NUMBER, NUMBER(p,s), NUMBER(p) 중에서 고르는 문제임

16. Table의 not null column인 경우 insert시 반드시 포함 (9-18)
    INSERT INTO emp (id, name, sal)
    VALUES (832, 'test', 40000);
   위의 문장에서 에러를 발생시키는 이유? ( not null column의 값이 지정되지 않음 )
   ( table의 column형식들을 보여줌. columns중에서 not null column인 deptno가 존재 )

17. not unique index를 foreign key에 대해서 생성하는 방법  (1)
    1. create index on table column...
    2. 자동 생성되므로 생성할 필요가 없다.
    3. 만들 수 없다.
    4....

18. Create a view by using a Subquery 문에서 에러 발생하는 곳 (4)
    VIEW 생성시 order by는 사용할 수없다.
        SQL>1 CREATE VIEW view1
                2 AS SELECT id, last_name, userid, start_date
            3     FROM s_emp
            4     ORDER BY deptno;

19. USER_CONS_COLUMNS : View columns associated with the constraint name
    emp table에서 ord_id column의 constraint를 보려면 어떤 data dictionary를 보면 되는가?

20. data dictionary에서 모든 table에 대한 정보를 알 수 있는 것은?
    USER_OBJECTS

21. DBA가 user에게 table에 대한 object privilege를 주었을때 어떤 data dictionary로 정보를 얻을 수
    있는가? (1)
   1) ALL_COL_PRIVS
   2) USER_COL_PRIVS
   3) ALL_CONS_COLUMNS
   4) USER_CONS_COLUMNS

22. A user가 B user에게 object privilege를 grant했을때 정보를 볼 수 있는 data dictionary는?
    USER_COL_PRIVS_RECD

23. 자동으로 COMMIT되는경우 2가지 (1,3)
        1) COMMIT, ROLLBACK문을 실행하지 않고 SQL*PLUS를 exit한 경우
      2) system craft
      3) GRANT 문
      4) take off system without exit SQL*PLUS

24. table emp에서 a라는 column을 PK로 정하고 곧바로 적용되도록 하고 싶을때 실행문은? (3번일까?)
     1) ALTER TABLE emp
        ADD ( a  number(2)  constraint emp_a_pk PRIMARY KEY);
     2) ALTER TABLE emp
       disable constraint emp_a_pk primary key ;
     3) ALTER TABLE emp
        ADD CONSTRAINT emp_a_pk PRIMARY KEY;
     4)...

25. sequence를 생성시 1000부터 시작하고 1씩 증가하며 max value는 9999999이고 한번 사용한
    값은 다시 사용하지 않을때 맞는 문장. (1아니면 2)
    1. CREATE SEQUENCE sequence1
       start with 1000
       maxvalue 9999999
       nocycle
       nocache;
    2. CREATE SUQUENCE sequece1
       start with 1000
       maxvalue 9999999
       increment by 1
    3. 4 ......
      - CRATE SEQUENCE sequenct_name
                        [INCREMENT BY n]
                        [START WITH n]
                        [{MAXVALUE n | NOMAXVALUE}]
                        [{MINVALUE n | NOMINVALUE}]
                        [{CYCLE | NOCYCLE}]
                        [{CACHE n | NOCACHE}]

26. Create Sequence시 start with n이 없으면 1로 시작 (13-7)

27. System level security와 연관되는 privilege
    1) DELETE ANY TABLE
    2) INSERT
    3) UPDATE
    4) ALTER

28. 다음 문장에서 실행된 것은? (5개중 3개 고르기)
        SQL> CREATE ROLE manager;
        SQL> GRANT create table, create view TO mansger;
        SQL> GRANT manager TO velasquez, ropeburn;
    1) role 이 생성됨
    2) velasquez, ropeburn granted privilege
    3) manager granted privilege
    4)
    5)  

29. INSERT 문을 실행 시 data validate를 하는 것은? (3일까?)
   1) stored procedure
   2) client function
   3) database trigger
   4) 5)...

30. EXIT를 필요로 하는 LOOP 문은 BASIC LOOP (5-17)

31. cursor에서
    DECLARE
       v_id   number(5)
       v_name   varchar2(25)
       v_sal     number(7)
    CURSOR  cursor1 IS
       SELECT id, name
       INTO  v_id, v_name
      FROM emp
      WHERE sal > v_sal;
   에서 에러가 발생하는 이유는? (3)
    1) variable의 type이 잘못되었다.
    2)...
    3) INTO는 사용할 수 없다.
    4) 5)...
    INTO만 보고 찍어서 다른 문장은 기억이 잘 안남...

32. 1 CREATE OR REPLACE PROCEDURE proc_1 IS
    2 BEGIN
    3   FOR cur_record IN cur_1
          ...
    4  LOOP
    5 END
      에서 에러가 발생하는 곳 (5)
    -> END proc_1; 혹은 END; 이어야 한다.

33. 다음 문장 중 옳은 것은 (2)
    1) DELETE FROM emp
       WHERE sal = v_sal;
    2) DELETE FROM emp
       WHERE sal = &v_sal;
    3) DELETE
       DECLARE v_sal
       FROM emp
       WHERE sal = v_sal
    4) DECLARE v_sal
       DELETE FROM emp
       WHERE sal = v_sal
    5) DELETE FROM emp
       WHERE sal = :v_sal

33.  VIEW가 SELECT emp, name, id FROM emp 를 이용해서 생성되어 있다.
     sal > 3000 인 조건을 더해서 view를 보고 싶을때 어떻게 해야하는가?
     1) ALTER VIEW ~
     2) REPLACE VIEW ~
     3) DROP VIEW & CREATE VIEW
     4) 할 수 없다.

34. 1 SELECT deptno, SUM(sal) FROM emp
    2 WHERE sal > 30000
    3 GROUP BY deptno
    4 ORDER BY 1
    5 HAVING SUM(sal) >  10000;
    에서 에러가 발생하는 곳은? (이와 유사한 문제 총 2문제 출제)

35. ALTER TABLE salary
    MODIFY ( salary DEAULT 0 CONSTRAINT salary_salary_nn NOT NULL.
               deptno CONSTRAINT salary_deptno_fk FOREIGN KEY );
    에서 에러가 나는 이유 ( 테이블의 row들을 보여주는데 salary에는 null값이 존재함)
    salary에 null값이 존재하므로 not null로 변경할 수 없슴.

36. emp record의 last_name값에 Jane을 할당하는 명령? (3)
    1 last_name = 'Jane'
    2 emp_record.last_name = Jane
    3 emp_record.last_name = 'Jane'
    4 ..

37. %TYPE 에 관한 문제
    emp%TYPE이 뜻하는 것이 무엇인가?  

38. variable을 선언할때 column의 형식을 모르면 어떻게 선언하면 되는가?
    -> %TYPE

39. SELET  NVL(hire_date ,'01-MAY-91') FROM emp;
    에서 hire_date가 null이면 ? '01-MAY-91'

40. CUSTOMER, SALES, ORD, ITEM 의 ENTITY가 존재하고 CUSTOMER는 다수의 phone number
    를 갖는다. ...각 entity의 attribute 를 설명하고 반드시 존재해야 하는 attribute를 고르는 문제

41. SQL*Plus 에서 주석처리에 사용되는 것은?  ( -- )

42.. PL/SQL은 어떻게 동작하는가? b
        a. 모든 문을 procedure excutable area로 보낸다.
        b. 각각을 분리(seperate)하여 SQL excutable area로 보낸다.
        c. 모든 문을 SQL excuable area로 보낸다.
        d. 분리하여 procedure excutable area로 보낸다.

43. Table create시 foreign key로 잡힌 column이 참조하는 Table이 없을경우? (c일거 같음)
        a. FORCE option을 사용하면 된다.
        b. disable constraint
        c. 만들수없다.
      d. 참조하는 table이 없음에도 불구하고 table이 생성된다.

44. COMMENT COLUMN ON ...으로 comment를 주었을때 정보를 볼 수 있는 data dictionary는?
    -> ALL_COL_COMMENTS

45. data를 delete 하고자 한다. 이를 다시 복구하지는 않는다. 어떤 명령을 사용하는가? b
        a. delete from table            b. truncate                     c. drop

46. select  A||‘ ’||B||‘ ’||C||‘Data’ from ...에서 결과 column 수는? - 1개

47. CUSTOMER 와 BOOK 의 관계 묻기
    한 customer는 여러권의 book을 빌릴 수 있다. 빌려진 book은 반드시 빌려간 customer가 존재한다.
    customer는 book을 한권도 빌리지 않을 수 있다.
                                  1) ___________<_
           CUSTOMER     2) -----------<-        BOOK                        
                                  3) ->---_______          
                                  4) _>____-------
                                  5) ______-------<

48. DECLARE
        v_sal      number(5)   not null,
        v_name    char(25)    
    BEGIN
       SELECT name, id
       FROM emp
       WHERE sal > v_sal ;
    END
    의 실행은 어떻게 되는가?    -> v_sal가 초기화되지 않았으므로 compile되지 않는다.

49. DECLARE
       emp_record  emp%ROWTYPE
   으로 선언되었을때 emp_record.id가 initialized되지 않았다.
   ( emp의 id column은 number, not null 이다. )
    이때 emp_record.id의 값은? (2)
   1) 0
   2) NULL
   3) compile되지 않는다.

50. SELECT name FROM emp
    WHERE name LIKE ((('%s%' AND '%t%') AND '%p%' ) OR '%r%');
    에서 나타나는 name 형식은? (1)
    1) stop, start, store
    2) ...



제 2 장

1. Operator Precedure, 계산식 중 먼저 실행 되는 항목
     *  salary + 12*5 -4 => 12*5가 먼저 실행 (1-16)

2. Multiple column으로 조회했을 때 sort 순서 (실습문제) (1-38)
        SQL> SELECT last_name, dept_id, salary FROM s_emp ORDER BY dept_id, salary DESC

3. SQL 문장 중 틀린부분   = NULL => IS NULL (1-54)

4. Character Functiond 선택(Multi choice) => substr, length, nvl(2-8) lower,upper,initcap,concat

5. Data Function MONTHS_BETWEEN => return number (2-24)

6. TRUNC('25-MAY-95','YEAR')의 결과는 ? '01-JAN-95' (2-30)

7. Cartesian Product를 만들기 위해서는 WHere 절의 JOIN Condition을 삭제하면 된다. (3-6)

8. Join condition의 수는 table의 수 -1 (3-9)

9. Table Alias가 정해지면 SQL 문장 전체에서 적용해야 된다. (3-17)

10. Out Join이란? (3-21)
        - missing rows can be returned if an outer join operator is used. The operator is a
          plus sign enclosed in parentheses (+), and is placed on the "side" of the join that
          is deficient in information. The operator has the effect of creating one or more NULL
          rows, to which one or more rows from the non-deficient table can be joined.

11. Self JOIN의 예를 선택하기 (3-24) : in order to simulate two tables in the From clause.
        SQL> SELECT worker.last_name||' works for '|| manager.last_name
                 FROM s_emp worker, s_emp mansger
                 WHERE worker.manager_id = manager.id;

12. Group Function에서 Having의 역할 (4-25)     : to specify which groups are to be displayed
        - The HAVING clause may precede the GROUP BY clause, but it is recommended that
          you place the GROUP BY clause first because it is more logical. Groups are formed
          and group finctions are calculated before the HAVING clause is applied  to the groups
          in the SELECT list.
13. SUBQUERY시 single row comparision operator는 multi row를 만나면 error 2문제(5-16)
        - To correct the error, change the comparison operator to IN a multiple row operator.

14. Define variable=value 시 CHAR datatype으로 잡힘 (7-16)

15. 대소문자와 관계 없는 SQL 문 :  Where UPPER(d.name) = UPPER('&p_dname') (7-19)

16. Foreign Key로 지정되면 related column에 data가 있거나 NULL이어야된다. (8-26)

17.  Naming Rule (Must Begin with a letter, ? 안됨, comment 는 예약어) (9-10)
        - 1~30 characters long, contain A-Z,a-z,0-9,_,$,#, not duplicate the name

18. number의 default precision 은 38 (9-13)

19. precision이 변동적일때 무엇으로 선언하나 default number(p,s)는 Maximum value (9-13)

20. Table의 not null column인 경우 insert시 반드시 포함 (9-18)

21. PK는 automatically create UNIQUE index. (9-20)

22. Create a table by using a Subquery 의 올바른 예 선택 (9-30)
        SQL> CREATE TABLE emp_41
                 AS SELECT id, last_name, userid, start_date FROM s_emp WHERE dept_id=41;

23. USER_CONS_COLUMNS : View columns associated with the constraint name
    USER_CONSTRAINT : View all constraint definitions and name in table (10-12 ~ 10-15)

24. Commit & Rollback에 대한 문제 (11-36)
        - Automatic commit : DDL(create), DCL(grant), normal exit

25. Commit & Rollback에 대한 문제 (11-38) : State of the Data Before COMMIT or ROLLBACK
        - previous state of the data can be recovered  because the database buffer is affected.
        - current user can review the results on the DML by using the SELECT statement.
        - other user cannot view the results of the DML by the current user
        - affected rows are locked; other users cannot change the data within the affected rows

26. Adding a Column의 예제에 대한 설명 (12-6)
        - You can add or modify columns, but you cannot drop them from table.
        - You cannot specify where the column is appear. new columns becomes the last column.

27. Enable Constraint에 대한 설명 (12-14)
        - if enable, constraint applies to all the data in the table
        - if enable a UNIQUE or PRIMARY KEY, index is automatically crated.
        - You can use ENABLE, DISABLE clause in CRATE TABLE, ALTER TABLE
        - CASCADE disables dependent integrity constraints.

28. Create Sequence의 올바른 문법 (13-7)
        - CRATE SEQUENCE sequenct_name
                        [INCREMENT BY n]
                        [START WITH n]
                        [{MAXVALUE n | NOMAXVALUE}]
                        [{MINVALUE n | NOMINVALUE}]
                        [{CYCLE | NOCYCLE}]
                        [{CACHE n | NOCACHE}]

29. Create Sequence시 start with n이 없으면 1로 시작 (13-7)

30. Remove sequence 문법 (13-18)
        - once removed, the sequence can no logner be referened.
        SQL> DROP SEQUENCE s_dept_id;

31. Create VIEW할때 Subquery can not contain an ORDER BY clause (14-6)

32. Create View에서 With Check option시 UPDATE 할 수있는 COLUMN (14-16)
        - If you attemp to change the department number for any rows in the view, the
          statement will fail because it violates the CHECK OPTION constraint.

33. User System Privileges  (16-9)
        - create session, create table, create sequence, create view, create procedure
        SQL> GRANT [,privilege..] TO user [, user ...];

34. Role 예제에 대한 올바른 설명 (16-11) : CREATE ROLE role;
        SQL> CREATE ROLE manager;
        SQL> GRANT create table, create view TO mansger;
        SQL> GRANT manager TO velasquez, ropeburn;
  ==> Allow the managers to create tables and views. Give these privileges to Velasquez and
        to Ropeburn.

35. Create synonym 예제에 대한 올바른 설명 (16-25)
        SQL> CREATE SYNONYM s_dept FOR alice.s_dept;
   ==> As user Scott, create a private synonym named S_DEPT for Alice''s S_DEPT table.


36. PL/SQL의 global variable은 colon(:)으로 선언 (1-11)

37. EXIT를 필요로 하는 LOOP 문은 BASIC LOOP (5-17)

38. FOR LOOP에 대한 설명 (5-23)
        - Reference the index within the loop only, it is undefined outside the loop
        - Reference the existing value of an index within an expression
        - Do not reference the index as the target of an assignment

39. cursor 이용 단계 (Declare-> Open-> Fetch-> check(확인 단계)-> Close) (6-6)

40. cursor 선언시 into 있으면 안됨 (6-18)



제 3 장

1. public synonym 만드는 방법

2. Evaluation order : where -> groub by -> having

3. which task can br performed by where clause?

4. right justified 되는 datatype은?

5. where절에서 single row function에 적용될 수 있는 argument?

6. %rowtype?

7. view의 저장형태 --> select문으로 data dictionary에 저장

8. Nextval이 전형적으로 사용되는 statement?

9. exception이 발생하는 부분

10. where (sal > 30000 and sal <20000) or sal between 10000 and 15000 or
    sal in(22000,32000,48000)일때 output으로 가능한 값 2개를 choose.

11. NVL(     ,'   ')의 return값?

12. PL/SQL For loop에서 가능한 task?

13.  disabled된 PK를 reinstate시키는 alter명령은?

14. nember type의 default precision?

15. PL/SQL select 문에 into 사용안함.

16. v_salary constant number(8,2)에서 error유발하는 부분은?

17. What is Self Join?

18. Implicit commit되는 경우?

19. create table __________
     ( 3000_id
                        );
        error 유발부분은?

20. Car와 sales간의 relation?

21. Outer Join하는 경우?

22. 다음 SQL문중 Cartesian Product를 만들기 위해 삭제되어야 할 line은?

23. SQL*Plus 에서 다음 line으로 continue시키는 것은?

24. 원래 table의 모든 col이 Not Null  constraint를 가지고 있는데
        insert into _______________
        values __________________;
에서 한 col을 omit했을때 error 발생하는 이유는?

25. parameter를 accept할 수 있는 PL/SQL program은 ?
        1) anonymous block
        2) stored function
        3) client function
        4) package
        5) Trigger
        6) client trigger

26. select name, sal*12/100
        from emp;
    에서 sal이 null값을 가지고 있을때 display되는 값은?
  






제 4 장

1. Date variable의 연산 가능한 것 3가지.  => a,b,c
        a. date1 - date2                b. date1 - 3            c. date1 + 3
        d. date1 / date2                        e. date1 - (12/24)

2. Automatic commit 문은? (select, update, insert를 선택안하면 됨)      - Alter

3. create sequence 문법

4. sequence를 이용하여 다음 row를 삽입할때 ?    - sequence_name.nextval 이용

5. index drop문? - Drop index

6. PL/SQL은 어떻게 동작하는가? b
        a. 모든 문을 procedure excutable area로 보낸다.
        b. 각각을 분리(seperate)하여 SQL excutable area로 보낸다.
        c. 모든 문을 SQL excuable area로 보낸다.
        d. 분리하여 procedure excutable area로 보낸다.

7. Table create시 foreign key로 잡힌 column이 참조하는 Table이 없을경우?
        a. FORCE option
        b. disable constraint
        c. 만들수없다.

8. select .. from ... where column = (Subquery문)에서 오류가 발생하는 경우?
        - subquery의 결과 row가  없거나 2개이상 query될때.

9. select .. from ... WHERE columnA = ... ORDER BY columnB 일때 동작하는 index? a
        a. columnA                      b. columnB

10. Table에 Comment를 주고 싶을때 문법? - COMMENT TABLE ON ...

11. 자료를 rollback시킬 가능성이 있는데 delete all 하고 싶다. 어떤 방법 사용?  a
        a. delete from table            b. truncate                     c. drop

12. A가 transaction 수행후(rollback/commit안함) B에게 확인시키면?
        - B는 확인할수 없고 A만 transaction 종료가능

13. View에서 check option을 주고 update시 update할수 있는 자료는 ?  A
        Create view ...
                as select * from table_name where  salary > 45000 with check option.
        - Table 값
                Name   Salary
                ====  ====
                  A     50000
                  B        20000
                  C      30000

14. Composite index 만드는 문법?

15. select 문의 evaluation order?       - where > group by > having

16. 일반 synonym을 만들때의 결과? - only ownere 만 synonym eliminate

17. Public synonym 을 만들때의 결과? a
        a. 모든 user가 access가능
        b. only owner만 scheme 생략
        c. 모든 user에서 scheme 생략

18. parameter를 줄수 있는 function은?(2개)  a, d
        a. procedure    b. package              c. client procedure     d. client function
        e. anonymous block

19. PL/SQL에서 array variable 의 값 할당?  -  array_name(  ) := expr  => 괄호있는것

20. where 절에 올수 있는것 3가지?
        - column, expression, constant  - comparison operator           - literal

21. select 구문 중 올바른것?   - select ... into ... from where ...    

22. select  A||‘ ’||B||‘ ’||C||‘Data’ from ...에서 결과 column 수는? - 1개

23. 사용자로부터 변수를 입력받아서 출력하는것? (Declare문 불필요)
        - select ... from ... where column = &AAA;

24. [customer]와 [books]의 도식을 보고 관계나타내기?
        a.                              b.                      c.                      d.

25. NVL(hire_date, '05-JUN-98')일때 hire_date가 null이면 출력은?
        - 05-JUN-98

26. 10 of January 1998으로 출력하고자 할때 TO_CHAR의 format은?
        - TO_CHAR(date_var, 'fmDD "of" Month YYYY')

27. PL/SQL Declare에서  NOT NULL column으로 변수 정의 하고 값을 할당 안하면?
        - not complie

28. column 을 정의하고 값을 할당안하면? NULL값을 가진다.

29. not null column constraint의 table type으로 값을 정의하고 할당안하면? NULL값을 가짐
        - s_dept.id%rowtype에서

30. Cursor 문에서 잘못된 라인은?  c
        a. begin
        b.    For ..... in cursor_name
                     ....
                end loop
        c.    close cursor_name
        d. end

31. 각각의 fetch후 수행할  SQL*PLUS문?  d
        a. close        b. open c. loop initialize              d. test for existing row

32. view의 저장방법? - select statement in Dictionary

33. 한 procedure내에서 when other문이 나올수있는 개수?  - only one

34. A가 boolean일때   select .... from ... where A=SQL%NOTFOUND에서 select 결과가
    없다. A가 가지는 값은?  - TURE

35. A가 number일때 select ... from .. where A=SQL%ROWCOUNT에서 select 결과가 6 일때
   A가 가지는 값은?   - 6

36. 조건을 주고 select 하는 결과(같은 유형 3문제)
        select ... from .. .where column like '%s%' or '%t%' or '%p%' and '%r%';

37. foreign key로 reference되는 parent table의 column dept_id = 901 을 지울때 오류발생 해결책?
        - child table의 row 삭제
        - CONSTRAINT CASCADE사용

38. PL/SQL Declare시 record 가 table_name%rowtype으로 정의되었다. 이때 record의 type은?
        - table_name의 row와 같은 type.
  









제 5 장

1. %TYPE attribute

2. PL/SQL : CHAR형 변수에 값 넣는 법
   --------- := 'JANE'

3. NUMBER
   LONG
   LONG RAW
   NUMBER(p)

4.

5. create table  -------------
   ( 3000_id -----------
    .
   )
   error 나는 곳?
- Naming Rule
① 반드시 문자로 시작
② 1 ~ 30 개의 CHAR 가능
③ Contain A-Z, a-z, 0-9, $, #
④ 같은 이름 쓰지 마라
⑤ 예약어 쓰지 마라

6. SQL 문 주고 ERROR 나는 곳 찾는 문제 : 2 ~ 3 문제

7. EXIT 문 사용해야 하는(?) LOOP <- 문제는 잘 기억이 나지 않지만 보기는 기억이 나네요... ^.^
   ① IF문
   ② Basic Loop
   ③ For Loop
   ④ While Loop

8. Sequance 만드는 법
   (최소값 : 1000
    최대값 : 99999999
    Increment : 1 일때)

9. SQL%FOUND

10. WHERE절에서
    IN ( Subquery ) -> Subquery의 결과가 여러개 data 나와도 됨
    =  ( Subquery ) -> Subquery의 결과가 한개

11. SELECT -----------------
    FROM -----------
    WHERE salary IN ( SELECT salary FROM -------
                      WHERE dept_id = '3' or dept_id = '5');
    설명 맞는것 고르기...

12. Self Join은 어떤거냐?
    어떨 때 쓰는가...

13. Date 함수중 Numeric을 Return하는 것
    MONTH BETWEEN

14. DELETE, TRUNCATE, DROP의 차이점 알기

15. 자동 COMMIT되는 것 3개 고르기
    (INSERT, UPDATE, DELETE 고르면 절대 안되겠죠?!)

16. 한번 Alias 주면 그 SQL문 내에서는 Alias 사용 해야 하는 거...

17. TRUNC('25-MAY-95', 'YEAR') 의 결과 -> '01-JAN-95'

18. NVL(   ,'   ') Return 값...

19. SELECT 'A'||'B'||'C' "aaa" -------
    제목이 몇개일까요...

20. USER_COL_COLIMN등과 같은 Data Dictionary의 어느 View를 보면 되는가 하는 문제도 여럿 된 거 같어...

21. CREATE VIEW 할 때 Subquery에 ORDER BY 절이 들어가면 안됨...

22. FOREIGN키 Column이 포함된 table이 아직 존재 하지 않을 때 그 Column을 포함하는 table을 만들 때 어떻게 해야하남?

23. SELECT ----------
    FROM -------
    WHERE (((col LIKE '%s%' AND col LIKE '%t%') AND col LIKE '%p%') OR col LIKE '%r%')
    수행했을 때
    SELECT 되는 a와 그렇지 못한 a 써 놓은 것 고르기...

24. 사용자로부터 변수를 입력 받아서 SQL문을 수행하는 것
    SELECT ---------------
    FROM ------------
    WHERE column = &aaa

25. CURSOR문 선언할 때 SELECT문에 INTO문 들어가면 안됨

26. = NULL -> IS NULL로 고쳐야 맞다.

27. 사용자 정의 ERROR HANDLING...
  









제 6 장

1. 결과값이 date가 return되는것은?(choose three)
   date - 1, date + 1, date + date, date + 14/24

2. sequence table create문장중 맞는것?
   주의) default값을 확실히 알고있기를(start with는 안주면 1부터 시작..)

3. join문장(수행이 되는지여부?)
   select patient.name, doctor.name
   from people patient, people doctor
   where patient.id = doctor.id;

4. sql문 쫙 써놓고 틀린부분 찾기
   제가보기엔 alias를 지정했으면 문장 끝날때까지 사용해야 되는것으로 아는데
   아닌것 같음

5. 답을 outer join찾는 문제
   ....the name of the table without the matching rows라고 나오길래...

6. select aa, count(*) "dkdkdkd" from bbb
   where count(*) > 10
   group by aa
   having count(*) > 10;
   틀린 부분찾기(아마 이런식의 sql이었던것 같아요)

7. subquery가 두문제가 나왔는데 하나는 생각이 안나네요
   average를 구해서 어떻게 하는 문제가 있었는데
   나머지 하나는 subquery시 error발생요인(multi row가 select되면 안되지요)

8. where조건에 오는 칼럼의 값을 외부에서 입력받아 처리할때..
   where aa = &bb;

9. 어떤 테이블에 not null과 foreign key constraints가 같이 걸려 있을때,
   (foreign key column에도 not null이 걸려 있음)
   이때, 이 칼럼에 null로 해서 isrt시 어느 error가 떨어 지나요?
   -not null이 먼저입니까? foreign key constraints error가 먼저 인가요?

10.subquery 를 이용해서 table create시 not null constraint만 copy된다는
   사실을 명심하세요. 실제 문제는 sql문 써놓고 뭐라고,뭐라고 물어보는데...

11.view가 create되어있는데 문제는 어느 특정칼럼의 update는 몇시부터몇시까지만
   가능하다. 여기에 update를 하고 싶다 어떻게 해야 하나?
   - view 을 drop하고 with check option을 이용해서 recreate해서 update한다.
   - 할 수 없다
   - .....잘 생각 안남

12.user define error가 handling되는 부분은?
   declare,exception,....,...

13. entity relationship에 관한 문제가 두문제가 나왔는데, 하나는 customer와
    book의 관계, 하나는 customer,order,등 많은 얘기가 나왔는데 문제가 너무길에
    도저히 해석이 안되더군요(죄송)



[ocp | pl/sql] 기출문제 유형 분석  

■  기출문제 유형 분석
1. SQL 문을 응용한 문제가 대부분이므로 function, 연산자, 연산 우선순위등에 대하여 연습을
  많이 하는게 좋다.
   (ex)  다음 SQL 문에서 얻어지는 sales 값을 2개 고르는 문제.
         SELECT sales
           FROM sale_table
          WHERE sales > 30000 AND sales < 20000 OR
                sales BETWEEN 10000 AND 15000 OR
                sales IN (12000,16000,21000,36000);
2. SQL 문법의 단순한 암기보다 복잡한 SQL 문을 통하여 흐름에 대한 이해가 중요.
(1)  Introduction
      - SQL : SQL is ANSI Standard language and Command language  
      - SQL*Plus : Oracle Tool to execute SQL and PL/SQL statements
      - PL/SQL : Oracle procedural language for writing application logic
(2) SQL 기본 문법
      - Column Aliases
        . SELECT col_name AS aliase_name
        . SELECT col_name aliase_name
        . SELECT col_name "aliase name"
      - Concatenation  Operator
        . SELECT col_name || ' ' || col_name
        . SELECT col_name || ',' || col_name
      - NVL function
        . NVL (col_name,'01-JAN-95')
        . NVL (col_name, 0)
      - DISTINCT keywork
        . To eliminate duplicate rows in the result, include the DISTINCT key
          word
          in the SELECT clause.
      - Ordering Rows with the ORDER BY clause
        . number :  1 to 999
        . date   :  01-JAN-92 to 01-JAN-95
        . character  : A to Z
        . NULL value : last for Ascending sequences,
first for descending sequences.
      - Sorting by Multiple columns
        . ORDER BY col_naem desc, col_name;
        . SELECT col_name1, col_name2
          FROM table
          ORDER BY 1;
        . You can sort by a column that is not in the SELECT list
      - Limiting selected rows with the WHERE clause
        . Comparison operator : Logical and SQL
        . Logical : = > >= < <=
        . SQL : IN, LIKE, IS NULL, BETWEEN..AND..  
        . Logical operator : AND, OR, NOT
(3)  Literal Character strings
      - literal : character, expression, number
      - Character strings and date : ' ' 사용
      - Number values : ' ' 사용 안함
      - Character values are case-sensitive : 'ABC' 와 ‘aBC' 다르다.
      - Default Date format : 'DD-MON-YY'
(4)  SQL Operators
      - Between..in.. : range of values
      - In : Specified list
      - Like : wildcard search
         . % : None or many character
         . _ : one character
         . "%", "_" 를 사용하고 싶을 때는 ESCAPE option 사용
            =>  WHERE col_name LIKE '%X/_Y%' ESCAPE '/';
      - Rules of Precedence
        . () -> All comparison operators -> AND -> OR  
(5)  SQL*Plus
      - DESCRIBE : Display table structure
      - To continue a SQL*Plus command on the next line : hyphen(-) 사용
      - Online help : SQL*Plus commands, SQL commands, PL/SQL commands
         => SQL> HELP select
(6)  Two types of SQL functions
      - Single row functions : character, number, date, conversion
      - Multiple row functions : Group Functions
(7)  Single Row Function
      - Character functions
        . LOWER ('SQL course')      =>  sql course
        . UPPER ('SQL course')      =>  SQL COURSE
        . INITCAP ('SQL course')    =>  Sql Course
        . CONCAT ('Good','String')  =>  GoodString
        . SUBSTR ('String',1,3)     =>  Str
        . LENGTH ('String')         =>  6      
      - Number Functions
        . ROUND (45.923,-1)  =>  50
        . TRUNC (45.923,-1)  =>  40
        . MOD (1600,300)     =>  100
      - Date Functions
        . MONTHS_BETWEEN ('11-JAN-95',SYSDATE)  =>  number of months
        . ADD_MONTHS ('11-JAN-95',6)            =>  '11-JUL-95'
        . NEXT_DAY ('01-MAY-98','SUNDAY')       =>  '03-MAY-98'
        . LAST_DAY ('01-MAY-98')                =>  '31-MAY-98'
        . ROUND ('25-MAY-98','MONTH')           =>  '01-JUN-98'
        . TRUNC ('25-MAY-98','MONTH')           =>  '01-MAY-98'
      -  Arithmetic Operators on Dates
        . date + number     =>  date
        . date - number     =>  date
        . date - date       =>  number of days
        . date + number/24  =>  date
      - Conversion Functions
        . TO_CHAR (SYSDATE,'fmDD "of" Month YYYY')  =>  '15 of May 1998'
        . TO_CHAR (SYSDATE,'fmDdspth "of" Month YYYY fmHH:MI:SS AM')
           =>  'Seventeenth of June 1998 12:00:00 AM'
        . TO_NUMBER (char) : Convert a character string to a number format
        . TO_DATE ('September 7,1998','Month dd,YYYY')  =>  '07-SEP-98'
(8)  Join Methods
      - 종류
        . Equijoin
        . Non-equijoin
        . Outer-join
        . Self join
        . Set operators
      -  Cartesian Product
        . When a join condition is invalid or omitted completely, the result
          is a Cartesian product.
      - Equijoin
        . Values in the col_name on the both tables must be equal.
        . WHERE 절에서 join condition 으로 equal(=) 만 사용
        . Table aliase : If a table alias is used for a particular table name
                         in the FROM clause, then that table alias must be
                         substituted for the table name throughout the SELECT
                         statement.
      - Non-Equijoin
        . WHERE 절에서 join condition 으로 equal(=) 이외의 operator 사용
      - Outer join
        . Use an outer join to see rows that do not normally meet the join co
          ndition.
        . Outer join operator is the plus sign (+)
        . Place the operator on the side of the join where there is no value
          to join.
          (ex)  SELECT    e.last_name, e.id, c.name
                FORM      s_emp e, s_customer c
                WHERE     e.id (+) = c.sales_rep_id
                ORDER BY  e.id;      
      - Self joins
        . Join rows in a table to rows in the same table by using a self join
        . Simulate two tables in the FROM clause by creating two aliases for
          the tables
          (ex)  SELECT  worker.last_name ||' works for '|| manager.last_name
                FROM    s_emp worker, s_emp manager
                WHERE   worker.manager_id = manager.id;
(9) Group Function
      - 특성
        . Group functions appear in both SELECT lists and HAVING clauses
        . Group function : AVG, COUNT, MAX, MIN, STDDEV, SUM, VARIANCE
        . COUNT(*) 를 제외하고 모든 group function 은 NULL value 를 무시한다.
        . COUNT(*) : Including duplicates and rows with nulls
        . AVG, SUM 은 Numeric data type 에 사용, MAX,MIN 은 모든 data type 에
          사용
      - GROUP BY clause
         SELECT     col_name1, col_name2,...
         FROM       table
         [WHERE      condition]
         [GROUP BY   group_by_expression]
         [ORDER BY   col_name;]
        . Create subgroups by using the GROUP BY clause
        . 일반 column 과 group function 을 함께 썼을 경우에 GROUP BY 를 사용
          하지 않으면 Error 가 발생
        . By default, rows ard sorted by ascending order of the GROUP BY list
        . You can override this by using the ORDER BY clause
        . Can use the GROUP BY clause without using a group function in the
          SELECT list
        . Cannot use the WHERE clause to restrict groups. Use the HAVING
          clause.
        . 실행 순서 : GROUP BY  -> HAVING  -> WHERE  -> ORDER BY
          (ex)  SELECT    title, SUM(salary) PAYROLL
                FROM      s_emp
                WHERE     title NOT LIKE 'VP%'
                GROUP BY  title
                HAVING    SUM(salary) > 5000
                ORDER BY  SUM(salary) ;
(10) Subquery
      - Can place the subquery in a number of SQL command clauses
         . WHERE clause
         . HAVING clause
         . UPDATE clause
         . INTO clause of an INSERT statement
         . SET clause of an UPDATE statement
         . FROM clause of a SELECT or DELETE statement
        (ex)  SELECT   last_name, title, dept_id
              FROM     s_emp
              WHERE    last_name IN
                       (SELECT    MIN(last_name)
                        FROM      s_emp
                        GROUP BY  dept_id)
(11) SQL*Plus Command
      - File Commands : EDIT, SAVE, START, GET, SPOOL, HOST
      - Environment Commands : SET, SHOW, CLEAR
      - Format Commands : COLUMN, BTITLE, TTITLE, BREAK, COMPUTE
      
(12) Specifying Variables at Runtime
      - Use SQL*Plus substitution variables to temporarily store values
        . Single ampersand types (&)
        . Double ampersand types (&&)
        . DEFINE and ACCEPT commands
        (ex)  SELECT    id, &&col_name
              FROM      s_ord
              ORDER BY  &col_name;
      - SET VERIFY command : SQL*Plus to display the text of a command before
                             and after it replaces substitution variables
                             with values
      - Predefine variables
        . DEFINE   : Create a CHAR datatype user variable
        . UNDEFINE : Confirm undefined variables with the DEFINE command
        . ACCEPT   : Read user input and store it in a variable
          (ex)  DEFINE  dept_name = sales
                ACCEPT  p_dname PROMPT 'Provide the department name : '
                SELECT  d.name, r.id, r.name "REGION NAME"
                FROM    s_dept d, s_region r
                WHERE   d.region_id = r.id
                        AND UPPER(d.name) = '&dept_name'
                        AND UPPER(d.name) LIKE UPPER ('%&p_dname%');  
      - Passing Values into a Script File
        (ex)  SQL>  START file_name value1 value2
              SQL>  SELECT id, last_name, salary
                    FROM   s_emp
                    WHERE  id = &1 and title = '&2';
(13) Overview of DATA Modeling and DATABASE Design
      - System Development : Strategy and Analysis -> Design -> Build and
                             Document -> Transaction -> Production
      - Relationship Types
        . One-to-One
        . Many-to-One
        . Many-to-Many      
      - Normalization
        . Minimizes data redundancy
        . Reduces integrity problems
        . Identifies missing entities, relationships, and tables
(14) Create Tables
      - Naming Rules
        . Must begin with a letter
        . Can be 1-30 characters long
        . Must contain only A-Z, a-z, 0-9, _, $, and #
        . Must not duplicate the name of another object owned by the same
          user
        . Must not be an Oracle7 server reserved word
      - Constraints
        . Integrity constraints   : NOT NULL, UNIQUE, Primary Key, Foreign
                                    Key, Check
        . Column-constraint level : 모든 constraints
        . Table-constraint level  : NOT NULL constraint