How to populate the dynamic recordset while passing the tablename dynamically [message #420794] |
Wed, 02 September 2009 05:05 |
tapaskmanna
Messages: 98 Registered: January 2007 Location: Cyprus,Nicosia
|
Member |
|
|
Hi,
Passing a table name and getting the data for table.
table name will have the dynamic value.
Getting error in the section of code [PRINT the data]
ORA-00932: inconsistent datatypes: expected NUMBER got DATE
Pls. suggest:
i) How to hold the dynamic table value with respect to tables values changes i.e.How to populate the dynamic recordset while passing the tablename as one does'nt know the table structure in order to fetch the value from ref cursor.
CREATE OR REPLACE PROCEDURE TK_Ext_TabCol_1(p_tab IN VARCHAR2)
IS
TYPE r_cursor IS REF CURSOR;
c_cur r_cursor;
v_cur r_cursor;
v_return_cur SYS_REFCURSOR;
v_col VARCHAR2(4000);
frows NUMBER:=0;
BEGIN
-- Populating the col name
FOR i IN (SELECT column_name FROM dba_tab_columns WHERE table_name=p_tab ORDER BY column_id)
LOOP
v_col:=i.column_name||','||v_col;
END LOOP;
v_col:=SUBSTR(v_col,1,LENGTH(v_col)-1);
-- Populating the
OPEN c_cur FOR
'SELECT '||v_col ||' FROM '||p_tab;
-- PRINT the data
LOOP
FETCH c_cur INTO v_cur;
EXIT WHEN c_cur%NOTFOUND;
frows :=frows+1;
END LOOP;
CLOSE c_cur;
dbms_output.put_line(frows);
END TK_Ext_TabCol_1;
|
|
|
|