The remainder of this chapter is a case study of a function published by Oracle Corporation in its Oracle Forms documentation. Now, I don’t mean to pick on Oracle Corporation. In fact, I find that in general their documentation—including their sample code fragments—is outstanding and improved beyond words over earlier manuals. To show just how far they’ve come, we’ll look at a function in the Oracle Forms Reference Manual, Volume 1. The manual presents a function called Is_Value_In_List, which returns the row number of the specified value if it is found in the record group (or “list”). Here is the Oracle Corporation-suggested implementation for such a function (reproduced as is, but without the comments):
/* Filename on web page: isvalinlis.sql */
FUNCTION Is_Value_In_List( the_value VARCHAR2,
the_rg_name VARCHAR2,
the_rg_column VARCHAR2)
RETURN NUMBER IS
the_rowcount NUMBER;
rg_id RECORDGROUP;
gc_id GROUPCOLUMN;
col_val VARCHAR2(80);
Exit_Function EXCEPTION;
BEGIN
rg_id := Find_Group( the_rg_name );
If Id_Null(rg_id) THEN
Message ('Record Group '||the_rg_name||' does not exist.'),
RAISE Exit_Function;
END IF;
gc_id := Find_Column( the_rg_name||'.'||the_rg_column );
If Id_Null(gc_id) THEN
Message ('Column '||the_rg_column||' does not exist.'),
RAISE Exit_Function;
END IF;
the_rowcount := Get_Group_Row_Count( rg_id );
FOR j IN 1..the_rowcount LOOP
col_val := Get_Group_Char_Cell( gc_id, j );
IF UPPER(col_val) = UPPER(the_value) THEN
RETURN j;
END IF;
END LOOP;
RAISE Exit_Function;
EXCEPTION
WHEN Exit_Function THEN
RETURN 0;
END; Here’s how you would use the function in another program: IF Is_Value_In_List ('hello', 'word_group', 'name') > 0
THEN
MESSAGE ('they said hello already'),
END IF; As the first question in the case study, critique this usage. Do you find the module name particularly descriptive or appropriate? To help you answer this question, begin by expressing the condition in the IF statement as an English sentence. |