전체 글
-
[PLSQL] procedureDataBase/PLSQL 2022. 9. 9. 17:06
-함수와 비슷한 구조 -함수는 결과 리턴이 있지만 PROCEDURE는 결과 리턴이 없는 것이 특징(리턴을 위한 별도의 코드(변수)가 있음) -리턴 키워드 대신, 리턴 역할을 하는 변수를 필요 갯수만큼 만들어서 사용함 1. 생성 CREATE OR REPLACE PROCEDURE 프로시져이름( 매개변수명1 [IN|OUT|IN OUT] 데이터타입[:=디폴트 값], 매개변수명2 [IN|OUT|IN OUT] 데이터타입[:=디폴트 값], ... ) IS[AS] 변수,상수 선언 BEGIN 실행부 [EXCEPTION 예외처리부] END[프로시져이름]; -CREATE OR REPLACE PROCEDURE: 프로시져를 생성하는 구문 -매개변수명1 [IN|OUT|IN OUT]: 매개변수를 만들되 전달되는 전달인수를 받는..
-
[PLSQL] functionDataBase/PLSQL 2022. 9. 9. 17:02
PL/SQL 코드 작성시에는 지금까지 사용하던 익명 블럭은 잘 사용하지 않음. 일반적으로 이름이 있는 서브프로그램(함수) 또는 프로시져를 사용하는 것이 대부분임. 익명 블럭은 한번 사용하고 나면 없어져 버리는 휘발성 블럭이지만 함수 또는 프로시져는 컴파일을 거쳐 데이터베이스에 저장되어 재사용이 가능한 구조. -- 함수의 형태 CREATE OR REPLACE RUNCTION 함수이름(매개변수1, 매개변수2, ...) RETURN 리턴될데이터타입; IS[AS] 변수,상수 선언 BEGIN 실행부 RETURN 리턴값; [EXCEPTION 예외처리부] END [함수이름]; -CREATE OR REPLASCE FUNCTION 라는 구문을 이용하여 함수를 생성함. 함수를 만들고 수정하더라도 이 구문을 계속 컴파일 할..
-
[PLSQL] if, case, loopDataBase/PLSQL 2022. 9. 9. 16:59
if문 1. 경우의 수가 둘 중 하나이고 단독 IF로 사용할 때 if 조건 then 실행문1 end if 2. 경우의 수가 둘 중 하나이고 else와 함께 사용할 때 if 조건 then 실행문1 else 실행문2 end if 3. 경우의 수가 셋 이상일 때 if 조건 then 실행문1 elsif 조건2 then --오타아님주의 elsif 실행문2 else 실행문3 end if 연습하기 DECLARE vn_num1 NUMBER := 1; vn_num2 NUMBER := 2; BEGIN IF vn_num1 >= vn_num2 THEN DBMS_OUTPUT.PUT_LINE(vn_num1 || '이(가) 큰 수'); ELSE DBMS_OUTPUT.PUT_LINE(vn_num2 || '이(가) 큰 수'); END..
-
[PLSQL] block, 출력, 변수, 자료형, SQLDataBase/PLSQL 2022. 9. 9. 16:50
block PL/SQL은 여러 블럭으로 구성돼 있는데 쉽게 짐작할 수 있는 실행할 SQL 명령이 모여있는 블럭 등이 있으며 이는 명령의 실행단위가 됨. 이외 익명 블럭, 이름이 있는 블럭 등도 있고, 내부는 기능별로 이름부, 선언부, 실행부, 예외처리부로도 나누기도 함. 1. 구성 -- PL/SQL로 하나의 단위명령을 실행할 때 -- 아래와 같이 각 위치, 기능별 구성이 이루어짐 IS(AS) -- 이름부 DECLARE -- 선언부(변수 선언 등등) BEGIN -- 실행부(SQL 명령) EXCEPTION -- 예외처리부 END; -- BEGIN, END를 제외한 나머지는 필요에 의해 생략이 가능함 2. 익명 블럭 DECLARE num NUMBER; --변수 선언 BEGIN num :=100; --실행명령 ..
-
[PLSQL] Procedural Language for SQL 설치DataBase/PLSQL 2022. 9. 9. 16:40
다수의 SQL 명령이 모여서 하나의 작업 모듈 또는 트랜잭션을 이룰 때, 이를 하나의 블럭으로 묶어서 한번에 실행하게 하는 단위실행명령 예를 들어 Shoes Shop 쇼핑몰의 경우 장바구니에 있던 상품들을 주문하려고 할 때 1. Orders 테이블에 새로운 레코드 insert 2. Orders 테이블에서 가장 큰 oseq 조회(select) 3. 장바구니에서 상품목록을 조회(select) 4. 조회된 oseq와 상품 목록을 order_detail에 insert 5. 장바구니에서 방금 주문한 상품 삭제(delete) 위 동작을 오라클에 제공하는 프로그래밍 요소와 함께 SQL 명령 그룹(블럭)을 만들어 한번에 실행할 수 있게 함 그렇게 만들어진 PL/SQL 블럭은 MyBatic에서 활용됨 설치 사이트..
-
[MySQL] JDBCDataBase/MySQL 2022. 9. 9. 16:37
1. booklist, memberlist, rentlist 테이블 생성 -아래 파일을 오라클에서 실행해 테이블 생성 2. rentdetail view 생성(sql 파일) create view rentdetail as select date_format(a.rentdate,'%y-%m-%d') as rd, a.num as rentnum, c.name as mname, b.subject, b.rentprice, a.discount, (b.rentprice-a.discount) as rentprice2 from rentlist a, booklist b, memberlist c where b.num=a.bnum and c.num=a.mnum order by rentnum desc; 3. DBManager imp..
-
[MySQL] command, limit, offsetDataBase/MySQL 2022. 9. 9. 16:33
Command창에서 MySQL 실행 환경변수 설정하기 제어판 → 시스템 → 고급 시스템 설정 → 환경 변수 command 창에서 운영되는 mysql 프로그램 접속 -h는 호스트, -u는 사용자 -p는 비밀번호 mysql -h localhost -u root -p Schema 생성 create schema scott default charcter set utf9mb4; 사용하려는 스키마로 이동 use scott; 현재 스키마의 테이블 보기 show tables; 테이블의 구조 보기 desc 테이블명; limit(오라클의 rownum 역할): select로 데이터 조회할 때 조회할 레코드의 갯수를 조절 제한 가능 offset: select로 데이터 조회할 때, 맨 위에서부터 offset에 지정한번째까지는 뛰..
-
[MySQL] FunctionDataBase/MySQL 2022. 9. 9. 16:26
숫자 관련 함수 문자 관련 함수 그룹 집계 함수 날짜 관련 함수 날짜 및 시간 형식 // 연습하기 select greatest(23,65,87,45,12,89) from dual; select floor(123.1234) from dual; select ascii('A') from dual; select concat('abcd','EFG','hijk') from dual; -- select 'abcd'||'EFG'||'hijk' from dual; --오라클에서 이어붙이기 select insert('나는 버스를 타고 간다',4,3,'승용차를') from dual; select replace('나는 버스를 타고 간다','버스를','승용차를') from dual; select instr('나는 버스를 타고 ..