5월, 2018의 게시물 표시

(오라클) 뷰 + 조인 예제

이미지
hr계정에서 자신이 소유한 정부중에서 사원번호, 이름 , 메일주소, 전화번호, 직책명, 부서명을 임의의 사용자(내 경우에선 imsihyun)에게 조회만 가능하도록 권환을 부여하시오 아물로 임의의 사용자 계정으로 접속후 결과를 확인하세요. 먼저 이걸 해석할수 있는 순서를 나눠보자 1. join 하기 2. join 한 view를 만들기 3. 권한 주기 더 디테일하게 선생님이 써주신 글들을 여기 아래다가 써놨다 요구사항을 분석 자료의 접근에 관련된 사항이기때문에->table,view라는 객체가 작업의 대상이 된다. 각각 테이블 또는 뷰에서 원하는 정보를 얻기위해 필요한 객체가 무엇 인지를 파악하자. 고려사항!!!!!!!!!!! 완전 중요!!! NULL에 대한 고찰이 필요하다!!!!!!!!!!!!!!!! null은 departmentname에 null이란 값이있다. 이게 고려사항이다. null 무시 -> inner join 하기 null x무시 -> outer join 하기 ansi표준의 쿼리를 통한 조인을 할것인지 결정하자 join에 대해서는 이미 써줬다.  hr 계정에 있는 우리가 불러와야하는 테이블들은... employees 테이블 안에있는것들 사원번호 -> employees_id 이름 -> first_name, last_name 메일주소 ->email 전화번호->phone_number departments 테이블 안에 있는것들 부서명 -> department_name jobs 테이블 안에 있는것들 job_title 이걸 먼저 다 조인해서 할것이다. SELECT employees.employee_id, employees.first_name, employees.last_name, employees.email, departments.department_name,jobs.job_title FROM employees, d...

(오라클) join

이미지
WE use DB for enterprise decision. select sum(salary) as total from employees;  select max(salary) from employees; max->최대 select count(employee_id) from employees; select count(commission_pct) from employees; select count(*), department_id from employees group by department_id; select- 고르다 count(*) - 모두다 센다 department_id를  어디서? employees 에서 department_id 부서별로. select avg(salary) ,department_id, count(*)  인원수 from employees group by department_id; avg(salary) -> 평균 월급 department_id -> 부서 아이디 를 출력하고, count(*) 인원수 -> 인원수를 다 세고 group by department_id-> 부서별로 나눈다 select round( avg(salary) ) ,department_id,count(*)인원수 from employees group by department_id; real number -> integer we use round() ' select * from departments where department_id = 90; join join type -> inner/outer/ inner join  inner  join, The method to join the same data in the two diff...

(오라클) view/뷰

이미지
"view" view isn't a physical table, it is virtual (default) table that doesn't actually store the data. DB developer should know how to use view in DB oracle, as the DB developer able to restrict the table that can be viewed by selected individuals/groups. We gonna enter to 'hr' account to create a view. The formula for view: create view view_name as select first_name, last_name, email, hire_date from employees; The detailed formula for the view create (or replace) [{force | no force }] view view_name as [with check option] [with read only];  1. create or replace actually, you can just use create only. but if you use replace with the create, you can create&edit the view at the same time. 2. force | no force you can force to create view even if you don't have default table. 3. with check optino you can use check option to use update and insert in the selected area 4. with read only you cannot edit the view with CRUD oper...

(오라클) Sequence/시퀸스의 활용과 개념

이미지
"왜 우린 오라클에서 시퀸스를 써야하는가?" 매일 오라클 사용자가 insert을 써서, 값을 일일이 타이핑 하는것도 노가다다. 우리 인간은 똑똑하기 때문에, sequence라는 걸 만들어서 자동화가 되게 만들었다. 간단한 규칙과 몇개의 숫자면 자동화가 된다는 얼마나 time-saving이라는 것 인가. 수학이랑 똑같다. 1, 2 , 3, 4, 5, 6...100 이 시퀸스를 보면 무슨 생각이 드는가? 수학적으로 해석하면, 1부터 시작, 100이 끝 +1 만큼 순환 x 이걸 우리는 영어로 쓸것이다. "시퀸스는 어떻게 써야하는가?" 아무 계정에서, create table 을 해서 sequence 을 만들것이다. create table emp01(     empNo number(13) primary key,       name varchar2(50) not null,     hire_date date ); sequence을 만드는 방법이 두가지가 있는데, 하나는 일일히 입력해서 만드는 것이고, create sequence emp_SEQ minvalue 1 //최솟값 maxvalue 999999999999999999 // 최대값 increment by 10 //증가값 start with 10 //10부터 시작 nocycle; //주기 없음 또 하나느 테이블을 펼쳐서 시퀸스를 눌러주고, 값을 입력해주면 된다. 시퀸스-> 오른쪽 마우스 클릭 -> 새 시퀸스 테이블에서 행을 집어넣을때 insert으를 쓴다 insert into emp01(empNo, name, hire_date) values(emp_SEQ.nextval,  'lucky', sysdate); 시퀸스에서 다른 insert 처럼 값을 바꿔서 넣지 않아도 된다 왜냐하면, 시퀸스에서 lucky란 이름은 중복되어도 되서 ...

(오라클+자바) 데이타베이스에 데이타 변경 하는 프로그램 만들기

이미지
We will make a program to edit the database in the oracle with the help of java. This will be our program templates. We will gonna make package and class like this. EmpMain In the main, we gonna introduce our first sentence in our program. We use switch ... case () sentence to build our front page of our program. if you enter 1 -> the prg will activate InsertEmp(); if you enter 2 -> the prg will activate UpdateEmp(); if you enter 3 -> the prg will activate SelectEmp(); if you enter 4 -> the prg will activate DeleteEmp(); if you enter nth -> the prg will go back to the first page of our program. EmpProcess This is prg foundation to act as a branch between main and insert/delete/update/select .  EmpDAO url is to oracle through IP address. uid and pwd is for oracle's account name and password, that you have already created. publuc EmpDAO is the must to write. pstmt = con.prepareStatement("insert (?,?,?,?,sysdate,?)...

(오라클) 데이타베이스를 만들기

이미지
1. table-space 만들기      table을 만든다 (DBMS 에 접속) 자료를 형식화 해서 table을 저장한다      table의 구조에 맞게 DTO.Clash을 만든다.      접근제어자 - private - table 컬럼과 일치하게 만든다 2. 계정 부여 받기      그리고선, source 메뉴에 가서 이렇게 하나하나씩 눌러준다.      getter- setter method 만들기      class에 serializable 을 만든다      toString & equals hashCode -> override  3. 권한 부여 받기 DAO class creation D- Data A- Access O- Object DB에서 CRUD 작업을 위한것, | classname | | DAO |  CRUD 작업을 위해서 필요한것 Driver (DBMS driver oracle driver- > ojdbc6.zip ) connection object is needed -> URL, id, pw 필요 명령 실행 객체가 필요함.-> prepared statement object is needed 실행 하면됨 -> 근데 결과가 2가지 종류가 있음 1st result - > single data -> int 2nd result -> bundle data -> ResultSet 형식 - >select 작업 DAO client  xxxVO->domain 영어겡 해당된다 domain0>전번에 걸쳐서 사용되는 class  전번->모든 class 데이타에 접근하...

(오라클+자바) 데이타베이스에 데이타 올리기-04

이미지
이제 hr계정에서 lucky 계정으로 옮길것이다. hr 계정 grant select on employees to lucky; lucky 계정 create table emp as      select employee_id as emp_id, First_Name || ' ' || Last_Name As irum,email,phone_number as phone,          hire_date as hidate, salary as pay from hr.employees;  desc emp; select * from emp; desc emp; select * from emp; create table emp2 as select * from emp where 0 > 5; select * from emp2; desc emp2; alter table emp2     add constraint emp2_pk primary key(emp_id) ; JAVA -> package lucky; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class EmployeeProcess {       public static void main(String[] args) {          Connection con = null;          Statement stmt = null;         ...

(오라클) View(뷰) + where/order by/like/is/() / in 사용방법 예제

이미지
먼저  hr 계정에 접속하자, hr 계정에 접속한뒤, hr에 이미 들어있던 테이블을 볼려면, select * from tab; 이제  VIEW 라는 걸 볼것이다. 그럼 VIEW 라는게 무엇일까? select ~ from @ @ 이 안에는 뭐가 들어갈수 있을까? 1. table view 2. virtual table 들만 들어갈수 있다. ~안에는 @이라는 테이블 컬럼 리스트를 추가적인 컬럼을 생성할수 있다. 그러니까 새로운 컬럼을 생성할수 있다는 이야기다. select * from employees; 이렇게 뜬다 *가 모든 컬럼 명 이란 뜻이다. 만약 성명과 이메일만 보고싶다면 select first_name, last_name, email from employees; 라고 하면 된다. select '회사명 : (주)상점', emp.*from employees emp; 을 적으면 employee_id 앞에, '회사명: (주)상점' 이라는 컬럼들이 생성된다. select employee_id, first_name || ' ' || last_name 성명, email as 이메일, phone_number, salary, department_id from employees; || ' ' ||은 first_name 과 last_name을 이어주는것이다. blank (공백)도는  as~ 은 닉네임을 주는것이다. 그럼 email>>이메일로 바뀌고, first_name || ' ' || last_name >> 성명 이라고 바뀐다. salary란 뜻은 1달치 급여다 wage 란 뜻은 1년치 급여다. salary*12 -> wage 라는 뜻이다 select employee_id, first_name, salary*12 wage from employees; ...