PLSQL,starting,Oracle,series,articles,After,e
Quick Search for:  in language:    
PLSQL,starting,Oracle,series,articles,After,e
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
SQL Stats

 Code: 31,327 lines
 Jobs: 372 postings

 
Sponsored by:

 

You are in:

 
Login



Latest Code Ticker for SQL.
Unix Date Convertor Function
By George Graff on 10/23


Insert pipe delimited rows into multiple rows.
By Charles Toepfer on 10/21


Logfiles by PL/SQL
By Stephan Rechberger on 10/21


To display a name in a default language if the given one doesn't exist
By Serge Alard on 10/18


Order by column except a few values
By Serge Alard on 10/18


Introduction to PL/SQL (Series 3) Cursors
By David Nishimoto on 10/14


Sorting a String using T-SQL
By Gaurav Pugalia on 10/12


Protecting against TSQL virii, worms and time bombs
By Joseph Gama on 10/11


Click here to see a screenshot of this code!Get size in bytes of SP, View, Trigger, UDF or Rule
By Joseph Gama on 10/11

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

Oracle PLSQL series 1

Print
Email
 

Submitted on: 9/21/2002 9:01:19 PM
By: David Nishimoto 
Level: Beginner
User Rating: By 2 Users
Compatibility:Oracle

Users have accessed this article 1342 times.
 
(About the author)
 
     I'm starting a Oracle PLSQL series of articles. After extreme demand to share my experiences learning PL/SQL, I will be creating a six to seven week - series. Make sure to join in and share ideas. Next week, I'll be covering various methods for data manipulation language (dml):select, insert, delete, and update

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.

I began professional programming using Oracle PLSQL, in 1998, as part of, an centralized budget project. The budget project was part of an Y2K project. Its purpose was to control budget appropriations, through out the world, for a particular organization. The Contractors office space included: a table, two computers, and our chairs. From our work-area, the view was great, for we sat infront of two windows, overlooking the city. The machines contained software, such as, visual basic, SQL Plus, and windows NT. All the necessary software, to build a world wide enterprise software managing the organizations budget. With over a million records, Oracle was the preferred database storage software. It provided the best volume managment by performance and could be designed nicely, to meet centralization issues. So, time was ticking and the software needed to be built before the turn of the century.

There is nothing better than the challenge to building a new software system. The adrenal was plumping and designs were beginning to materialized. The big picture needed to be built. So starting on white boards, the team talked about and sketched diagrams showing how the data was to be stored.

The buzz word, "relational databases" emmerged in the conversation. Jargon like rows, columns, primary keys, foreign keys, one to many, many to many, joins, and constraints were exchanged between developers and database administrator. In a relational database, the data is stored as tables. Tables contain fields describing the type of date, container name of the data, size, decimal precision, and required or not required constraints. Technically, a table is an object residing in a schema. A schema can contain other objects like indexes, views, snapshots, functions, procedures, packages, sequences, and clusters.

CREATE TABLE my_table_name( 
{field1} VARCHAR2(10) NOT NULL, 
{field2} NUMBER(10) ) 
PCTFREE 30 PCTUSED 60 TABLESPACE a_tablespace_name 
STORAGE ( INITIAL integer NEXT integer ); 

Wew! I had to describe schema tables definitions. Ok, so what type of information does the database administrator need? Well here's a few to steps to consider when adding tables to the schema.

1) Define each field name, field type, size, required for the tables 
2) Define and create the primary key constraints 
3) Define and create the foreign key constraints 
4) Define and create the indexes 

There is alot of planning. The data needed to analyzed, to determine, what data kept the field information kept the data records unique. This field was called the primary key. The primary key is always unique and provides a field or fields associated creating the primary key index.

Likewise, the foreign key is a field reference, into another table. The foreign key points back to the primary key of another table. Foreign keys prevent dependant tables from added orphan records. Orphan records are bad because they jeapordize the integrity of your data. Bad data makes the system unreliable. An example of an primary key and foreign key relationship would exist between an employee table and an address table.

The primary key in the employee table could be the employee identification number and the foreign key in the address book is the employee identification number linking back to the employee table.

Primary Key Constraint 
ALTER TABLE employee ADD 
( CONSTRAINT EMPLOYEE_EMPLOYEEID_PK PRIMARY KEY (EMPLOYEEID) 
USING INDEX 
TABLESPACE a_tablespace_name 
PCTFREE 10 STORAGE 
(INITIAL 20K NEXT 20K PCTINCREASE 0) 
) 
Foreign Key Constraint 
ALTER TABLE address 
ADD ( CONSTRAINT (employeeid_pk) 
FOREIGN KEY (employeeid ) REFERENCES employee ( employeeid ) 

So my constraints are created and data integrity were looking good. The next problem was performance improvements, since some of the database tables contained millions of records. During query extraction of data full table scans over a million records were very time consuming. The user didn't want to wait for over a few seconds to receive their data. It was important for the user to have real time response when they pressed a button. The database adminstrator analyzed what fields had criteria applied to them and created an index. An index is a object containing only fields that are being search. A index contains a pointer to the physical table records. So searching an index for a data match is much faster.

CREATE {UNIQUE} 
name_idx 
ON employee ( name ) 
PCTFREE 10 TABLESPACE (table_space_name) 
STORAGE (INITIAL 20K NEXT 20K PCTINCREASE 0); 

If UNIQUE is specified the key in the index is force to be unique otherwise the index is assumed to be non-unique.

Wow! Queries ran alot faster. SQL Plus has commands that measure query execution time in milliseconds.

In summary, planout and sketch, what your data will look like. Decide how the data will be stored. Apply rules of normalization (PL/SQL Haven) to move data around so rules of a relational database can be applied to your data. Once your table schema design has been completed start writing oracle scripts to create your schema. Try loading your data. If constraint problem occur you can enable and disable your constraints and indexes. Its more efficient to load your data into the table with index and constraints disabled. After the data has been loaded then enable your indexes and constraints.

Next week, I'll be describing Select, Insert, Update, and Delete; all the CRUID about data manipulation. David Nishimoto LSS


Other 9 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this article(in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
9/23/2002 10:03:20 AM:Markus Q
Question: So... Why would you create an index over a view?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this article has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular article, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | SQL Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.