Basic_SQL

Basic_SQL - P L / S Q L SQL Basic Oracle10g Developer:...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
P L / S Q L Oracle10 g Developer: PL/SQL Programming 1 SQL Basic
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
P L / S Q L SQL SELECT A common use is to select data from the tables located in a database. Immediately, we see two keywords: we need to SELECT information FROM a table. Hence we have the most basic SQL structure: SELECT "column_name" FROM "table_name" Oracle10 g Developer: PL/SQL Programming 2
Background image of page 2
P L / S Q L SQL DISTINCT The SELECT keyword allows us to grab all information from a column (or columns) on a table. This, of course, necessarily mean that there will be redundancies. What if we only want to select each DISTINCT element? This is easy to accomplish in SQL. All we need to do is to add DISTINCT after SELECT . The syntax is as follows: SELECT DISTINCT "column_name" FROM "table_name" Oracle10 g Developer: PL/SQL Programming 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
P L / S Q L SQL WHERE We might want to conditionally select the data from a table. To do this, we use the WHERE keyword. The syntax is as follows: SELECT "column_name" FROM "table_name" WHERE "condition“ This condition can be a simple condition (like the one presented in the previous section), or it can be a compound condition. Oracle10 g Developer: PL/SQL Programming 4
Background image of page 4
P L / S Q L SQL AND OR Compound conditions are made up of multiple simple conditions connected by AND or OR . There is no limit to the number of simple conditions that can be present in a single SQL statement. The syntax for a compound condition is as follows: SELECT "column_name" FROM "table_name" WHERE "simple condition" {[AND|OR] "simple condition"}+ The {}+ means that the expression inside the bracket will occur one or more times. Oracle10 g Developer: PL/SQL Programming 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
P L / S Q L SQL IN The syntax for using the IN keyword is as follows: SELECT "column_name" FROM "table_name" WHERE "column_name" IN ('value1', 'value2', . ..) The number of values in the parenthesis can be one or more, with each values separated by comma. Values can be numerical or characters. If there is only one value inside the parenthesis, this commend is equivalent to WHERE "column_name" = 'value1' Oracle10 g Developer: PL/SQL Programming 6
Background image of page 6
P L / S Q L SQL BETWEEN The BETWEEN keyword allows for selecting a range. The syntax for the BETWEEN clause is as follows: SELECT "column_name" FROM "table_name" WHERE "column_name" BETWEEN ‘value1’ AND ‘value2’ This will select all rows whose column has a value between 'value1' and 'value2'. Oracle10 g Developer: PL/SQL Programming 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
P L / S Q L SQL Wildcard In SQL, there are two wildcards: % (percent sign) represents zero, one, or more characters. _ (underscore) represents exactly one character. Examples: 'A_Z‘, 'ABC%‘, '%XYZ‘, '%AN%‘, '_AN%' Oracle10 g Developer: PL/SQL Programming 8
Background image of page 8
P L / S Q L SQL LIKE LIKE allows you to do a search based on a pattern rather than specifying exactly what is desired (as in IN ) or spell out a range (as in BETWEEN ). The syntax is as follows:
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/17/2012 for the course GCIS 511 taught by Professor Liu during the Fall '10 term at Gannon.

Page1 / 67

Basic_SQL - P L / S Q L SQL Basic Oracle10g Developer:...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online