Presentation is loading. Please wait.

Presentation is loading. Please wait.

5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.

Similar presentations


Presentation on theme: "5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping."— Presentation transcript:

1 5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping

2 5. Simple SQL using Oracle2 SQL DML DML data manipulation language –insert –update –delete –select

3 5. Simple SQL using Oracle3 insert, 98 insert one new row into a table 2 syntaxes –insert into student values ('Christian', 'Roskilde', 4) values must come in same order as attributes in table definition –insert into student (name, semester) values ('Christian', 4) values come in the stated order missing values use –default value –null

4 5. Simple SQL using Oracle4 insert dates, 99 Attributes with data type date requires special attention –default format DD-MM-YYusing current century –use the built-in to_date function to convert a string to a date to_date('08 mar 1966', 'DD MON YYYY') insert into student (name, birthday) values ('Anders', to_date('08 mar 1966', 'DD MON YYYY') )

5 5. Simple SQL using Oracle5 Sequences, 196 Primary keys are often simple ID's –integers, not carrying data MS Access: auto number MS SQL Server: identity Oracle: sequence –generates a sequence of unique numbers –page 196-197 –Fig. 9-7 + 9-8, page 197 –Fig. 9-9, page 198

6 5. Simple SQL using Oracle6 Update, 103 Update an existing row - or more rows. Example update student set semester = semester + 1 where semester < 5 no where clause ⇒ updates every row

7 5. Simple SQL using Oracle7 Delete, 105 deletes one or more rows from a table. Example delete from student where grade <= 3 –no where clause ⇒ delete every row!

8 5. Simple SQL using Oracle8 Select, 105 Simple select –select columns from tablename –variations wild card * –select all columns select distinct attribute … –excludes equal rows (equals attribute values) in the result column aliases –select columnname [as] alias, »You can use the keyword AS if you like »I always use AS

9 5. Simple SQL using Oracle9 Select II, 106 Concatenation –String columns may be concatenated using || select firstname || ' ' || lastname … Arithmetic operations –Number columns may be used in arithmetic operations +, -, *, /

10 5. Simple SQL using Oracle10 select … where, 114 The where clause restrict the number of rows in the result. Operators in where –AND, OR, NOT combining boolean statements –IS NULL … where column IS NUL ordinary equality (=) with NULL is always false, –NULL == NULL is false –BETWEEN … AND … where age between 45 and 78 –IN … where country in ('DK', 'SE', 'NO') –LIKE … where firstname like 'And%'wild card: 0 or more chars … where firstname like 'A_ders'wild card: 1 characters Don’t use == with wildcards, use like

11 5. Simple SQL using Oracle11 Sorting, 122 The DBMS may order the result of a select Syntax –select … order by col1, col2 asc / desc ascascending descdescending –col1primary order –col2 secondary order –Eample fig. 5-38 – 5-40, page 124 Never sort the result in an application program!

12 5. Simple SQL using Oracle12 Built-in functions, 133 Functions on a single row –Character functions Fig. 6-1 + 6-2, page 134 –Number functions Fig. 6-6 + 6-7, page 138 –Date functions Fig. 6-8 + 6-9, page 139 + 6-10, page 140 select sysdate from dual –current time –dual is a dummy table, it doesn’t exist –Conversion functions Fig. 6-12, page 144 + Figure 6-15, page 145

13 5. Simple SQL using Oracle13 Group functions, 147 Functions on a table –Fig. 6-19, page 147 –functions may be computed on groups of data select attribute functions … group by attribute select grade, count(*) from students group by grade select semester, avg(grade) from students group by semester –having clause restricts the groups select col functions … group by col having condition select grade, count(*) from students group by grade having count(*) > 4small groups excludes


Download ppt "5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping."

Similar presentations


Ads by Google