I have a situation where I need to access the column values from rowtype variable. However, the column names are dynamic.
below is sample code:
Cursor c1 is select * from emp;
Cursor c2 is select column_name from xyztable;
for rec in c1
open c2;---this cursor has column names like EMPLOYEE_ID, FIRST_NAME, LAST_NAME etc.
fetch c2 into v_c2;
exit when c2%notfound;
/* now lets say i want to access value of LAST_NAME from cursor c1, so I am writing below code, however it does not work as expected */
v_str:= 'rec.'|| v_c2.column_name; -- this will give me string like "rec.EMPLOYEE_ID"
Plz help ASAP.Thanks.
Answers were Sorted based on User's Feedback
CURSOR C1 IS SELECT *
CURSOR C2 IS SELECT *
FOR REC IN C1
FETCH C2 INTO v_c2;
EXIT WHEN C2%NOTFOUND;
v_str := 'REC'||v_c2.ENAME;
v_res := V_STR;
|Is This Answer Correct ?||1 Yes||0 No|
Answer / abhishek jee
So what this PL/SQL block is trying to do is post as many records from "emp" table as there are records in "dept" table, i.e., if there are 27 records in "dept" table and 107 records in "emp" table, then the output would show the first 27 records from the "emp" table, isn't that so?
|Is This Answer Correct ?||0 Yes||0 No|
Can delete statement be rollbacked?
What are the basic techniques of indexing?
What are the types of join in sql?
What is a dynamic query?
What is over () in sql?
How can we implement rollback or commit statement in a trigger?
How to remove duplicate rows from a table?.
how many ways we can we find the current date using mysql? : Sql dba
What does plvtab enables you to do when you showthe contents of pl/sql tables?
What is an exception in PL/SQL? What are the two types of exceptions?
Explain cursor types?
what is the forward decleration in packages?