dynamic search for the missing values [message #61873] |
Mon, 07 June 2004 12:35 |
Misha
Messages: 25 Registered: October 2001
|
Junior Member |
|
|
In this assignment I have to come up with list of the columns that are missing required data in a specific table, whose names (table and columns) are stored in a separate table. I have a table (display_control) which containsštable names and corresponding column names in each table. Depending on the input table name, I have to find that table and it's column, go that table and check if the column contain any data, and if not list that table and column as an output. It's convoluted logic and I can't think of a clean solution, short of some kind off kludge.
Here is a table structure:
CREATE TABLE display_controls
(
DISPLAY_CONTROLS_ID NUMBER,
TABLE_NAME VARCHAR2(50 BYTE),
COLUMN_NAME VARCHAR2(50 BYTE),
WIDGET_NAME VARCHAR2(50 BYTE),
WIDGET_SEQ_NR NUMBER DEFAULT 0,
REQUIRED_FLG VARCHAR2(1 BYTE) DEFAULT 'T',
CREATED_BY VARCHAR2(30 BYTE),
CREATED_TMS DATE,
CHANGED_BY VARCHAR2(30 BYTE),
CHANGED_TMS DATE)
Thank you for any response.
š
š
|
|
|
Re: dynamic search for the missing values [message #61877 is a reply to message #61873] |
Mon, 07 June 2004 21:43 |
|
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
Something like this procedure then:
CREATE OR REPLACE PROCEDURE prc$check_data (
piv_tab IN VARCHAR2,
piv_col IN VARCHAR2
)
IS
v_sql_text VARCHAR2 (2048);
vn_cnt NUMBER := -1;
BEGIN
-- Construct the SQL statement (the second where clause is for performance, we don't need
-- to know how many rows, if we get one it is enough)
v_sql_text :=
'SELECT count('
|| piv_col
|| ') cnt FROM '
|| piv_tab
|| ' WHERE '
|| piv_col
|| ' IS NOT NULL AND ROWNUM < 2';
-- Fetch the data
EXECUTE IMMEDIATE v_sql_text
INTO vn_cnt;
-- if records found
IF vn_cnt = 1
THEN
DBMS_OUTPUT.put_line (piv_col || ' contains data in table ' || piv_tab);
ELSE
DBMS_OUTPUT.put_line ('No data in ' || piv_col || ' of table '
|| piv_tab
);
END IF;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (SQLERRM);
END prc$check_data;
/ It is possible that it contains typos (it's not tested) but it should get you on the way.
MHE
|
|
|