私はOracleの初心者です。いくつかの機能を持つパッケージを作成しようとしています。これは私がやりたいことの擬似コードです
function FunctionA(UserID, startdate, enddate)
/* Select TransactionDate, Amount
from TableA
where TransactionDate between startdate and enddate
and TableA.UserID = UserID */
Return TransactionDate, Amount
end FunctionA
function FunctionB(UserID, startdate, enddate)
/* Select TransactionDate, Amount
from TableB
where TransactionDate between startdate and enddate
and TableB.UserID = UserID */
Return TransactionDate, Amount
end FunctionA
TYPE TRANSACTION_REC IS RECORD(
TransactionDate DATE,
TransactionAmt NUMBER);
function MainFunction(startdate, enddate)
return TBL
is
vTrans TRANSACTION_REC;
begin
FOR rec IN
( Select UserID, UserName, UserStatus
from UserTable
where EntryDate between startdate and enddate )
LOOP
vTrans := FunctionA(rec.UserID, startdate, enddate)
if vTrans.TransactionDate is null then
vTrans := FunctionB(rec.UserID, startdate, enddate)
if vTrans.TransactionDate is null then
rec.UserStatus := 'Inactive'
endif;
endif;
END Loop;
PIPE ROW(USER_OBJ_TYPE(rec.UserID,
rec.UserName,
rec.UserStatus,
vTrans.TransactionDate,
vTtans.TransactionAmt));
end MainFunction
TableAとTableBは非常に大きなテーブルであり、テーブルからレコードごとに1つのエントリしか取得していないため、この種のコードの実行には長い時間がかかります。
パッケージ内に一時テーブル(TempTableA、TempTableB)を作成し、開始日と終了日に基づいてすべてのレコードを一時的に保存します。そのため、各レコードのTransactionDateとAmountを取得しようとすると、 TempTables(TableAおよびTableBよりも小さい)。
TableAとTableBにUserIDが見つからない場合も考慮に入れたいと思います。したがって、基本的に、TableAとTableBにレコードが見つからない場合は、出力にもエントリが必要ですが、ユーザーが非アクティブであることが示されます。
よろしくお願いします。