Oracle
  Home arrow Oracle arrow Page 2 - Oracle Database Fundamentals
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ORACLE

Oracle Database Fundamentals
By: Mamun Zaman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 73
    2007-05-01


    Table of Contents:
  • Oracle Database Fundamentals
  • Creating Database Tables
  • Inserting Data
  • Selecting Data
  • Updating Data

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Oracle Database Fundamentals - Creating Database Tables
    ( Page 2 of 5 )

    You need to log in to Oracle before executing any SQL statement. SQL is case-insensitive, even with the Oracle username and password!

    The main data types used in Oracle are: varchar2(x) which can hold a variable length of string up to x characters long; number, an integer or real value up to 40 decimal digits; and date, which holds a date. For our example department table, the Dept field can be varchar2, while the EmpID and DeptID fields can be numbers. To create the table, the SQL statement is like this:

    create table tablename (columnname type, columnname type ...);

    create table department (
       Dept varchar2(20),
       EmpID number,
       DeptID number
    );

    If we execute the above SQL statement a table will be created with the name "department." To view the information of a table, the describe or desc statement can be used, like so:

    describe department;

    or

    desc department;

    So the SQL for the employee table would be:

    create table employee (
       "First Name" varchar2(20),
       "Last Name" varchar2(20),
       Address varchar2(60),
       Phone varchar2(15),
       Salary number,
       EmpID number,
       DeptID number
    );
     

    Do you find any differences between the column names? The "First Name" and "Last Name" column names have a space in between the words. To use spaces in column names, you need to enclose them with quotation marks ("").

    Here are some things to remember:

    • SQL select statements return column names in upper case.
    • If you want to mix upper cases and lower cases in the column name, then you need to enclose them with quotation marks ("").
    • Single quote marks are used to express a string in SQL. 'String' is a string but "Not a String" is not.

    Oh no! I forgot to add the "Joining Date" column in the employee table. Don't worry. Oracle tables can be altered to add/delete columns or change column types. To add the "Joining Date" column we need to execute following SQL.

    alter table employee add ("Joining Date" date);

    We used varchar2 for the Phone column. If we want to change this column type to number then we need to modify the table using the following SQL: 

    alter table employee modify (Phone number);

    To drop a column from a table we need to use the following statement.

    alter table tablename drop column columnname;

    If it's not specified, then columns are nullable by default, i.e. they can hold null values. To specify a column as not nullable add the words "not null" after the column type in create table or alter table statements, like so:

    alter table employee add ("Joining Date" date not null);

    Once we tried to create a table of about 1200 columns, but failed, because Oracle only supports 1000 columns in a single table!

    Now we have some idea of how to create and alter tables. In the next section we will show you how to insert some data in our tables.



     
     
    >>> More Oracle Articles          >>> More By Mamun Zaman
     

       

    ORACLE ARTICLES

    - Oracle's Turn to Play in the Sun
    - Implementing and Using Oracle`s Restore Poin...
    - Tuning PL/SQL Code
    - Debugging PL/SQL Code
    - Testing PL/SQL Code
    - Working With PL/SQL Code
    - Conditional Compilation for Oracle Database ...
    - Compile-Time Warnings for Oracle DB 10g
    - Compiling PL/SQL Code for an Oracle Database
    - Troubleshooting PL/SQL Code
    - Managing PL/SQL Code
    - Data Manipulation and More for HTML DB Appli...
    - Oracle Database Fundamentals
    - Adding Processes to HTML DB Applications
    - Adding Computations, Processes, and Validati...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT