编写存储过程 SELECT a.order_id, a.done_date, a.cust_id, a.subscriber_ins_id, a.access_num, c.dev_id, c.dev_name, c.corp_org, c.company_name, c.department_code, c.department_name, c.remarks FROM JOUR1.Om_Subscriber_202301 a LEFT JOIN JOUR1.om_order_202301 b ON a.order_id = b.order_id LEFT JOIN params1.sec_developer c ON b.dev_id = c.dev_id UNION ALL SELECT a.order_id, a.done_date, a.cust_id, a.subscriber_ins_id, a.access_num, c.dev_id, c.dev_name, c.corp_org, c.company_name, c.department_code, c.department_name, c.remarks FROM JOUR1.Om_Subscriber_202302 a LEFT JOIN JOUR1.om_order_202302 b ON a.order_id = b.order_id LEFT JOIN params1.sec_developer c ON b.dev_id = c.dev_id UNION ALL SELECT a.order_id, a.done_date, a.cust_id, a.subscriber_ins_id, a.access_num, c.dev_id, c.dev_name, c.corp_org, c.company_name, c.department_code, c.department_name, c.remarks FROM JOUR1.Om_Subscriber_202303 a LEFT JOIN JOUR1.om_order_202303 b ON a.order_id = b.order_id LEFT JOIN params1.sec_developer c ON b.dev_id = c.dev_id UNION ALL SELECT a.order_id, a.done_date, a.cust_id, a.subscriber_ins_id, a.access_num, c.dev_id, c.dev_name, c.corp_org, c.company_name, c.department_code, c.department_name, c.remarks FROM JOUR1.Om_Subscriber_202304 a LEFT JOIN JOUR1.om_order_202304 b ON a.order_id = b.order_id LEFT JOIN params1.sec_developer c ON b.dev_id = c.dev_id
时间: 2024-04-12 07:31:14 浏览: 210
cust_global.rar_DEA-Solver-Lv_I Do! I Do!
你可以编写一个存储过程来执行这个查询。下面是一个示例:
```sql
CREATE OR REPLACE PROCEDURE get_data AS
BEGIN
-- 创建临时表来保存结果
CREATE GLOBAL TEMPORARY TABLE temp_data (
order_id NUMBER,
done_date DATE,
cust_id NUMBER,
subscriber_ins_id NUMBER,
access_num VARCHAR2(100),
dev_id NUMBER,
dev_name VARCHAR2(100),
corp_org VARCHAR2(100),
company_name VARCHAR2(100),
department_code VARCHAR2(100),
department_name VARCHAR2(100),
remarks VARCHAR2(100)
) ON COMMIT PRESERVE ROWS;
-- 第一个查询
INSERT INTO temp_data
SELECT a.order_id,
a.done_date,
a.cust_id,
a.subscriber_ins_id,
a.access_num,
c.dev_id,
c.dev_name,
c.corp_org,
c.company_name,
c.department_code,
c.department_name,
c.remarks
FROM JOUR1.Om_Subscriber_202301 a
LEFT JOIN JOUR1.om_order_202301 b
ON a.order_id = b.order_id
LEFT JOIN params1.sec_developer c
ON b.dev_id = c.dev_id;
-- 后续查询使用UNION ALL连接
INSERT INTO temp_data
SELECT a.order_id,
a.done_date,
a.cust_id,
a.subscriber_ins_id,
a.access_num,
c.dev_id,
c.dev_name,
c.corp_org,
c.company_name,
c.department_code,
c.department_name,
c.remarks
FROM JOUR1.Om_Subscriber_202302 a
LEFT JOIN JOUR1.om_order_202302 b
ON a.order_id = b.order_id
LEFT JOIN params1.sec_developer c
ON b.dev_id = c.dev_id;
INSERT INTO temp_data
SELECT a.order_id,
a.done_date,
a.cust_id,
a.subscriber_ins_id,
a.access_num,
c.dev_id,
c.dev_name,
c.corp_org,
c.company_name,
c.department_code,
c.department_name,
c.remarks
FROM JOUR1.Om_Subscriber_202303 a
LEFT JOIN JOUR1.om_order_202303 b
ON a.order_id = b.order_id
LEFT JOIN params1.sec_developer c
ON b.dev_id = c.dev_id;
INSERT INTO temp_data
SELECT a.order_id,
a.done_date,
a.cust_id,
a.subscriber_ins_id,
a.access_num,
c.dev_id,
c.dev_name,
c.corp_org,
c.company_name,
c.department_code,
c.department_name,
c.remarks
FROM JOUR1.Om_Subscriber_202304 a
LEFT JOIN JOUR1.om_order_202304 b
ON a.order_id = b.order_id
LEFT JOIN params1.sec_developer c
ON b.dev_id = c.dev_id;
-- 查询结果
SELECT * FROM temp_data;
-- 删除临时表
DROP TABLE temp_data;
END;
/
```
这个存储过程创建了一个临时表 `temp_data` 来保存查询结果,并将每个查询的结果插入到临时表中。最后,通过查询 `temp_data` 表来获取结果。
请注意,根据你的实际需求和数据库结构,你可能需要修改表和列的定义,以及查询的逻辑。确保在执行存储过程之前,已经创建了所需的表和索引。
阅读全文