Как получить значения из входного параметра (Таблица типов объектов) в процедуре в Oracle PL SQL? - PullRequest
0 голосов
/ 14 июля 2020

Пожалуйста, помогите мне. У меня есть объект типа таблицы .

CREATE OR REPLACE TYPE SI_PHONE_ACC_T AS TABLE OF SI_PHONE_ACC;

CREATE OR REPLACE TYPE SI_PHONE_ACC AS OBJECT
(
  PHONE_ACC  VARCHAR2(15);
);

Ниже обычно передается в процедуру как вход из конца пользовательского интерфейса.

Пример:

SI_PHONE_ACCT_T (SI_PHONE_A CC ('123-345-6543'), SI_PHONE_A CC ('999-999-9999'), SI_PHONE_A CC ('ax878974545787wp')); - первые 2 номера телефона, 3-й номер счета

Телефон:

Emp_id--- phone_number

1 --     123-345-6543
2 --     999-999-9999
3---     897-897-8781

Таблица счетов:

Emp_id---  account_number

10 --     A0000
20 --     B0000
30---     ax878974545787wp
CREATE OR REPLACE PACKAGE BODY order_mgr 
IS

PROCEDURE ins_trees (  p_emp_details_in    IN  SI_PHONE_ACC_T )
BEGIN

 -- Now, I need to retrieve emp_ids from Phone and Account tables based on the phone or account numbers passed in the input parameter. please let me know how to do this.
 
---once I get those emp_id's, i need to insert into employee table which contains only one column emp_id.

--Please let me know how to do this.

FOR i IN 1 .. p_emp_details_in.count 
LOOP  
    INSERT into employee (emp_id)
      values(??);
  END IF;
END LOOP;
    
END;

1 Ответ

1 голос
/ 14 июля 2020
PROCEDURE ins_trees (  p_emp_details_in    IN  SI_PHONE_ACC_T )
BEGIN

    INSERT into employee (emp_id)
      select Emp_id 
      from table(p_emp_details_in) t
         , Phone_table t2 
      where t.PHONE_ACC = t2.phone_number
      union
      select Emp_id 
      from table(p_emp_details_in) t
         , Account_table t2 
      where t.PHONE_ACC = t2.account_number
      ;
    
END;
/
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...