ABOUT ME

초보 개발자의 일기장입니다. 배운 것들을 정리하며 복습하는 시간을 갖기 위해 개설했습니다.

Today
Yesterday
Total
  • DATABASE - 10장 데이터 조작어 연습문제
    oracle/10장_데이터 조작어 2022. 12. 8. 17:02

    문제 1번) 교수 번호, 이름, 학과 번호를 제외한 칼럼은 NULL을 가지도록 묵시적인 방법과 명시적인 방법으로 교수테이블을 입력하고 select 하십시오.

     

    묵시적인 방법 :  해당 칼럼의 값을 생략하면 된다

    insert into professor (profno, name, deptno)
    values (9911, '이순신', 201);

     

    명시적인 방법: null 값을 넣어준다

    insert into professor
    values(9911, '이순신', null, null, null, null, null, 201);

     

    select * from professor where profno = 9911;

     

     

    문제 2) 문제1에서 입력한 데이터 값을 수정하시오. ( 사용자 아이디: sunshine, 입사일 : 2005/01/01)

    update professor
    set userid = 'sunshine', hiredate =  to_date('2005/01/01', 'YYYY/MM/DD')
    where profno = 9911;

     

    문제 3) 이순신 교수의 직급은 사용자 아이디가 'Pascal' 인 교수와 동일하게 하고,

                 급여는 교수번호가 '9908'인 교수와 동일하게 하시오.

     

    update professor
    set position = (select position
                    from professor
                    where userid = 'Pascal'),
        sal = (select sal
              from professor
              where profno = '9908');

    문제 4) 3번까지 수행한 후  새로운 세션(sql*plus를 사용하여 동일 사용자로 로그인하여 생성하는 세션)을 오픈하여 교수 테이블을 확인하시오.

    commit 사용

     

    문제 5) 현재까지 생성한 데이터 (이순신)을 삭제하시오

    DELETE FROM PROFESSOR WHERE PROFNO=9911;

     

    문제 6) 보직수당이 null 인 교수(직급모두포함)의 보직수당을 최소 보직수당을 받는 교수와 동일하게 수정해주시오.

     

    update professor
    set comm = (select min(comm)
                from professor)
    where comm is null;
    select *
    from professor
    where comm = (select min(comm)
                  from professor);

     

     

    문제 7) 학생 테이블에서 1학년 학생을 검색해서 키 정보를 height_info 테이블에 삽입하고,

                몸무게 정보는 weight_info에 입력하시오 (단, 기존 테이블에 레코드를 전부 삭제하고 삽입하시오)

     

    테이블 안의 레코드를 전부 삭제

    delete from weight_info;
    delete from height_info;

     

    테이블이 없는 경우 생성해주기

    create table height_info(
    studno number(5),
    name  varchar(10),
    height number(5,2));
    
    create table weight_info(
    studno number(5),
    name  varchar(10),
    weight number(5,2));

     

    student 테이블에 1학년의 정보만을 info에 정보 담아주기

    insert all
    into height_info values(studno, name, height)
    into weight_info values(studno, name, weight)
    select studno, name, height, weight
    from student
    where grade = '1';
    select * from weight_info;
    select * from height_info;

    weight_ifno / height_info

     

    문제 8) 시퀸스를 설명하시오.

      - 기본 키 값을 자동 생성하기 위해 필요한 일련번호를 생성하기 위한 객체

     

     

    문제 9) 1. '시작값 :2 ,최대값:100,증가치:2'를 만족하는 시퀀스(s_board)를 생성하시오.

    2. 생성후 s_board를 검색하시오.

    3. 일련번호를 확인 하세요.

    4. 생성한 시퀀스를 삭제하시오.

     

    create sequence s_board
    increment by 2
    start with 2
    maxvalue 100;
    
    select *
    from user_sequences
    where sequence_name = 's_board';
    
    select s_board.currval from dual;
    
    select s_board.nextval from dual;
    
    drop sequence s_board;

     

    'oracle > 10장_데이터 조작어' 카테고리의 다른 글

    시퀸스  (0) 2022.12.08
    pivotion insert  (0) 2022.12.08
    데이터 조작어  (0) 2022.12.08
Designed by Tistory.