Professional Documents
Culture Documents
Page 1
Page 2
Page 3
/* 10. Move repeated operations to local variables. */ v_name := UPPER (comm_pkg.rewards(indx).nm); v_sal := comm_pkg.rewards(indx).sal * 2; /* 11. Skip assignment to v_info; put in SQL directly. */ IF v_name LIKE v_nmfilter THEN UPDATE employee SET salary = v_sal, info = 'Doubled ' || TO_CHAR (indx - v_first) || 'th employee''s salary on ' || v_date || ' to ' || TO_CHAR (v_sal), commission = comm_pkg.rewards(indx).comm WHERE last_name = v_name; comm_pkg.rewards(indx).comm := 0; END IF; END LOOP; END IF; END; /
Page 4
Page 5
Page 6
Page 7
Page 8
Page 9
Commentary
The algorithm in this case uses a WHILE loop. For each iteration of the loop body, it checks to see if the sub-string occurs at the beginning of the string. If so, that sub-string is stripped off using SUBSTR and tested again. So which is the better implementation (version 1 or version2)? Neither is particularly long or complex. One should, however, always be concerned about the use of recursion, because it can be very resource-intensive. - Danny Wagenaar (danny@duvel.fmv.ulg.ac.be):
Page 10
Commentary
"We avoided the use of the char_in parameter in our implementation. We were careful not to use recursion to make sure there would be no problem with nesting depth. Also, we do not use INSTR to see if the substring_in is at the beginning of string_in, since this could potentially lead to a search through 32767 bytes for a nonexistent pattern. "My new solution to the lstrip problem is significantly faster than the one I sent yesterday when used to strip large numbers of substrings from the input string. It is also much faster on stripping small iterations, although that is not really noticeable to the user unless the function is called a lot. On top of that, the code is smaller while maintaining readability." - Ken Geis and Jay Weiland (kgeis@cchem.berkeley.edu and jweiland@cchem.berkeley.edu)
Page 11
Page 12
Page 13