Home » SQL & PL/SQL » SQL & PL/SQL » Concatenate issue (11.2.0.3)
Concatenate issue [message #606371] Thu, 23 January 2014 01:40 Go to next message
rishwinger
Messages: 132
Registered: November 2011
Senior Member
Hi Experts

SET serveroutput ON
Declare
  v_prop dept%rowtype;
type lst_column_name
IS
  TABLE OF all_tab_columns.column_name%type INDEX BY binary_integer;
  v_column_name lst_column_name;
BEGIN
  SELECT *
  INTO v_prop
  FROM dept
  WHERE deptno='10';
  dbms_output.put_line('Count='||v_prop.dname);
  SELECT column_name bulk collect
  INTO v_column_name
  From All_Tab_Cols
  WHERE table_name='DEPT'
  AND owner       ='SCOTT';
  FOR i IN 1..v_column_name.count
  Loop
    --insert into excepts select exception_seq.nextval,table_name,v_column_name(i) ,v_prop.v_column_name(i),sysdate from dual;
    dbms_output.put_line(v_prop.v_column_name(i));
  END LOOP;
  COMMIT;
END;
/
    dbms_output.put_line(v_prop.v_column_name(i));
                                *
ERROR at line 21:
ORA-06550: line 21, column 33:
PLS-00302: component 'V_COLUMN_NAME' must be declared
ORA-06550: line 21, column 5:
PL/SQL: Statement ignored


Is this even possible?
I have to store key(column_name),value(column_value) pair. Please advise.

Re: Concatenate issue [message #606372 is a reply to message #606371] Thu, 23 January 2014 01:54 Go to previous messageGo to next message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Do you really expect we reverse engineer your code? Explain WITH WORDS what you are trying to do with it.
I will just answer to the error: V_COLUMN_NAME is not part of v_prop.

Re: Concatenate issue [message #606373 is a reply to message #606371] Thu, 23 January 2014 02:11 Go to previous messageGo to next message
rishwinger
Messages: 132
Registered: November 2011
Senior Member
Michel,

I have to take backup of a single row of table in another table which has column KEY which will store column_name and VALUE which will store COLUMN_VALUE,

In the script above
1. Fetching a column from DEPT table with DEPTNO=10 in rowtype variable V_PROP
2. FETCHING all columns from ALL_TAB_COLUMNS

I'm trying to dynamically get column_value using V_PROP.V_COLUMN_NAME(I) which is throwing an error.

Regrads'
Re: Concatenate issue [message #606375 is a reply to message #606373] Thu, 23 January 2014 02:14 Go to previous message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You can't and it is a bad idea in a real application.
"%rowtype" is static so you know the columns when you compile the code and so you don't need to query all_tab_columns.
If you really want to do dynamic things, do not use %rowtype, use dnms_sql.
See
T.Kyte's print_table function.

[Updated on: Thu, 23 January 2014 02:15]

Report message to a moderator

Previous Topic: TO_DATE conversion issue
Next Topic: How to use bind variables in cursors?
Goto Forum:
  


Current Time: Tue Apr 16 18:14:00 CDT 2024