sql - Oracle: IN function within an IF block -


i have cursor c2, 1 column 'note', containing numbers. want check, whether column contains 5 , change local variable if so.

this:

create or replace procedure proc  result varchar(50);  cursor c2 select  note    student;      begin  if c2.note in(5) result := 'contains 5';  dbms_output.put_line(result);  end; / 

doesnt work.

please help!

you have loop on records/rows returned in cursor; can't refer cursor that:

create or replace procedure proc     result varchar(50);      cursor c2         select  note            student;     begin     r2 in c2 loop         if r2.note = 5 -- in work doesn't add             result := 'contains 5';         end if;     end loop;      dbms_output.put_line(result); end; / 

but if you're testing existence of record value 5 don't need cursor:

create or replace procedure proc     result varchar(50); begin     select max('contains 5')     result     student     note = 5;      dbms_output.put_line(result); end; / 

if there rows 5 you'll 'contains 5' string; if not you'll null. max() stops exception being thrown if there either 0 or more 1 matching records in table.


Comments

Popular posts from this blog

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -