以下の列を持つテーブル attribute_config があります。
table_name column_name キー
2行の下にあるとしましょう
アカウント accountphone accountnum
顧客 顧客番号 顧客ID
キーは、accountnum または customerid のみにすることができます。
(i_accountnum,i_customerid) を受け入れるコードを作成する必要があります。
where条件のキーを使用して、table_nameで言及されたテーブルのcolumn_nameで言及された列からそれぞれの値をフェッチします。
例: accountnum = i_accountnum のアカウントから accountphone を選択し、customerid = i_customerid の顧客から customernumber を選択します。
完全なクエリは動的に形成する必要があります。クエリで i_accountnum または i_customerid を渡すかどうかも動的に決定する必要があります。key - accountnum の場合、i_accountnum が where 条件に渡されます。
私はこれまでこれらの行を試してきましたが、これは機能していません。間違っていることはわかっています。
declare
v_accountnum varchar2(20);
v_customerid varchar2(20);
v_attribute_value varchar2(20);
v_stmt varchar2(255);
begin
Account_Num := 'TestCustomer'; -- input to the function
v_customer_ref := 'TestAccount'; -- input to the function
for i in (Select * from attribute_config) loop
v_stmt := 'select ' || i.column_name || ' from ' || i.table_name ||' where ' || i.key|| ' = v_' || i.key;
execute immediate v_Stmt into v_attribute_value;
end loop;
end;