Oracle saves data from individual tables to another table

Source: Internet
Author: User

Save the data from each table in another table:

CREATE VIEW
Parameter_view as
With
Tall as
(
SELECT
P.pi_no,--Product serial number
P.serialno,--Product Code
P.pi_name,--Product Name
P. pi_start_date,--product start date
P.pi_end_date,--Product Period Date
P.pi_customer_yield/100 Pi_customer_yield,--yield of products
A.ai_no,--Asset serial number
A.cas_assets_na,--The name of the asset
A.dono,--Asset Encoding
A.cas_issue_sum,--Asset Issue Amount
A.cas_yield_rate/100 Cas_yield_rate,--Asset return rate
A.cas_value_date,--Asset interest date
A.cas_due_date,--Asset expiry date
NVL (feenum,0) feenum,--Other costs
NVL (feerate,0) feerate,--Other rates
NVL (fmfee,0) Fmfee,--cumulative floating management fee
NVL (fmfee3/100,0) fmfee3,--floating management fee
NVL (Ct. feeratio/100,0) Feeratio,--Escrow fee for products
NVL (cg.cgrate/100,0) cgrate,--product management fee
NVL (atrate/100,0) escrow fee for atrate,--assets
NVL (agrate/100,0) agrate management fee for,--assets
NVL (cgrates/100,0) cgrates,--product investment fee
NVL (agrates/100,0) agrates,--Asset investment fee
Gl_date,--Trading date
Floor (Sysdate-to_date (pi_start_date, ' Yyyy-mm-dd hh24:mi:ss ')) pflday,--product cumulative days
Floor (Sysdate-to_date (cas_value_date, ' Yyyy-mm-dd hh24:mi:ss ')) aflday--asset accumulation Days
From
Gl_productassets g
Left JOIN
Product_info P
On
G.pbs_mainpro_no=p.pi_no
Left JOIN
Assets_info A
On
G.cas_assets_nu=a.ai_no
Left JOIN
(
SELECT
ProductID
SUM (Fmfee) Fmfee
From
Product_fmfee
GROUP by
ProductID) F
On
G.pbs_mainpro_no=f.productid
Left JOIN
(
SELECT
Feeratio Fmfee3,
Feeobjectno
From
Product_cost_info
WHERE
Feetype= ' floating management fee ') F2
On
P.pi_no=f2. Feeobjectno
Left JOIN
(
SELECT
*
From
Product_cost_info
WHERE
Feeobjecttype= ' Product '
and feetype= ' escrow fee ') CT
On
P.pi_no=ct. Feeobjectno
Left JOIN
(
SELECT
SUM (feeratio) cgrate,
Feeobjectno
From
Product_cost_info
WHERE
Feeobjecttype= ' Product '
and feetype= ' management fee ' GROUP by Feeobjectno CG
On
P.PI_NO=CG. Feeobjectno
Left JOIN
(
SELECT
Feeratio Cgrates,
Feeobjectno
From
Product_cost_info
WHERE
Feeobjecttype= ' Product '
and feetype= ' investment fee ') CGG
On
P.PI_NO=CGG. Feeobjectno
Left JOIN
(
SELECT
Feeratio Atrate,
Feeobjectno
From
Product_cost_info
WHERE
Feeobjecttype= ' Asset '
and feetype= ' escrow fee ') att
On
A.ai_no=att. Feeobjectno
Left JOIN
(
SELECT
Feeratio Agrate,
Feeobjectno
From
Product_cost_info
WHERE
Feeobjecttype= ' Asset '
and feetype= ' management fee ') AG
On
A.ai_no=ag. Feeobjectno
Left JOIN
(
SELECT
Feeratio Agrates,
Feeobjectno
From
Product_cost_info
WHERE
Feeobjecttype= ' Asset '
and feetype= ' investment fee ') agg
On
A.ai_no=agg. Feeobjectno
Left JOIN
(
SELECT

SUM (feeratio) Feenum,
Feeobjectno
From
Product_cost_info
WHERE
Feeobjecttype= ' Product '
and Feetype not in (' Escrow fee ',
' Investment fee ',
' Management fee ',
' Floating management fee ')
and feeratio>1
GROUP by
Feeobjectno
) FS
On
A.ai_no=fs. Feeobjectno

Left JOIN
(
SELECT

SUM (feeratio) feerate,
Feeobjectno
From
Product_cost_info
WHERE
Feeobjecttype= ' Product '
and Feetype not in (' Escrow fee ',
' Investment fee ',
' Management fee ',
' Floating management fee ')
and feeratio<1
GROUP by
Feeobjectno
) FSS
On
A.AI_NO=FSS. Feeobjectno

WHERE
G.gl_state=1
)
SELECT
Ta.*,
(a_day_receive+p_day_manage+p_day_tm+p_day_tes-p_day_receive-a_day_manage-a_day_tm-a_day_tes+
Fmfee3+feenum) All_get
From
(
SELECT
Pi_no,
Pi_name,
pi_customer_yield*cas_issue_sum/365 p_day_receive,--product code, product name, product daily revenue
Pi_customer_yield*cas_issue_sum/365*pflday p_all_receive,--accrued from the date of interest to the day
cgrate*cas_issue_sum/365 P_day_manage,--Product day management fee
Cgrate*cas_issue_sum/365*pflday P_all_manage,--product accumulative management fee
feeratio*cas_issue_sum/365 P_day_tm,--Product day escrow fee
Feeratio*cas_issue_sum/365*pflday P_all_tm,--product cumulative escrow fee
cas_assets_na,cas_yield_rate*cas_issue_sum/365 a_day_receive,--asset number, asset name, daily return on assets
Cas_yield_rate*cas_issue_sum/365*aflday A_all_receieve,--accumulation of assets from the date of interest to the current day
agrate*cas_issue_sum/365 A_day_manage,--Asset day management fee
Agrate*cas_issue_sum/365*aflday A_all_manage,--product accumulative management fee
atrate*cas_issue_sum/365 A_day_tm,--Asset day escrow fee
Atrate*cas_issue_sum/365*aflday A_all_tm,--asset accumulation escrow fee
' 0 ' Tdfee,
' 0 ' Tdallfee,
Fmfee3,
cgrates*cas_issue_sum/365 p_day_tes,--Products The same day investment fee
Cgrates*cas_issue_sum/365*pflday P_all_tes,--Products Cumulative investment fee
agrates*cas_issue_sum/365 a_day_tes,--Asset Day investment fee
Agrates*cas_issue_sum/365*aflday A_all_tes,--Asset accumulative investment fee
Feenum--Other fees
From
Tall) Ta;





SELECT
DECODE (Gl_date,a.cas_value_date, P.pi_no, P.pi_name)
From
Gl_productassets g
Left JOIN
Product_info P
On
G.pbs_mainpro_no=p.pi_no
Left JOIN
Assets_info A
On
G.cas_assets_nu=a.ai_no
Left JOIN
(
SELECT
ProductID
SUM (Fmfee) Fmfee
From
Product_fmfee
GROUP by
ProductID) F
On
G.pbs_mainpro_no=f.productid
Left JOIN
(
SELECT
ProductID
SUM (Fmfee) fmfee3
From
Product_fmfee
WHERE
Inputdate = To_char (sysdate, ' yyyy/mm/dd ')
GROUP by
ProductID) F2
On
G.pbs_mainpro_no=f2. PRODUCTID
Left JOIN
(
SELECT
*
From
Product_cost_info
WHERE
Feeobjecttype= ' Product '
and feetype= ' escrow fee ') CT
On
P.pi_no=ct. Feeobjectno
Left JOIN
(
SELECT
Feeratio Cgrate,
Feeobjectno
From
Product_cost_info
WHERE
Feeobjecttype= ' Product '
and feetype= ' management fee ') CG
On
P.PI_NO=CG. Feeobjectno
Left JOIN
(
SELECT
Feeratio Cgrates,
Feeobjectno
From
Product_cost_info
WHERE
Feeobjecttype= ' Product '
and feetype= ' investment fee ') CGG
On
P.PI_NO=CG. Feeobjectno
Left JOIN
(
SELECT
Feeratio Atrate,
Feeobjectno
From
Product_cost_info
WHERE
Feeobjecttype= ' Asset '
and feetype= ' escrow fee ') att
On
A.ai_no=att. Feeobjectno
Left JOIN
(
SELECT
Feeratio Agrate,
Feeobjectno
From
Product_cost_info
WHERE
Feeobjecttype= ' Asset '
and feetype= ' management fee ') AG
On
A.ai_no=ag. Feeobjectno
Left JOIN
(
SELECT
Feeratio Agrates,
Feeobjectno
From
Product_cost_info
WHERE
Feeobjecttype= ' Asset '
and feetype= ' investment fee ') agg
On
A.ai_no=ag. Feeobjectno
WHERE
G.gl_state=1

Then save this view data to the table you want to save:

Insert INTO (and column name for the column of the View) Table A (SELECT * from view chart)

Oracle saves data from individual tables to another table

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.