Database Data Acquisition instance in Oracle Stored Procedure

Source: Internet
Author: User

How can we insert the data obtained in Table A into another table B?

(1) For tables A and B with the same structure [number of fields, type of corresponding fields, etc.], you can use

Insert into B select * From;

Insert into B (field1, field2, field3) Select a. field1, A. field2, A. field3 from;

(2) If the number of fields in two tables is different but the structure of several fields is the same (similar to parent-child relationship), you must use insert into B (field1, field2) Select. field1,. field2 from;

1. Use a cursor with parameters to implement the insert function:

Create or replace procedure get_data (

-- Parameter list:

N_task_id in number, -- task id
V_task_name in varchar2, -- Task Name
V_name in varchar2 -- name
)

-----------------------------------------------

-- Procedure name: get_data --

-- Comment content: obtain qualified data from the data source table and insert it to the target data table :--

-- Reference: n_tas_id task id ,--

-- V_task_namek Task Name ,--

-- V_bdw_name restrictions on the data source table: Intranet name --

-----------------------------------------------

Is

-- Insert row number control

I _count number (5 );

-- Data cursor: data_cur (in_name)

-- Parameter: Intranet name: in_name

Cursor data_cur (in_name varchar2) is/** note: the Parameter definition does not contain precision **/
Select *
From get_data_src
Where a. Name = in_name;
Begin

-- Counter to control the number of inserted rows

I _count: = 0;

-- Insert data cyclically

For mycur in data_cur (v_name) loop
Insert into ABC (
Row_id,
Task_id,
Task_name,
Get_data_dt,
Cust_id,
Assign_flag,
Deal_date
) Values (
Seq_kd.nextval,
N_task_id,
V_task_name,
Sysdate,
Mycur. cust_id,
'N ',
Null
);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.