목록전체 글 (35)
5시간코딩
1. oracleDriver를 깔아야 한다. 2. RJDBC패키지는 java로 만들어졌기 때문에 rJava 패키지를 설치해야하는데, 이를 위해서 Java 64비트가 깔려있어야 한다. 하지만 패키지로 깔면 32비트가 깔린다. 그래서 Java 홈페이지 가서 64비트 정상적으로 깔고 하면 잘된다. 시간 얼마 안걸리니 Java 홈페이지 가서 그냥 깔자 3. 엄청난 문제는... connection 시 disconnection하지않고 계속 사용하면 oracle 접속이 안끊기고 계속 누적되어있다. 파이썬으로 실험해봤을 땐, disconnect 하지않고 connect 만 엄청 날려도 기존 connection이 자동으로 해제되고 새로 connect 됐었다. 그런데 RJDBC connection 하는 만큼 계속계속 con..
1. 기존 테이블명을 다른 이름으로 변경 1) DROP TABLE emp PURGE; 2) ALTER TABLE emp RENAME TO emp_tmp; 2. CTAS 로 테이블 복제( 컬럼명을 명시적으로 적어줘서 순서를 원하는 대로 바꿔준다) CREATE TABLE emp AS (SELECT A.id, A.name, A.deptcd, B.deptname FROM emp_tmp A, dept A WHERE A.deptcd = B.deptcd); * 같은 방법으로 테이블에 컬럼을 추가해서 다른 테이블에 ctas 할 때 컬럼명을 잘 지정해줘서 하는 방법을 응용할 수 있다.
1. Process로 직접 RTest.R 을 실행시키기 string RScriptPath = @"C:\Program Files\R\R-3.4.2\bin\x64\Rscript.exe"; string RCodeFilePath = @"C:\RTest.R"; ProcessStartInfo pstInfo = new ProcessStartInfo(RScriptPath, RCodeFilePath); pstInfo.UseShellExecute = false; pstInfo.RedirectStandardOutput = true; Process.Start(pstInfo); Console.WriteLine("R Done!!"); 2. R 연동시킨 후 RTest.R을 불러오는 RCode 작성하기 string path = @"..
Sys.setlocale("LC_ALL","C") # 강제 언어 삭제 read.csv(~~~) Sys.setlocale("LC_ALL","Korean") # 언어 다시 한글로 다른 블로그에 이 글 올려주신분 감사합니다.
평일엔 하나의 코드에 어쩔땐 VALUE1, VALUE2, VALUE3이 들어가고 주말엔 VALUE1, VALUE4, VALUE5 가 들어가고 어쩔땐 VALUE1, VALUE2, VALUE3, VALUE4, VALUE5 다 들어가고 추후에 VALUE6이 추가될 수도 있고 VALUE3을 안쓸 수도 있고 이렇게 가변적일 때, 할 수 있는 방법들이다. 1. VALUE 하나의 컬럼으로 하여 아래 로우를 VALUE1, VALUE2, VALUE3 ... 으로 추가하는 방법. 아마 현업에서 많이 쓰는 방법이 아닐까싶다. ROW수가 배가 되어 많아 진다는 단점이 있다. 2. TABLE 2개로 유지하는 방법 TABLE1 : 값이 들어가는 테이블, TABLE2 : 컬럼을 매핑하는 테이블로 해서... TABLE2에 TABLE..
현재 글쓴 날짜는 2019년이다. 2019년 데이터를 돌릴 때는 아무 이상없이 돌아가던 쿼리가 2013년~2019년으로 범위를 넓게 해서 돌리니까 없던 에러가 생겼다. 심지어 오라클에서 에러가 발생한 부분이라고 표시해준 부분도 완전 이상한 곳이더라... 원인은... 사용하던 테이블 중 가장 컸던 테이블이 2000만row짜리가 있었는데, 사용했던 컬럼 중에 문자형식으로 된 날짜가 있었는데, 그 중 '20140631' 이라는 row가 6개 정도 있었다. 6월달은 30까지 밖에 없다... 날짜로 바꾸니 에러가 날 수 밖에 없다. 날짜는 자동으로 박힐텐데 왜 이런 이상한 날짜가 들어갔는지는 알 수 없었다. 뭐 어쨋든.. 타부서에 수정요청했지만, 안된다는 반응이어서 어쩔 수 없이 하드코딩으로 CASE WHEN d..

