Never underestimate the supremacy of SQL. We have seen many programmers so overwhelmed by the idea of PL/SQL (finally, a structured programming language!) that they forget basic SQL. Simple tasks that are better suited to pure SQL are coded in PL/SQL, using many times more lines of code than are actually necessary. In general, SQL is easier to code, easier to understand, and much more efficient. For example to Exploit SQL, the following PL/SQL:
DECLARE
CURSOR C1 IS
SELECT fld1, fld2
FROM summary_table
WHERE fld3 = 1234;
xfld1 NUMBER;
xfld2 NUMBER;
xfld_tot NUMBER;
BEGIN
OPEN C1;
FETCH C1 INTO xfld1, xfld2;
xfld_tot := xfld1 + xfld2;
UPDATE summary_table
SET fld1 = 0,
fld2 = 0,
fld3 = xfld_tot
WHERE fld4 = 1234;
END;
should be coded as
BEGIN
UPDATE summary_table
SET fld1 = 0,
fld2 = 0,
fld3 = fld1 + fld2
WHERE fld4 = 1234;
END;
0 comments:
Post a Comment