Oracle
-
210902_Oracle 2021. 9. 2. 15:40
--cart1에 상품추가 insert into cart1 values(seq_shop.nextval,1,2,sysdate); --1번 나이키 추가 insert into cart1 values(seq_shop.nextval,5,1,sysdate); --5번 추가 insert into cart1 values(seq_shop.nextval,2,3,sysdate); insert into cart1 values(seq_shop.nextval,4,2,sysdate); commit; --shop에 없는 상품 추가 --오류 보고 - --ORA-02291: 무결성 제약조건(ADMIN.CART_FK_NUM)이 위배되었습니다- 부모 키가 없습니다 --없는 번호 insert into cart1 values(seq_shop.n..
-
210902_join+부모,자식테이블(예제)Oracle 2021. 9. 2. 11:42
(예제1) --cart1에 상품추가 insert into cart1 values(seq_shop.nextval,1,2,sysdate); --1번 나이키 추가 insert into cart1 values(seq_shop.nextval,5,1,sysdate); --5번 추가 insert into cart1 values(seq_shop.nextval,2,3,sysdate); insert into cart1 values(seq_shop.nextval,4,2,sysdate); commit; --shop에 없는 상품 추가 --오류 보고 - --ORA-02291: 무결성 제약조건(ADMIN.CART_FK_NUM)이 위배되었습니다- 부모 키가 없습니다 --없는 번호 insert into cart1 values(seq_..
-
210901_joinOracle 2021. 9. 1. 17:25
--student의 이름과 학과번호, department dname(학과명)으로 조인 select s.name 학생명, s.deptno1 학과번호, d.dname 학과명 from student s,department d where s.deptno1=d.deptno; --emp,dept 사원명, 근무지역으로 조인하고 학과번호가 10인 사람만 출력 select e.ename 사원명, d.loc 근무지역 from emp e, dept d where e.deptno=d.deptno and e.deptno='10'; --student와 department, professor를 조인하여 학생명, 학과명, 교수명 출력 select s.name 학생명, d.dname 학과명, p.name 교수명 from student..
-
210901_오류Oracle 2021. 9. 1. 17:11
제약조건 테이블에 부적절한 자료가 입력되는 것을 방지하기 위해서 여러 가지 규칙을 정해 놓으 것. 데이터의 무결성 유지를 위하여 사용자가 지정할 수 있는 성질 모든 constraint는 데이터 사전(dictionary에 저장됨 의미있는 이름을 부여했다면 constraiont를 쉽게 참조할 수 있음 표준 객체 명명법을 따르는 게 좋음. 제약조건은 테이블을 생성할 당시에 지정할 수도 있고, 테이블 생성 후 구조변경(alter)명령어를 통해서도 추가가 가능 not null 제약조건은 반드시 컬럼 레벨에서만 정의 가능 primary key(pk) : 유일하게 테이블의 각행을 식별(not null과 unique 조건 둘 다 만족) foreign ket(fk) : 열과 참조된 열 사이의 외래키 관계를 적용하고 설정..
-
210901_숫자함수Oracle 2021. 9. 1. 12:17
숫자함수 --abs : 절대값 --ceil : 올림 --floor : 내림 --round : 반올림 --round(숫자,자릿수) : 숫자의 소수점 이하 몇번째 자릿수에서 반올림 --round(숫자,-자릿수) : 숫자의 뒤 몇번째 자릿수에서 반올림 --power(숫자1,숫자2) : 숫자1의 숫자2승 (예제) select abs(-5), abs(5) from dual; --절대값 select ceil(2.7), ceil(2.1) from dual; --무조건 올림 select floor(2.7), floor(2.1) from dual; --무조건 내림 select round(2.7), round(2.1) from dual; --반올림 select round(123.456,2) from dual; --소수점이..
-
210901_rollup,cubeOracle 2021. 9. 1. 10:48
rollup 자동으로 소계 구하기 (예제) --professor에서 부서별,직급별, 소계 select deptno, position, count(*),sum(pay) 소계 from professor group by rollup(deptno,position); cube 자동으로 총계 구하기 (예제) select deptno, position, count(*),sum(pay) 소계 from professor group by cube(deptno,position);
-
210831_update,deleteOracle 2021. 8. 31. 14:34
update --update: 수정 --update 테이블명 set 컬럼명1='바꿀내용', 컬럼명='바꿀내용' where 조건 --직업과 나이 수정하기..where조건 안 쓰면 전체 데이터 수정됨 update person set job='공무원',age=38; --잘못 수정한 데이터 되돌리기 rollback; --5번의 직업과 나이 수정하기 update person set job='공무원',age=38 where num=5; --전체 데이터 확인 select * from person; --저장 commit; --황씨이면서 세무사인 사람의 gender를 남자로 수정 update person set gender='남자' where name like '황%' and job='세무사'; --num이 12인 사람..