数据类型错误ORA-01790

时间:2018-03-29 06:11:04

标签: sql oracle union

我的数据类型错误:

  

ORA-01790:表达式必须与对应的表达式具有相同的数据类型

我已经检查了所有相同的数据类型。

这是我的代码:

SELECT CONTRACT_ID, DATEKEY, 'Projection', '1', OPEN_BALANCE,
  PRINC_REPAYMENT, INTEREST, PAR_PREPAYMENT, FULL_REDEMPTION, REDRAW_AMOUNT, PRIN_DEFAULTS,
  PRIN_RECOVERY, PRIN_DEL, INTE_DEL, DEL_PRIN_COLL, DEL_INT_COLL, CLOSE_PRIN_BAL, EXT_ID,
  LAS_ACTIVE_FLG, PROD_ID, ASSET_TYP_ID, CPT_ID, ACCRETION, CASHFLOW_DT 
FROM FACT_PWOR_CASHFLOW
WHERE ACTUAL_FLG = 'Y' AND LATEST_PROJ_IND = '0' AND LAS_ACTIVE_FLG = 'Y'
UNION
(SELECT CONTRACT_ID, DATEKEY_COLL, 'Actual', '1', SUM(OPENING_BALANCE) SUM_OPEN_BAL,
    SUM(MI_PRINCIPLE) SUM_MI_PRIN, SUM(MI_INTEREST) SUM_MI_INTER, SUM(PARTIAL_PREPAYMENT) SUM_PAR_PREPAY,
    SUM(FULL_REDEMPTION) SUM_FULL_REDEM, SUM(TTL_AMT_REDRAW) SUM_TTL_AMT,
    '0', '0', '0', '0', '0', '0', SUM(CLOSING_BALANCE) SUM_CLOS_BAL, '0', 'Y',
    PROD_ID, ASSET_TYPE_ID, CPT_ID, '0', COLLECTION_START_DT
FROM FACT_PWOR_COLLECTION
WHERE LAS_ACTIVE_FLG = 'Y'
GROUP BY CONTRACT_ID, DATEKEY_COLL, PROD_ID, ASSET_TYPE_ID, CPT_ID, COLLECTION_START_DT);

1 个答案:

答案 0 :(得分:0)

在您的案例中使用UNION之类的设置操作时,所有匹配的列都会被列出来。表FACT_PWOR_CASHFLOWFACT_PWOR_COLLECTION中的数据类型必须匹配。

例如,如果第一个ACCRETION语句中列SELECT的数据类型可能是integer,而第二个'0'中的相应列是SELECT string type语句为DataType Error,然后CONTRACT_ID发生。

删除SELECT列表中的所有列,然后尝试从第一个Update tmp Set tmp.TenantReceipts = a.TenantReceipts, tmp.OtherReceipts = a.OtherReceipts, tmp.Disbursments = a.Disbursments, tmp.AgentFeesCollectionCommission = a.AgentFeesCollectionCommission, tmp.AgentFeesManagementFee = a.AgentFeesManagementFee, tmp.AgentFeesBankCharges = a.AgentFeesBankCharges, tmp.AgentOnlyCashMovements = a.AgentOnlyCashMovements, tmp.PaidToOwners = a.PaidToOwners From #tmpResultSet tmp Inner Join (Select PropertyID, IsNull(CashBookID, 0) as CashBookID, --Tenant Receipts Sum of tenant receipts (type = 2) and tenant payments (type = 3), excluding agent only transactions, for either financial or owner statement period. Sum (Case When TransactionTypeID in (2,3) and ExcludeFromOwnerReports = 0 then InclusiveAmount else 0 end) as TenantReceipts, --Other Receipts Sum of suppier receipts (type = 12 not used) and property receipts (type = 22), excluding agent only transactions, for either financial or owner statement period. Sum (Case When TransactionTypeID in (12,22) and ExcludeFromOwnerReports = 0 then InclusiveAmount else 0 end) as OtherReceipts, --Disbursements Sum of suppier payments (type = 13) and property payments (type = 23), excluding agent only transactions, for either financial or owner statement period. --Excludes transactions designated as Agent Fees in Global Options i.e Collection Commission, Management Fee, Bank Charge son Cash, Bank Charges on Cheques (includes all payments) and Bank Charges on Cash, as well as amounts Paid to Owners. Sum (Case When TransactionTypeID in (13,23) --and IsNull(afgo.TransactionCodeID, 0 ) = 0 and tx.TransactionCodeID not in (@CollectionCommissionID) and tx.TransactionCodeID not in (@ManagementFeeID) and tx.TransactionCodeID not in (@BankChargesOnCashID) and tx.TransactionCodeID not in (@BankChargesOnChequesID) and tx.TransactionCodeID not in (@OwnerPaymentsID) and ExcludeFromOwnerReports = 0 then InclusiveAmount else 0 end) as Disbursments, --Agent Fees For Amounts Paid: --If any of the Agent Fee components are unchecked on the parameter screen, they will be excluded from the calculation. --Sum of supplier payments (type = 13) and property payments (type =23), excluding agent only transactions, for either financial or owner statement period. --Further restricted to transactions designated in Global Options as Collection Commission, Management Fee and Bank Charges, and if ticked on the parameter form. --Agent Fees Collection Commission Sum (Case When TransactionTypeID in (13, 23) and ExcludeFromOwnerReports = 0 and @AmountsAccrued = 0 and @ShowCollectionCommission = 1 and tx.TransactionCodeID in (@CollectionCommissionID) then InclusiveAmount else 0 end) as AgentFeesCollectionCommission, --Agent Fees Management Fee Sum (Case When TransactionTypeID in (13, 23) and ExcludeFromOwnerReports = 0 and @AmountsAccrued = 0 and @ShowManagementFee = 1 and tx.TransactionCodeID in (@ManagementFeeID) then InclusiveAmount else 0 end) as AgentFeesManagementFee, --Agent Fees Bank Charges Sum (Case When TransactionTypeID in (13, 23) and ExcludeFromOwnerReports = 0 and @AmountsAccrued = 0 and @ShowBankCharges = 1 and (tx.TransactionCodeID in (@BankChargesOnCashID) or tx.TransactionCodeID in (@BankChargesOnChequesID)) then InclusiveAmount else 0 end) as AgentFeesBankCharges, --Agent Only (Cash) Movements Sum of cash transactions (types = 2, 3, 12, 13, 22 and 23) and where such transactions are designated as ‘agent only, for either financial or owner statement period. Sum (Case When TransactionTypeID in (2, 3, 12, 13, 22, 23) and ExcludeFromOwnerReports = 1 then InclusiveAmount else 0 end) as AgentOnlyCashMovements, --Paid to Owners Sum of property payments (type = 23) allocated to the Owner Payment transaction code in Global Options, excluding agent only transactions, for either financial or owner statement period. Sum (Case When TransactionTypeID in (13, 23) --RB 05/08/2009 Added Transaction Type 13 where expense accruals are paid to owner payment codes and ExcludeFromOwnerReports = 0 and tx.TransactionCodeID = @OwnerPaymentsID then InclusiveAmount else 0 end) as PaidToOwners From Transactions tx (NoLock) Where ( (@UseFinPeriod = 1 and tx.Period = @Period) or (@UseFinPeriod = 0 and tx.OwnerStatPeriod = @Period) ) and ((@IncludeRegularTransactions = 1 and @IncludeAgentOnlyTransactions = 1) or (tx.ExcludeFromOwnerReports = 0 and @IncludeRegularTransactions = 1) or (tx.ExcludeFromOwnerReports = 1 and @IncludeAgentOnlyTransactions = 1) ) and (@GenerateOwnerPayments = 0 or @PropertyDefaultCashBookID = tx.CashBookID) and tx.PropertyID in (Select PropertyID from #tmpProperties) Group By tx.PropertyID, tx.CashBookID --Order by tx.PropertyID ) a on a.PropertyID = tmp.PropertyID and a.CashBookID = tmp.CashBookID 开始逐步为两个SELECT语句添加列。