Search code examples
oracle-sqldeveloper

SQL query returns necessary data, but the procedure doesn't


I need to create a procedure that returns the list of entries from two tables. Here's the code for the procedure:

create or replace PROCEDURE goods_to_transfer
    IS
     begin
        for rec in (select sales.good_id, sales.good_count, goods.priority 
                    FROM goods,sales 
                    where sales.good_id=goods.id and sales.delivered='YES');
 
    loop
        
    dbms_output.put_line( 'GOOD ID' || rec.good_id);
    dbms_output.put_line( 'GOOD COUNT' || rec.good_count);
    dbms_output.put_line( 'PRIORITY' || rec.good_priority);

   end loop;
     end goods_to_transfer;

The execution ends up with the following mistakes:

ORA-01403: no data found ORA-06512: in "C##XSENIA.GOODS_TO_TRANSFER", line 7 ORA-06512: in line 2

The same query returns all the necessary data:

select sales.good_id, sales.good_count, goods.priority FROM goods,sales 
        where sales.good_id=goods.id and sales.delivered='YES'

I wonder if anyone could possibly tell me, what do I do wrong. Thank you!


Solution

  • try to remove the ; at the end of the request

    for rec in (select sales.good_id, sales.good_count, goods.priority 
                        FROM goods,sales 
                        where sales.good_id=goods.id and sales.delivered='YES')