/*글자크기변경
Editor > Display > Fonts*/
--문법 SELECT [컬럼명 또는 표현식] FROM [테이블명, 뷰명]
--epm테이블의 모든 컬럼 조회하기
SELECT * FROM emp;
SELECT * FROM dept;
SELECT * FROM bonus;
SELECT * FROM salgrade;
--사용자(hr)계정의 전체 테이블모록을 조회한다.
SELECT * FROM tabs;
--테이블 구조를 확인한다.DESC[Describe]
Desc emp;
Desc dept;
Desc bonus;
Desc salgrade;
--원하는 컬럼만 조회하기
SELECT empno, ename FROM emp;
--부서테이블에서 부서명만 출력하세요
SELECT * FROM tabs;
SELECT dname FROM dept;
-- 실습* 사원의 입사일/급여 출력하기
SELECT * FROM emp;
SELECT ename, hiredate FROM emp;
SELECT ename, sal FROM emp;
--일괄처리[F5], 현재커서 또는 범위[F9]
--교수테이블에서 교수이름뒤에 good moring~~! 라고 출력하세요.
--컬럼의 별명을 "Good morning"이라고 하세요.
SELECT * FROM tabs;
SELECT * FROM professor;
SELECT name FROM professor;
SELECT name, 'Good morning~~!' "Good Morning" FROM professor;
--부서테이블에서 부서명과 It's deptno : ', deptno "DNAME AND DEPTNO"을 출력하시오
--"쌍따옴표는 별칭에서 띄어쓰기를 했을 때 사용한다.
SELECT * FROM dept;
SELECT dname,'It''s deptno : ', deptno "DNAME AND DEPTNO" FROM dept;
--오라클에서 q와 []를 이용하여 ' 작은 따음표를 출력해보자
SELECT dname,q'[It's deptno : ]', deptno "DNAME AND DEPTNO" FROM dept;
--컬럼의 별칭 사용하여 출력하기
--교수테이블에서 교수번호, 이름, 급여를 출력하세요
SELECT * FROM professor;
SELECT profno "Prof'NO", name AS"Prof's NAME", pay as Prof_Pay FROM professor;
--테이블이름에 별명사용하기
--테이블명의 첫글자 또는 단어와 단어사이의 글자를 적는다.
SELECT profno, name, pay FROM professor;
SELECT p.profno, p.name, p.pay FROM professor p;
SELECT * FROM tabs;
DESC dept;
DESC emp;
SELECT ename, deptno FROM emp;
SELECT * FROM dept;
--DISTINCT 명령어로 중복된 값을 제거하고 출력하기
--emp테이블로부터 부서번호를 출력하세요.
--단 중복된 값은 제거하세요.
SELECT DISTINCT deptno FROM emp;
--emp테이블에 job, ename컬럼을 출력하세요.
--[문법] SELECT [컬럼명] FROM 테이블명 ORDER BY절
SELECT job, ename FROM emp
ORDER BY 1, 2;
SELECT DISTINCT job, ename FROM emp
ORDER BY 1, 2;
--연결연산자로 컬럼을 붙여서 출력하기
--emp테이블에서 ename과 job을 하나의 컬럼으로 출력하세요.
SELECT ename|| job FROM emp;
--SMITH's job is CLERK 처럼 출력하세요.
SELECT ename || '''s job is' || job FROM emp;
--SELECT '010', '8654', '3420' FROM dual;을 실행하여 010-8654-3420로 출력하세요.
SELECT '010','8654','3420' FROM dual;
SELECT '010'||'-'||'8654'||'-'||'3420' FROM dual;
-- dual - 가상테이블
-- 테이블이 없을때 임시로 붙여주는 테이블
SELECT 1+2 From dual;
-- SELECT sysdate FROM dual; 시간 테이블
--Student테이블에서 모든 학생의 이름과ID,체중을 아래 화면과 같이 출력하세요. 컬럼이름은 "ID AND WEIGHT"로 나오게 하세요.
SELECT * FROM student;
SELECT name || '''s ID : ' || id ||', WEIGHT is ' || weight || 'Kg' AS "ID AND WEIGHT" FROM student;
SELECT name || q'['s ID : ]' || id ||', WEIGHT is ' || weight || 'Kg' AS "ID AND WEIGHT" FROM student;
--emp테이블을 조회하여 모든 사람의 이름과 직업을 아래와 같이 출력하세요.
SELECT * FROM emp;
SELECT ename, job FROM emp;
SELECT ename || '('|| job || '),' || ename || '''' || job || '''' FROM emp;
SELECT ename || '('|| job || '),' || ename || q'[']' || job || q'[']' "NAME AND JOB"FROM emp;
--emp테이블을 조회하여 모든 사원의 이름과 급여를 아래와 같은 형태로 출력하세요.
SELECT ename, sal FROM emp;
SELECT ename || q'['s sal is ]' || '$' || sal "NAME and Sal" FROM emp;
create table professor
(profno number(4) primary key,
name varchar2(10) not null,
id varchar2(15) not null,
position varchar2 (10) not null,
pay number (3) not null,
hiredate date not null,
bonus number(4) ,
deptno number(3),
email varchar2(50),
hpage varchar2(50)) tablespace users;
insert into professor
values(1001,'조인형','captain','정교수',550,to_date('1980-06-23','YYYY-MM-DD'),100,101,'captain@abc.net','http://www.abc.net');
insert into professor
values(1002,'박승곤','sweety','조교수',380,to_date('1987-01-30','YYYY-MM-DD'),60,101,'sweety@abc.net','http://www.abc.net');
insert into professor
values (1003,'송도권','powerman','전임강사',270,to_date('1998-03-22','YYYY-MM-DD'),null,101,'pman@power.com','http://www.power.com');
insert into professor
values (2001,'양선희','lamb1','전임강사',250,to_date('2001-09-01','YYYY-MM-DD'),null,102,'lamb1@hamail.net',null);
insert into professor
values (2002,'김영조','number1','조교수',350,to_date('1985-11-30','YYYY-MM-DD'),80,102,'number1@naver.com','http://num1.naver.com');
insert into professor
values (2003,'주승재','bluedragon','정교수',490,to_date('1982-04-29','YYYY-MM-DD'),90,102,'bdragon@naver.com',null);
insert into professor
values (3001,'김도형','angel1004','정교수',530,to_date('1981-10-23','YYYY-MM-DD'),110,103,'angel1004@hanmir.com',null);
insert into professor
values (3002,'나한열','naone10','조교수',330,to_date('1997-07-01','YYYY-MM-DD'),50,103,'naone10@empal.com',null);
insert into professor
values (3003,'김현정','only-u','전임강사',290,to_date('2002-02-24','YYYY-MM-DD'),null,103,'only_u@abc.com',null);
insert into professor
values (4001,'심슨','simson','정교수',570,to_date('1981-10-23','YYYY-MM-DD'),130,201,'chebin@daum.net',null);
insert into professor
values (4002,'최슬기','gogogo','조교수',330,to_date('2009-08-30','YYYY-MM-DD'),null,201,'gogogo@def.com',null);
insert into professor
values (4003,'박원범','mypride','조교수',310,to_date('1999-12-01','YYYY-MM-DD'),50,202,'mypride@hanmail.net',null);
insert into professor
values (4004,'차범철','ironman','전임강사',260,to_date('2009-01-28','YYYY-MM-DD'),null,202,'ironman@naver.com',null);
insert into professor
values (4005,'바비','standkang','정교수',500,to_date('1985-09-18','YYYY-MM-DD'),80,203,'standkang@naver.com',null);
insert into professor
values (4006,'전민','napeople','전임강사',220,to_date('2010-06-28','YYYY-MM-DD'),null,301,'napeople@jass.com',null);
insert into professor
values (4007,'허은','silver-her','조교수',290,to_date('2001-05-23','YYYY-MM-DD'),30,301,'silver-her@daum.net',null);
commit;
create table student
( studno number(4) primary key,
name varchar2(30) not null,
id varchar2(20) not null unique,
grade number check(grade between 1 and 6),
jumin char(13) not null,
birthday date,
tel varchar2(15),
height number(4),
weight number(3),
deptno1 number(3),
deptno2 number(3),
profno number(4)) tablespace users;
insert into student values (
9411,'James Seo','75true',4,'7510231901813',to_date('1975-10-23','YYYY-MM-DD'),'055)381-2158',180,72,101,201,1001);
insert into student values (
9412,'Rene Russo','Russo',4,'7502241128467',to_date('1975-02-24','YYYY-MM-DD'),'051)426-1700',172,64,102,null,2001);
insert into student values (
9413,'Sandra Bullock','Bullock',4,'7506152123648',to_date('1975-06-15','YYYY-MM-DD'),'053)266-8947',168,52,103,203,3002);
insert into student values (
9414,'Demi Moore','Moore',4,'7512251063421',to_date('1975-12-25','YYYY-MM-DD'),'02)6255-9875',177,83,201,null,4001);
insert into student values (
9415,'Danny Glover','Glover',4,'7503031639826',to_date('1975-03-03','YYYY-MM-DD'),'031)740-6388',182,70,202,null,4003);
insert into student values (
9511,'Billy Crystal','Crystal',3,'7601232186327',to_date('1976-01-23','YYYY-MM-DD'),'055)333-6328',164,48,101,null,1002);
insert into student values (
9512,'Nicholas Cage','Cage',3,'7604122298371',to_date('1976-04-12','YYYY-MM-DD'),'051)418-9627',161,42,102,201,2002);
insert into student values (
9513,'Micheal Keaton','Keaton',3,'7609112118379',to_date('1976-09-11','YYYY-MM-DD'),'051)724-9618',177,55,202,null,4003);
insert into student values (
9514,'Bill Murray','Murray',3,'7601202378641',to_date('1976-01-20','YYYY-MM-DD'),'055)296-3784',160,58,301,101,4007);
insert into student values (
9515,'Macaulay Culkin','Culkin',3,'7610122196482',to_date('1976-10-12','YYYY-MM-DD'),'02)312-9838',171,54,201,null,4001);
insert into student values (
9611,'Richard Dreyfus','Dreyfus',2,'7711291186223',to_date('1977-11-29','YYYY-MM-DD'),'02)6788-4861',182,72,101,null,1002);
insert into student values (
9612,'Tim Robbins','Robbins',2,'7704021358674',to_date('1977-04-02','YYYY-MM-DD'),'055)488-2998',171,70,102,null,2001);
insert into student values (
9613,'Wesley Snipes','Snipes',2,'7709131276431',to_date('1977-09-13','YYYY-MM-DD'),'053)736-4981',175,82,201,null,4002);
insert into student values (
9614,'Steve Martin','Martin',2,'7702261196365',to_date('1977-02-26','YYYY-MM-DD'),'02)6175-3945',166,51,201,null,4003);
insert into student values (
9615,'Daniel Day-Lewis','Day-Lewis',2,'7712141254963',to_date('1977-12-14','YYYY-MM-DD'),'051)785-6984',184,62,301,null,4007);
insert into student values (
9711,'Danny Devito','Devito',1,'7808192157498',to_date('1978-08-19','YYYY-MM-DD'),'055)278-3649',162,48,101,null,null);
insert into student values (
9712,'Sean Connery','Connery',1,'7801051776346',to_date('1978-01-05','YYYY-MM-DD'),'02)381-5440',175,63,201,null,null);
insert into student values (
9713,'Christian Slater','Slater',1,'7808091786954',to_date('1978-08-09','YYYY-MM-DD'),'031)345-5677',173,69,201,null,null);
insert into student values (
9714,'Charlie Sheen','Sheen',1,'7803241981987',to_date('1978-03-24','YYYY-MM-DD'),'055)423-9870',179,81,102,null,null);
insert into student values (
9715,'Anthony Hopkins','Hopkins',1,'7802232116784',to_date('1978-02-23','YYYY-MM-DD'),'02)6122-2345',163,51,103,null,null);
commit;