상세 컨텐츠

본문 제목

[오라클]4월 13일 수업 예제 문제만

데이터베이스

by esoesmio 2023. 4. 13. 16:12

본문

-- 송강보다 부임일시가 빠른 교수들의 목록 조회
--손하늘 사원보다 급여가 높은 사원 목록
--이렇게도 할 수 있음 조은이로
--노육이라는 학생들과 학점이 같은 학생 목록 조회
-- 조인으로도 할 수 있음
 
 
--기말고사 성적이 95점 이상인 학번, 과목번호 과목명 , 성적
-- 조회하는 서브쿼리 하나 만들고

--학생테이블이랑 조인해서 학번, 학생이름, 과목번호, 과목명, 성적, 전공
 
 
 

-기말고사 성적이 95점 이상인 학번, 과목번호 과목명 , 성적
-- 조회하는 서브쿼리 하나 만들고

--학생테이블이랑 조인해서 학번, 학생이름, 과목번호, 과목명, 성적, 전공

 

 

 

 

--score, scgrade, student -> 하나의 서브쿼리

--course, professor -> 하나의 서브쿼리로 (당당교수가 없는 과목도 조회되도록)

--위 서브쿼리 테이블 2개를 다시 조인해서 결과
--기말고사의 성적을 조회할건데 담당교수가 없는 과목도 나올 수 있도록
--과목이름, 담당교수이름, 학생이름, 점수등급 함께 조회 과목번호 순서로 정렬

--2 집합 연산자
--2-1 합집합 연산자
--2000년 이후에 임용된 교수와 2000년 이후에 입사한 직원의 목록조회
pname, pno, hiredate
ename, eno, hdate
--job을 넣으면 컬럼의 갯수가 맞지 않아서 에러생김

 

 

 

 

 

 

 

--차집합 연산자
--성이 제갈이면서 지원업무를 하지 않는 사원의 번호, 사원이름, 업무 조회

 

 
 
 

 

--과목중에서 담당교수가 배정이 안됐거나 담당교수의 정보가 존재하지 않는 과목번호
-------------모르겠따 다시해부자
 
 
 

---화학과 교수중에 일반화학 수업을 하지 않는 교수들만 조회

 

 

--물리 화학과 학생 중 학점이 3.0 이상인 학생의 학번, 학생이름, 학과, 평점조회
 
 
--문자함수
--lower, upper, inicap
 

--부서명이 erp인 정보를 조회
--부서명의 대, 소문자를 모를 때

 
--문자함수
--lower, upper, inicap

 
- dept에서 dno, : dname : loc를 한번 합쳐봐라
- 프로페서 오더에서 첫번째 글자만 다 가져와봐라.
- dept에서 dname의 글자수, 바이트까지 계산해서 나오게해라
 
- select trim ('병' from '조병조') from dual; 이런식으로 병을 빼려면 어떻게해야돼
이런식으로 병을 빼봐라.
 
 
select DNO
, lower(dname)
, upper(dname)
, initcap(dname)
from dept;

select*
from dept;


--부서명이 erp인 정보를 조회
--부서명의 대, 소문자를 모를 때

select dno, dname
from dept
where lower(dname) = 'erp';

--1-2, 문자 연산 함수

--concat
select concat(dno, ':', dname, ':' || loc)

from dept;
-- 두개 이상 안됨
select dno || ':' || dname || ':' || loc

from dept;
--- 섭스트
select substr(Orders, 1, 1)
from PROFESSOR;

--서브 오라클은 첫 번째 글자부터 몇개를 가져온다
select *
from professor
where substr(Orders, 1, 1) = '정';

-- 왜안되냐 또


select *
from PROFESSOR
where substr(orders, 2, 1) = '교';

select ename
, substr(ename, 2) --두번째 글자부터 모두
, substr(ename, -2)-- 뒤에서 두번째 글자부터 모두
, substr(ename, 1, 2) --첫번째 글짜부터 두글자
, substr(ename, -2, 2) --뒤에서 두번짹 글잦부터 두글자
from emp;


--length, lengthB
select Dname, length(dname), lengthb(dname)
from dept;

--현재 오라클이 사용중인 문자셋 AL32UTF8 -> 한글 3byte
select *
FROM NLS_DATABASE_PARAMETERS
where PARAMETER = 'NLS_CHARACTERSET'
or parameter = 'NLS_NCHAR_CHARACTERSET';


--듀얼테이블 : 오라클에서 제공해주는 가상의 기본 테이블 간단하게 날짜나 연산 또는 결과값을 보기 위해 사용
--원래 듀얼 테이블 수요자는 sys로 되어있는데 모든 User에서 접근 가능

select instr('DATABASE', 'A'),
instr('DATABASE', 'A', 3),
instr('DATABASE', 'A', 1, 3)
from dual;



select instr('DATABASE', 'A'), --첫번째 A의 위치
instr('DATABASE', 'A', 3), -- 세번째 글자인 T 다음의 첫번째 A의 위치
instr('DATABASE', 'A', 1, 3) -- 첫번째 글자 D 다음의 세번쨰 A의 위치

,
sysdate
,
1 + 2
from dual;


--트림
select trim('조' from '조병조'), --both 생략, 앞뒤의 조를 제거
trim(leading '조' from '조병조'), --앞에 있는 조 제거
trim(trailing '조' from '조병조'), --뒤에 있는 조 제거
trim(' 조 병 조 ') --공백 제거
from dual;

--lpad, rpad :charset 한글을 3byte로 잡아도 컴퓨터에서는 2byte로 사용하기 때문에 한글 연산자체는 2byte로 진행된다.

select lpad(ename, 10, '*'), --사원명 뒤에 *을 붙여서 총 길이를 10으로 만듬
rpad(ename, 10, '*') --사원명 앞에 *을 붙여서 총 길이를 10으로 만듬
from emp;


--직원이름을 출력하는데 마지막 글자만 제거해서 출력(substr, length)


select ename
, substr(ename, 2) --두번째 글자부터 모두
, substr(ename, -2)-- 뒤에서 두번째 글자부터 모두
, substr(ename, 1, 2) --첫번째 글짜부터 두글자
, substr(ename, -2, 2) --뒤에서 두번짹 글잦부터 두글자
from emp;

select Dname, length(dname), lengthb(dname)
from dept;

select ename, substr(ename, 1,length(ename)-1)
from emp;
select professor.*  from PROFESSOR professor where professor.HIREDATE <
                                                   (select HIREDATE from professor  where PNAME = '송강');

select emp.* from emp emp where emp.SAL > (select sal from emp where ENAME = '손하늘');

select student.* from student student where student.AVR = any (select avr from student where sname = '노육');

select student.sno, student.sname, course.cno, course.cname, score.result, student.major from STUDENT student, course course, score score where student.SNO = score.SNO and course.CNO = score.CNO and score.RESULT = 95
;
select student.sno, student.sname, student.major from student student, (select b.sno, b.sname, course.cno, course.cname, score.result, b.major from STUDENT b, course course, score score where b.SNO = score.SNO and course.CNO = score.CNO and score.RESULT = 95) A   where student.sno = A.SNO ;

select professor.* from professor professor, course course where professor.PNO = course.PNO and course.Cname != '일반화학' and professor.section = '화학' ;

select  student.* from student student where student.major in ('물리','화학') and student.AVR>=3;

select * from emp;

select * from DEPT
;

select emp.* from emp emp, dept dept where emp.DNO = dept.DNO and dept.DNAME = 'ERP';
select professor.*  from PROFESSOR professor where professor.HIREDATE <
                                                   (select HIREDATE from professor  where PNAME = '송강');

select emp.* from emp emp where emp.SAL > (select sal from emp where ENAME = '손하늘');

select student.* from student student where student.AVR = any (select avr from student where sname = '노육');

select student.sno, student.sname, course.cno, course.cname, score.result, student.major from STUDENT student, course course, score score where student.SNO = score.SNO and course.CNO = score.CNO and score.RESULT = 95
;
select student.sno, student.sname, student.major from student student, (select b.sno, b.sname, course.cno, course.cname, score.result, b.major from STUDENT b, course course, score score where b.SNO = score.SNO and course.CNO = score.CNO and score.RESULT = 95) A   where student.sno = A.SNO ;

select professor.* from professor professor, course course where professor.PNO = course.PNO and course.Cname != '일반화학' and professor.section = '화학' ;

select  student.* from student student where student.major in ('물리','화학') and student.AVR>=3;

select * from emp;

select * from DEPT
;

select emp.* from emp emp, dept dept where emp.DNO = dept.DNO and dept.DNAME = 'ERP';

select * from dept;

select dno, lower(dname), upper(dname), initcap(dname) from dept;

select dno, upper(dname), lower(dname), initcap(dname) from dept;

select dno, dname from dept where lower(dname) = 'erp';

select concat(dno, ':',dname, ':'||loc) from dept;


select concat(dno|| ':'||dname,loc) from dept;

select dno || dname || loc || director from dept

;select * from professor;

select substr(Orders, 1,1) from professor;


select substr (orders,1,1) from PROFESSOR where substr(ORDERS,1,1) = '정';

select ename, substr(ename, 2) from EMP;

select * from dept;

select dname, length(dname), lengthb(dname) from dept;

select 1+2 from dual;

select trim('조' from '조병조') from dual;

select trim ('병' from '조병조') from dual;
SELECT REPLACE('조병조', '병', '') FROM dual;

select ename, substr(ename,2) from emp;


select ename, substr(ename,2)from emp;

 

관련글 더보기

댓글 영역