로메오의 블로그

[ORACLE PLSQL] SELECT INTO 문 사용하기 본문

Backend/Oracle & SQL

[ORACLE PLSQL] SELECT INTO 문 사용하기

romeoh 2020. 2. 3. 16:13
반응형

SELECT 해 온 ROW를 변수로 저장합니다.

 

DECLARE
    V_CITY_ID VARCHAR2(10);
BEGIN
    SELECT OBJECT_ID 
      INTO V_CITY_ID 
      FROM CITY_TABLE
     WHERE OBJECT_ID = 1000;
    
    EXCEPTION
    	WHEN NO_DATA_FOUND THEN
        	V_CITY_ID := NULL;
            
    DBMS_OUTPUT.PUT_LINE('조회된 DATA = ' || V_CITY_ID);
END 

 

ARRAY로 저장하기

DECLARE
    V_CITIES_IDS DBMS_SQL.NUMBER_TABLE;
BEGIN
    SELECT OBJECT_ID 
      BULK COLLECT INTO V_CITIES_IDS 
      FROM CITY_TABLE
     WHERE OBJECT_ID = 1000;
    
    FOR i IN 1..V_CITIES_IDS.COUNT LOOP
    	DBMS_OUTPUT.PUT_LINE('조회된 DATA = ' || V_CITIES_IDS(i));
    END LOOP;
    
END 

 

 

 

 

 

 

반응형
Comments