Question

I have a region in oracle apex to which the data is getting from an pl/sql.

The following is the pl/sql source:

begin    
    for drow in ( select * from books where book_id = :P13_BooK_ID ) loop
        htp.prn('<table border=0>
              <tbody>
                <tr>
                  <td valign=top>
                      <table border=0>
              <tbody>
                                     <tr>
                  <td >Reporting Period</td>    
                  <td >' || to_char(drow.REPORTING_PERIOD, 'MM-DD-YYYY') || '</td>
                </tr>   
                 <tr>
                  <td >L Key</td>    
                  <td >' || drow.L_KEY || '</td>
                </tr>
                <tr>
                  <td >Name</td>
                  <td >' || drow.BooK_NAME || '</td>
                </tr>                   
                <tr>
                  <td >C Type</td>
                  <td >' || drow.C_TYPE || '</td>
                </tr>                   
                <tr>
                  <td >E Count</td>
                  <td >' || drow.E_COUNT || '</td>
                </tr>
              </tbody>
            </table>');    
    end loop;
end;
/

Now I would like to add two more details(principal,director) into this region which are in another table called school and I have a common column in these two tables books,school as books.l_key = school.k_key.

How can I add these two details in the above region and there are many common column names in both the tables so when I tried as:

for drow in ( select * from books b, school s where book_id = :P13_BooK_ID and books.l_key =school.k_key) loop

it shows me error

ORA-06550: line 4, column 2: PLS-00402: alias required in SELECT list of cursor to avoid duplicate column names ORA-06550: line 4, column 2: PL/SQL: Statement ignored

can someone tell me how can I get these two details to add in the region. Thanks

Was it helpful?

Solution

As the error says, you need to specify which columns you want to have in your cursor and give it different aliases. For example, if you have column ID in both tables, to avoid indeterminate behaviour, you need to specify cursor like this:

for drow in ( select b.id books_id, s.id school_id from books b, school s where b.book_id = :P13_BooK_ID and books.l_key =school.k_key) loop

And access them accordingly, i.e. drow.books_id or drow.school_id.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top