문제

여러 작업을 수행 해야하는 기능이 있다고 가정 해 봅시다.이 모든 작업은 하나의 쿼리 결과에 따라 다릅니다. 내가 찾을 수있는 모든 것은 절차 밖에서 온도 테이블을 정의해야한다는 것을 나타냅니다.

다음과 같은 일을하고 싶습니다.

create or replace function f_example(
  a_input in number
)
return varchar2 is
begin
  create local temporary table tempIDs
  ( 
    testID number(6, 0)
    , testValue number(8,0)
  );

  //select data from tableFoo that will be overwritten by a_input into tempIDs

  //update data in tableFoo with a_input & store old data in another tableFoo field

end f_example;

이 구문은 작동하지 않습니다. Oracle은 함수 내부에서 '작성'을 허용하지 않습니다.

저는 실제로 데이터베이스 프로그래머가 아닙니다. C#과 Java에서 일하는 데 익숙합니다. 이 경우 메소드가 완료되었을 때 범위를 벗어난 로컬 어레이 (또는 무엇이든)에 내 값을 저장합니다. Oracle SQL에서 이와 같은 일을 할 수있는 방법이 합법적으로 없습니까?

도움이 되었습니까?

해결책

PL/SQL 레코드 유형 및 관련 테이블 유형을 정의 할 수 있습니다. 그런 다음 a를 발행 할 수 있습니다 SELECT...BULK COLLECT 테이블을 채우기 위해.

declare
  type my_record_type is record (testId number, testvalue number);
  type my_table_type is table of my_record_type index by binary_integer;
  my_table my_table_type;
begin
  select x, y bulk collect into my_table from table_foo;
end;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top