我已将单行提取到 rowType 变量中。这一行有 80 列。所以,我不想在我的程序中硬编码列名并从数据字典中获取列名。
请有人告诉我,我怎样才能访问单独的列值??????以下是我的代码。
DECLARE
fetchedRow EMP%ROWTYPE;
TYPE columnNameList IS TABLE OF USER_TAB_COLUMNS.column_name%TYPE;
CURSOR empCursor IS select column_name from USER_TAB_COLUMNS where table_name = 'EMP';
empColumnNames columnNameList;
colName varchar2(100);
BEGIN
-- Fetching column names of EMP from data dictionary
OPEN empCursor;
FETCH empCursor BULK COLLECT INTO empColumnNames;
CLOSE empCursor;
DBMS_OUTPUT.PUT_LINE('Columns fetched');
BEGIN
SELECT * into fetchedRow from EMP where EMP_ID = 1234;
END;
colName := 'fetchedRow.'||empColumnNames(1); --- colName will have fetchedRow.EMP_ID
DBMS_OUTPUT.PUT_LINE('Going to Compare'||colName);
--stuck here
if colName = 1234 then -- Want to compare value of fetchedRow.EMP_ID with 1234
DBMS_OUTPUT.PUT_LINE('Matching');
else
DBMS_OUTPUT.PUT_LINE('Not-Matching');
END IF;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error'||SQLERRM);
END;