Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005
■SETTING UP YOUR ENVIRONMENT xliii OWNER, OBJECT_NAME, SUBOBJECT_NAME, OBJECT_ID, DATA_OBJECT_ID, OBJECT_TYPE, CREATED, LAST_DDL_TIME, TIMESTAMP, STATUS, TEMPORARY, GENERATED, SECONDARY from big_table where rownum user, tabname => 'BIG_TABLE', method_opt => 'for all indexed columns', cascade => TRUE ); end; / select count(*) from big_table; I gathered baseline statistics on the table and the index associated with the primary key. Additionally, I gathered histograms on the indexed column (something I typically do). Histograms may be gathered on other columns as well, but for this table, it just isn’t necessary. Coding Conventions The one coding convention I use in this book that I would like to point out is how I name variables in PL/SQL code. For example, consider a package body like this: create or replace package body my_pkg as g_variable varchar2(25); procedure p( p_variable in varchar2 ) is l_variable varchar2(25); begin null; end; end;
xliv ■SETTING UP YOUR ENVIRONMENT Here I have three variables: a global package variable, G_VARIABLE; a formal parameter to the procedure, P_VARIABLE; and finally a local variable, L_VARIABLE. I name my variables after the scope they are contained in. All globals begin with G_, parameters with P_, and local variables with L_. The main reason for this is to distinguish PL/SQL variables from columns in a database table. For example, a procedure such as the following: create procedure p( ENAME in varchar2 ) as begin for x in ( select * from emp where ename = ENAME ) loop Dbms_output.put_line( x.empno ); end loop; end; will always print out every row in the EMP table, where ENAME is not null. SQL sees ename = ENAME, and compares the ENAME column to itself (of course). We could use ename = P.ENAME— that is, qualify the reference to the PL/SQL variable with the procedure name—but this is too easy to forget and leads to errors. I just always name my variables after the scope. That way, I can easily distinguish parameters from local variables and globals, in addition to removing any ambiguity with respect to column names and variable names.
- Page 2 and 3: Expert Oracle Database Architecture
- Page 4 and 5: Contents Foreword . . . . . . . . .
- Page 6 and 7: ■CONTENTS v Block Buffer Cache .
- Page 8 and 9: ■CONTENTS vii ■CHAPTER 9 Redo a
- Page 10 and 11: ■CONTENTS ix ■CHAPTER 12 Dataty
- Page 12 and 13: Foreword “THINK.” In 1914, Thom
- Page 14 and 15: ■FOREWORD xiii Tom is an aficiona
- Page 16 and 17: About the Technical Reviewers ■JO
- Page 18 and 19: Introduction The inspiration for th
- Page 20 and 21: ■INTRODUCTION xix • Exposure to
- Page 22 and 23: ■INTRODUCTION xxi Chapter 3: File
- Page 24 and 25: ■INTRODUCTION xxiii Next up are t
- Page 26 and 27: Setting Up Your Environment In this
- Page 28 and 29: ■SETTING UP YOUR ENVIRONMENT xxvi
- Page 30 and 31: ■SETTING UP YOUR ENVIRONMENT xxix
- Page 32 and 33: ■SETTING UP YOUR ENVIRONMENT xxxi
- Page 34 and 35: ■SETTING UP YOUR ENVIRONMENT xxxi
- Page 36 and 37: ■SETTING UP YOUR ENVIRONMENT xxxv
- Page 38 and 39: ■SETTING UP YOUR ENVIRONMENT xxxv
- Page 40 and 41: ■SETTING UP YOUR ENVIRONMENT xxxi
- Page 42 and 43: ■SETTING UP YOUR ENVIRONMENT xli
- Page 46 and 47: CHAPTER 1 ■ ■ ■ Developing Su
- Page 48 and 49: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 50 and 51: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 52 and 53: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 54 and 55: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 56 and 57: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 58 and 59: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 60 and 61: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 62 and 63: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 64 and 65: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 66 and 67: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 68 and 69: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 70 and 71: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 72 and 73: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 74 and 75: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 76 and 77: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 78 and 79: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 80 and 81: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 82 and 83: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 84 and 85: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 86 and 87: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 88 and 89: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 90 and 91: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
- Page 92: CHAPTER 1 ■ DEVELOPING SUCCESSFUL
xliv<br />
■SETTING UP YOUR ENVIRONMENT<br />
Here I have three variables: a global package variable, G_VARIABLE; a formal parameter to<br />
the procedure, P_VARIABLE; <strong>and</strong> finally a local variable, L_VARIABLE. I name my variables after<br />
the scope they are contained in. All globals begin with G_, parameters with P_, <strong>and</strong> local variables<br />
with L_. The main reason for this is to distinguish PL/SQL variables from columns in a<br />
database table. For example, a procedure such as the following:<br />
create procedure p( ENAME in varchar2 )<br />
as<br />
begin<br />
for x in ( select * from emp where ename = ENAME ) loop<br />
Dbms_output.put_line( x.empno );<br />
end loop;<br />
end;<br />
will always print out every row in the EMP table, where ENAME is not null. SQL sees ename =<br />
ENAME, <strong>and</strong> compares the ENAME column to itself (of course). We could use ename = P.ENAME—<br />
that is, qualify the reference to the PL/SQL variable with the procedure name—but this is too<br />
easy to forget <strong>and</strong> leads to errors.<br />
I just always name my variables after the scope. That way, I can easily distinguish parameters<br />
from local variables <strong>and</strong> globals, in addition to removing any ambiguity with respect<br />
to column names <strong>and</strong> variable names.