node-oracle 사용 중인데요 익명 pl/sql 질문이요 0 3 1,058

by 김대현이 [SQL Query] forall sqlrowcount [2017.03.17 15:00:57]


declare 
    type col_1_at is table of varchar2(50) index by pls_integer;
    type col_2_at is table of varchar2(50) index by pls_integer;
    type col_3_at is table of number index by pls_integer;
    l_col_1 col_1_at     := :col_1s;  --Array bind value 
    l_col_2 col_2_at     := :col_2s;  --Array bind value 
    l_col_3 col_3_at     := :col_3s;  --Array bind value 
begin 
    forall i in l_col_1.first .. l_col_1.last 
        insert /*+ ignore_row_on_dupkey_index(table_name, table_name_PK) */ into table_name(col_1, col_2, col_3) 
        values (to_date(l_col_1 (i), 'yyyymmddhh24miss'), l_col_2 (i), l_col_3 (i));
    end;

 

위와 같이 익명 pl/sql문을 사용 하고, insert할때 힌트를 줘서 중복되는 행은 insert 되는 걸 막고 있습니다.

여기서 궁금 한점은 만약 array value를 10건 insert 했을 때, 중복되는 행을 제외 하고 몇 행이 insert됐는가를 return 받고 싶은데 

방법을 모르겠어요 node-oracledb를 사용 중인데 :col_1s 는 IN_BIND 변수 이고,

변수를 하나 더 만들어 몇개의 행이 insert 되었는지 OUT_BIND 변수로 받고 싶어요.. 

by 마농 [2017.03.17 15:18:43]

SQL%ROWCOUNT 를 이용해 보세요.
http://www.gurubee.net/lecture/1062


by jkson [2017.03.17 15:30:43]

그런데 저런 식으로 table형 타입 지정하고 :col_1s 와 같이 사용자바인드변수로 넘길 수도 있는 건가요?

따라해보려고 토드에서 해보니 뭘 어떻게 입력하는 건지 모르겠네요.

ignore_row_on_dupkey_index도 첨보는데 신기하네요~


by 김대현이 [2017.03.17 17:53:49]

바이드 변수는 array로 넘겨요~ [1,2,3,4,5] 이런 식으로요

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입