Uni DB1 Syntax Details

Syntax details for the DB1 (databases) course at HdM Stuttgart

Felicitas Pojtinger

2022-02-01

“so basically i am monkey” - monke, monkeeee

2 Acknowledgements

Most of the following is based on the Oracle Tutorial.

3 Reset Everything

Run the following to get the commands to drop all tables and their constraints:

begin
  for i in (select index_name from user_indexes where index_name not like '%_PK') loop
    execute immediate 'drop index ' || i.index_name;
  end loop;

  for i in (select trigger_name from user_triggers) loop
    execute immediate 'drop trigger ' || i.trigger_name;
  end loop;

  for i in (select view_name from user_views) loop
    execute immediate 'drop view ' || i.view_name;
  end loop;

  for i in (select table_name from user_tables) loop
    execute immediate 'drop table ' || i.table_name || ' cascade constraints';
  end loop;

  execute immediate 'purge recyclebin';
end;

Now copy & paste the output into SQL Developer’s SQL worksheet and hit F5.

4 SQL

4.1 Operators

Operator Description
= Equality
!=,<> Inequality
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
IN Equal to any value in a list of values
ANY/ SOME/ ALL Compare a value to a list or subquery. It must be preceded by another operator such as =, >, <.j
NOT IN Not equal to any value in a list of values
[NOT] BETWEEN n and m Equivalent to [Not] >= n and <= y.
[NOT] EXISTS Return true if subquery returns at least one row
IS [NOT] NULL NULL test

4.2 Joins

4.3 Aliases

4.4 Limits and Pagination

4.5 Dates and Intervals

4.6 Expressions

select product_name as "Product Name", list_price - standard_cost as "Gross Profit" from products order by "Gross Profit"

4.7 Grouping and Ordering

4.8 Counting and Sums

4.9 Inserting

4.10 Switches

4.11 Helper Functions

4.12 Auto-Generated Primary Keys

4.13 Modifying Columns

4.14 Virtual Columns

4.15 Modifying Tables

4.16 Constraints

4.17 Types

4.18 Views

4.19 Indexes

5 PL/SQL

5.1 Block Structure

5.2 Variables

5.3 Fetching Data

5.4 Branches and Expressions

5.5 Switches

5.6 Labels and Goto

5.7 Loops

5.8 Types and Objects

5.9 Exceptions

5.10 Cursors

5.11 Locks

5.12 Procedures

5.13 Functions

5.14 Packages

5.15 Triggers

5.16 Maps

5.17 Arrays