摘要:Avoid Unstructured Exits from LoopsDo not EXIT or RETURN out of a FOR loop. * A FOR loop should only be used when you want to execute the body a fixed number of times. * Stay for the duration or...
阅读全文
09 2005 档案
摘要:Never Declare the FOR Loop Index FOR year_ind IN 1 .. 20LOOP calc_profits (year_ind);END LOOP; Do not declare the loop index variable (year_ind in the example above). PL/SQL does that for you autom...
阅读全文
摘要:Employ indentation rigorously with IF statements to show logical levels. Each IF, THEN, ELSE, ELSIF, and END IF should align within each level. For example:Nested IFs: IF THEN ELSE IF THEN ...
阅读全文
摘要:Avoid IF With BooleansSometimes you will code or come across conditional statements which, while valid, are unnecessary and cumbersome. Replace this IF statement: IF hiredate < SYSDATETHEN date_in_...
阅读全文
摘要:You can code real Boolean variables and literals (TRUE, FALSE and NULL values) in PL/SQL.Boolean variables and functions allow you to greatly improve readability of programs. You can hide complex expr...
阅读全文
摘要:The implication of ELSIF clauses is that if one condition is fulfilled, all others would fail -- they are mutually exclusive. The following IF statement is a classic misuse of ELSIF clauses. It might ...
阅读全文
摘要:Generally, you will want to use an ELSIF statement instead of nested IFs.A good candidate for a nested IF, however, arises when one condition is much more resource-intensive than the other. Suppose co...
阅读全文
摘要:Avoid Unnecessary Nested IFsThe following statements are equivalent. The flat structure expresses the logic more clearly and with less code.Nested: 1IF 2THEN 3 4ELSE 5 IF 6 THEN 7 ...
阅读全文
摘要:Anchor Declarations with %TYPE and %ROWTYPEYou must declare all variables and constants before you can use them. The best way to declare them is to use %TYPE and %ROWTYPE attributes to anchor your var...
阅读全文
摘要:Avoid all forms of “magic values” in your applications, such as: * Maximum number of accounts allowed.The codes used for “closed”, opened”, etc. MoreThis package below collects together a set of ...
阅读全文
摘要:Leverage PL/SQL DatatypesPL/SQL offers a real Boolean datatype, unlike the Oracle database. *. Values are TRUE, FALSE, NULL. These are not string values. *. You can also build Boolean functions ...
阅读全文
摘要:Employ naming conventions throughout your applications. For example: ExamplesCursors: company_curConstants: c_earliest_dateVariables: v_company_idParameters: p_company_id (Append parameter mode: compa...
阅读全文

浙公网安备 33010602011771号