Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 실습
- 빅데이터 분석 기사
- 튜닝
- 코딩테스트
- SQL
- 실기
- R
- 파이썬
- level 2
- Kaggle
- 카카오
- 알고리즘
- 오라클
- Python
- Oracel
- 머신러닝
- level 1
- Numpy
- python3
- sklearn
- 프로그래머스
- oracle
- 빅분기
- matplotlib
- 데이터 분석
- seaborn
- pandas
Archives
- Today
- Total
라일락 꽃이 피는 날
[Oracle] 알고리즘 문제 2 본문
728x90
예제 1. 3개의 숫자를 각각 물어보게 하고, 3개의 숫자에 대한 최대 공약수를 출력
accept num1 prompt '첫 번째 숫자를 입력하세요'
accept num2 prompt '두 번째 숫자를 입력하세요'
accept num3 prompt '세 번째 숫자를 입력하세요'
select max(level)
from dual
where mod(&num1, level) = 0
and mod(&num2, level) = 0
and mod(&num3, level) = 0
connect by level <= &num3;
예제 2. 16과 24의 최소 공배수를 출력
select 16 * 24 / max(level)
from dual
where mod(16, level) = 0
and mod(24, level) = 0
connect by level <= 24;
예제 3. 피타고라스의 정리로 직각 삼각형의 여부를 출력
accept num1 prompt '밑변의 길이를 입력하세요 ~'
accept num2 prompt '높이를 입력하세요 ~'
accept num3 prompt '빗변의 길이를 입력하세요 ~'
select decode(power(&num1, 2) + power(&num2, 2), power(&num3, 2), '직각 삼각형이 맞습니다', '직각 삼각형이 아닙니다') as 결과
from dual;
예제 4. 0에서 1사이의 난수를 출력
select dbms_random.value(0,1)
from dual;
예제 5. 몬테카를로 알고리즘으로 원주율의 근삿값을 출력
accept p_num prompt '정사각형 안에 들어가는 빨간점의 갯수를 입력하세요'
select sum(case when power(x, 2) + power(y, 2) <= 1 then 1 else 0 end) / &p_num * 4 as 원주율
from ( select dbms_random.value(0,1) as x,
dbms_random.value(0,1) as y
from dual
connect by level <= &p_num );
정사각형의 넓이 : 부채꼴의 넓이 = 정사각형의 점의 개수 : 부채꼴의 점의 개수
예제 6. 자연 상수 e 의 값 구하기
with loop_table as ( select level as num
from dual
connect by level <= 100000 )
select result
from ( select num, power((1+1/num), num) as result
from loop_table )
where num = 100000;728x90
'프로그래밍 > Oracle' 카테고리의 다른 글
| [Oracle] 알고리즘 문제 1 (0) | 2022.06.14 |
|---|---|
| [Oracle] WITH ~ AS 절 (0) | 2022.06.14 |
| [Oracle] 제약 (constraint) 2 (0) | 2022.06.14 |
| [Oracle] 제약 (constraint) 1 (0) | 2022.06.14 |
| [Oracle] 머신러닝 - 미국인 의료비 데이터 (0) | 2022.06.12 |