PL/SQL Procedure Error by dbms output function

时间:2019-01-09 21:47:03

标签: sql oracle plsql dbms-output

I have the following task: "Write a Print Siblings procedure (p person) that has as input the name or ID of the person from the family tree scheme and, as a result, outputs the list of siblings."

Table Relations which contains the information of the successor(Nachfolger) and predecessor(Vorgänger) of a person. Table Relations

My procedure is the following:

create or replace procedure PrintSiblings4(p_Person varchar2)
is
  cursor c_geschwister is select nachfolger
  from relations
  where nachfolger != p_Person and vorgänger = 
    (select vorgänger from relations
    Where nachfolger = p_Person and rownum = 1) ;
  v_geschwister  c_geschwister%rowtype;
begin
  open c_geschwister;
  loop
    fetch c_geschwister into v_geschwister;
    exit when c_geschwister%NOTFOUND;
    dbms_output.put_line('geschwister' || v_geschwister);
  end loop;
end;

I get the following error messages by the sqldeveloper if I compile the procedure:

Error (14,22): PLS-00306: Incorrect number or types of arguments in call to '||'

I can´t unterstand why it´s not working. I used an explicit cursor to handle the problem that i get more than 1 row, but its not working.

1 个答案:

答案 0 :(得分:2)

change:

dbms_output.put_line('geschwister' || v_geschwister);

to:

dbms_output.put_line('geschwister' || v_geschwister.nachfolger);

Here a new (cleaner/compacter) version of your procedure. We get here all columns of table relations:

create or replace procedure print_siblings4(p_person varchar2)
is
  cursor c_geschwister is 
  select *
  from relations
  where nachfolger != p_person 
  and vorgänger = 
  (
  select vorgänger 
  from relations
  where nachfolger = p_person 
  and rownum = 1
  ) 
  ;

begin
  for r_geschwister in c_geschwister loop
    dbms_output.put_line('geschwister' || v_geschwister.nachfolger);
  end loop;
end;