1. 아나콘다 기본제공 64비트에서 사이보스가 연결이 안되서 확인해보니 32비트에서만 된다고 한다. 그래서 기왕 이렇게 된 거 파이참으로 옮겨볼까하다가 아나콘다에서 32비트 설치방법 아주 쉽게 설명해주신 블로그 보고 그냥 쓰기로 했다. 참고 블로그 : "64비트 아나콘다에서 32bit 파이썬 설치하는 방법" 1) 아나콘다 프롬프트로 접속 ( 스파이더 아나콘다 아님 ) 1 2 3 4 5 6 7 8 9 set CONDA_FORCE_32BIT = 1 conda create -n py_37_32 python=3.7 anaconda # 2019-10-06 기준 3.7버전을 사용함 # 다운로드를 한 15분 정도 하면 끝난다. activate py37_32 # 그리고 C:\Anaconda3\envs\py37_32\p..
1. oracle 1) employees와 departments를 join하세요. 단, employees의 모든 행을 출력하세요. (1) select e.employee_id, e.last_name, d.department_id, d.department_name from employees e, departments d where e.department_id = d.department_id(+); (2) select e.employee_id, e.last_name, d.department_id, d.department_name from employees e left outer join departments d on e.department_id = d.department_id; 2) employees테이블에..
1. oracle 1) select to_char(hire_date,'yyyy'), sum(case when to_char(hire_date,'q')=1 then salary end) "1분기", sum(case when to_char(hire_date,'q')=2 then salary end) "2분기", sum(case when to_char(hire_date,'q')=3 then salary end) "3분기", sum(case when to_char(hire_date,'q')=4 then salary end) "4분기" from employees group by to_char(hire_date,'yyyy') order by 1; 2) pivot select * from (select to_char..
1. oracle select employee_id, salary a, first_value(salary) over() b, last_value(salary) over() c, min(salary) over() d, max(salary) over() e, sum(salary) over() f, rank() over(order by salary desc) g, dense_rank() over(order by salary desc) h from employees; select employee_id, department_id, salary a, sum(salary) over() b, sum(salary) over(order by employee_id) c, sum(salary) over(partition by..
1. oracle 1)컬럼별로 null 몇개씩 있는지 찾기 select sum(case when employee_id is null then 1 end)"a", sum(case when last_name is null then 1 end)"b", sum(case when commission_pct is null then 1 end)"c", sum(case when department_id is null then 1 end)"d" from employees; 2) na총 개수 이건... 1번작업 모든 컬럼 대상으로 해서 노가다 해야하나? 3) null을 0으로 바꾸기 (1) 눈속임 방법 : 환경설정 -> 고급 -> null을 0으로 바꾸기 (2) 5가지 방법 select nvl(commission_pct,..
1. oracle 1) select day,sumsal from( select to_char(hire_date,'d') d, to_char(hire_date,'day') day, sum(salary) sumsal from employees where sysdate - hire_date >= 12*365 group by to_char(hire_date,'day'), to_char(hire_date,'d') order by to_char(hire_date,'d') ); 2) pivot 후 unpivot 하는 방법도 있음 2. r 1) emp% arrange(WEEKDAYS) 3. python 1) import pandas as pd from datetime import datetime, date, time ..
1. oracle 2. r 3. python
1.oracle select department_id, sum(salary) from employees group by department_id having sum(salary) = (select max(sum(salary)) from employees group by department_id); 2. r emp
1. oracle select department_id, job_id, sum(salary) from employees group by department_id,job_id order by department_id,job_id; 2. r 1) emp1
text="━ [SPECIAL REPORT]인공지능 ‘메디치 전략’ ‘메디치(Medici) 전략’. 메디치 가문은 15세기 이탈리아 피렌체에서 무역과 금융업으로 번성했다. 그들은 막대한 자금을 조건 없이 과학과 예술에 투자했다. 르네상스를 사실상 가능하게 했다는 평가를 받고 있다. 이런 메디치 전략이 600여 년이란 세월의 간극을 뛰어넘어 인공지능(AI) 시대에 재조명되고 있다. ‘딥 러닝(Deep Learning)의 아버지’ 후쿠시마 구니히코(福島邦彦) 일본 퍼지논리시스템연구소 수석 과학자는 최근 중앙SUNDAY와의 단독 인터뷰에서 “지금 AI 시대를 이끄는 나라를 보라”며 “캐나다와 일본은 모두 ‘AI 겨울’ 시기에 메디치 가문 사람들처럼 투자했다”고 말했다. AI 겨울은 정부와 기업의 투자가 급감했..
1. oracle1)select next_day(add_months(hire_date,6),'월요일') from employees;2)select next_day(hire_date + to_yminterval('0-6'),'월') from employees;-- select next_day(add_months(sysdate,6),'월요일') from dual;-- select next_day(sysdate + to_yminterval('0-6'),'월') from dual; 2. rlibrary(lubridate)add
1. oracle 1) select employee_id, last_name, hire_date, round((sysdate-hire_date)/365,1) "year", round(months_between(sysdate,hire_date),1) "month", round(sysdate-hire_date,1) "month", to_char(hire_date,'day') "weekday" from employees where (sysdate - hire_date)/365 >= 15 order by to_char(hire_date-1,'d'); 2. r 1) library(doBy) emp % arrange(WEEKDAY) 3. python 1) import pandas as pd import numpy ..
1. oracle explain plan for select employee_id, last_name,hire_date, to_number(to_char(hire_date,'mm')) as "hire_month" from employees where mod(to_number(to_char(hire_date,'mm')),2)=0 order by 4; select * from table(dbms_xplan.display(null,null,'typical')); -------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time ..
1. oracle 1) 가장 좋은 방법 select employee_id, last_name, hire_date from employees where hire_date >= to_date('2005-01-01','yyyy-mm-dd') #데이터가 날짜형으로 되어 있으므로 ! and hire_date
1. oracle 1) 교집합 select department_id from departments intersect select department_id from employees; ---------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 27 | 429 | 6 (84)| 00:00:01 | | 1 | INTERS..
1. oracle select employee_id, last_name from employees where last_name like '%a%a%'; 2. r 1) library(stringr) emp =2 for i in df['LAST_NAME']]]
1.SQL explain plan for select employee_id, last_name from employees where last_name like '__a%' or last_name like '__e%'; select * from table(dbms_xplan.display(null,null,'typical')); ------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------..
1. oracle explain plan for select employee_id, last_name, department_id from employees where department_id not in (10,30,50); select * from table(dbms_xplan.display(null,null,'typical')); 실행계획: ------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------..
1. oracle select employee_id, last_name, salary from employees where salary between 5000 and 10000;explain plan for select employee_id, last_name, salary from employees where salary between 5000 and 10000; select * from table(dbms_xplan.display(null,null,'typical')); ------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CP..
1. oracle 1) select last_name||' '||first_name from employees; 2. r 1) 새로 만들어야함 data.frame(id = emp$EMPLOYEE_ID,name=paste(emp$LAST_NAME,emp$FIRST_NAME)) 3. python 1) 새로운 컬럼을 넣는 것이기 때문에 새로 만들어야함 name = emp["LAST_NAME"]+' '+emp["FIRST_NAME"]res = emp["LAST_NAME"]+' '+emp["FIRST_NAME"] pd.DataFrame({'id':emp['EMPLOYEE_ID'],'name':res}) 2) 수정하기 emp_copy=emp emp_copy['FIRST_NAME'] = pd.DataFrame({'n..
import 할 테이블은 oracle에서 employees와 departments 테이블을 export 하셔서 사용하시면 됩니다. 1. oracle 1) select * from employees; select * from departments; 2. r 1) emp=read.csv("c:/data/employees.csv",header=T,stringsAsFactors = FALSE) dept=read.csv("c:/data/departments.csv",header=T,stringsAsFactors = FALSE) class(emp) str(emp) head(emp) print(emp) colnames(emp) rownames(emp) 3. python 1)csv :: csv.reader import..
oracle 1. 현재날짜시간 select sysdate,current_date,systimestamp,current_timestamp,localtimestamp from dual; 2.문자 -> 날짜 select to_date('2019-01-15 15:14:13','yyyy-mm-dd hh24:mi:ss') from dual; 3.날짜->문자/숫자 1) select to_char(hire_date,'yyyy-mm-dd hh24:mi:ss.sssss') "년월일시분초", to_char(hire_date,'yyyy"년" yy year') "년", to_char(hire_date,'q"분기"')"분기", to_char(hire_date,'mm month mon')"월", to_char(hire_date,'..
oracle(select, from 생략) r + (::stringr) python(::re) 대문자로 upper(last_name) to_upper('asd') str_to_upper('abc') 'abc'.upper() 소문자로 lower(last_name) to_lower('ASD') str_to_lower('abc') 'ABC'.lower() 첫글자대문자+소문자 initcap(last_name) str_to_title('abc') 'abc'.capitalize() 'ab cd'.title() 'abCD'.swapcase() 문자 letter[1:26] 조회 문자갯수(char/bite) length(last_name) lengthb(last_name) nchar('qwe',type='char') n..
1. oracle select round(45.926,2), round(45.926,1), round(45.926,0), round(45.926), round(45.926,-1) from dual; select trunc(45.925,2), trunc(45.925,1), trunc(45.925,0), trunc(45.925), trunc(45.925,-1) from dual; select ceil(10.1), ceil(10.999), ceil(10.0001), ceil(10.0) from dual; --> ceil(10.0)은 10나오고 나머지는 다 11 나옴 select floor(10.1), floor(10.999), floor(10.0001), floor(10.0) from dual; --> 다 1..