I want to run a query, get the results, and then iterate over the results of this query using another select statement, using the values ββof the first statement in my second expression (cursor).
I have 40 users in my db. All users have the same db schema structure. I want to get the username via:
SELECT distinct username
from all_users
then use the username to run this query:
Select lastname, firstname, email, email2 from username.member.
My result set will return multiple rows, so I need a row type.
I tried many different pl / sql combinations:
DECLARE
CURSOR client_cur IS
SELECT distinct username
from all_users
where length(username) = 3;
CURSOR emails_cur (cli all_users.username%TYPE) IS
SELECT id, name
FROM cli.org;
BEGIN
FOR client IN client_cur LOOP
dbms_output.put_line('Client is '|| client.username);
FOR email_rec in client_cur(client.username) LOOP
dbms_output.put_line('Org id is ' ||email_rec.id || ' org nam ' || email_rec.name);
END LOOP;
END LOOP;
END;
/
and
DECLARE
CURSOR c1 IS
SELECT distinct username from all_users where length(username) = 3;
client c1%rowtype;
cursor c2 is Select id, name, allow_digest_flg from c1.username.org;
digest c2%rowtype;
BEGIN
OPEN c1;
loop
FETCH c1 INTO client;
open c2;
loop
fetch c2 into digest;
DBMS_OUTPUT.PUT_LINE('digest is : ' || c2.id || ' and name is ' || c2.name || ' flg is ' || c2.allow_digest_flg );
end loop;
end loop;
END;
/
AND LOT OF CHANGES TO THESE.
Can someone help me. THANKS
source
share