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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -