【问题标题】:How to get the values from the Input parameter of (Object Type Table) in procedure in Oracle PL SQL?如何从 Oracle PL SQL 的过程中的(对象类型表)的输入参数中获取值?
【发布时间】:2020-11-04 00:35:44
【问题描述】:

请任何人都可以帮助我。我有一个表格类型对象

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);
);

下面一般是作为UI端的输入传递给过程的。

示例:

SI_PHONE_ACCT_T(SI_PHONE_ACC('123-345-6543'),SI_PHONE_ACC('999-999-9999'), SI_PHONE_ACC('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;

【问题讨论】:

  • 请告诉我们describe Phonetable。列 phone_number 真的是 varchar2 吗?
  • 基本上就是这个例子。但由于 SI_PHONE_ACC_T 类型包含电话和帐户,我只需要 varchar2 的东西。实际的表只包含不同的值与 varchar2。

标签: oracle object stored-procedures input types


【解决方案1】:
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;
/

【讨论】:

    猜你喜欢
    • 2020-01-20
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多