How to access columns on a cursor which is a join on all elements of two tables in Oracle PL/SQL -


i trying run cursor on full join of 2 tables having problem accessing columns in cursor.

create  table apple(     my_id           varchar(2) not null,     a_timestamp     timestamp,     a_name          varchar(10) );  create  table banana(     my_id           varchar(2) not null,     b_timestamp     timestamp,     b_name          varchar(10) ); 

i have written full join return related rows tables , b of 2 timestamps in future. i.e. if row in table apple has timestamp in future fetch row apple joined row banana on my_id similarly, if row in table banana has timestamp in future fetch row banana joined row apple on my_id full join works me.

select * apple full join banana b on  a.my_id = b.my_id      (       a.a_timestamp > current_timestamp       or b.b_timestamp > current_timestamp      ); 

now want iterate on each joined record , processing. able access columns present in 1 tables getting error when trying access column names same in both tables. ex. id in case.

create or replace  procedure testproc(somedate in date) cursor c1     select * apple full join banana b on  a.my_id = b.my_id      (       a.a_timestamp > current_timestamp       or b.b_timestamp > current_timestamp      );  begin     rec in c1     loop             dbms_output.put_line(rec.a_name);         dbms_output.put_line(rec.a_timestamp);         dbms_output.put_line(rec.my_id);     end loop; end testproc; 

i error when compile above proc:

error(16,28): pls-00302: component 'my_id' must declared

and not sure how access my_id element. sure pretty straight forward new database programming , have been trying unable find right way it. appreciated. thanks

one other thing can in case join tables using clause instead of using on, in:

select *   apple   full join banana b     using (my_id) a.a_timestamp > current_timestamp or       b.b_timestamp > current_timestamp 

using can used if columns on both tables have same name, , comparison of key values made using equality ('=') operator. in result set there 1 column named my_id along other columns both table (a_timestamp, b_timestamp, etc).

share , enjoy.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -