Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

EXECUTE IMMEDIATE and testing for returned values

47727Oct 23 2002
I am using EXECUTE IMMEDIATE to perform a dynamic sql action. I need to test whether or not there are values returned from this statement so that I can put some conditional logic in my program. I would normally do this with a cursor and check if cur%FOUND/%NOTFOUND, but I don't know how to do this with EXECUTE IMMEDIATE. Look at the comments in the code below for the specific action I am trying to perform.


FUNCTION new_func(p_subj_seq IN subject.subj_seq%TYPE, p_cur_vnum IN form_log.visit_num%TYPE,
p_prev_vnum IN form_log.visit_num%TYPE, p_dmonth IN p2_diary.dmonth%TYPE,
p_dday IN p2_diary.dday%TYPE, p_diary_field IN VARCHAR2)
RETURN VARCHAR2 IS

v_result VARCHAR2(10) := 'FALSE';

BEGIN

EXECUTE IMMEDIATE 'SELECT * FROM p2_diary d, form_log f ' ||
'WHERE d.form_seq = f.form_seq ' ||
'AND f.subj_seq = ' || p_subj_seq ||
' AND f.visit_num = ' || p_cur_vnum ||
' AND d.dmonth = ' || p_dmonth ||
' AND d.dday = ' || p_dday ||
' AND ' || p_diary_field || ' IS NOT NULL';
--If this select comes back with 1 or more rows, I want to set v_result = 'TRUE'
--otherwise, if I get a no rows selected, I want to leave v_result = 'FALSE'

RETURN v_result;
END new_FUNC;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 20 2002
Added on Oct 23 2002
4 comments
1,561 views