




























































































Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!





























































































José R. Paramá
Contents
Introduction Connecting to Oracle with Dbeaver Tables used in the examples Previous concepts Select statement Distinct Order by Predicates Functions Group by Having Join Subqueries Query composition
Introduction
Manufacturers comply with most of it, but some divergences exist. The SQL implemented in each product is called dialect. In spite of its name, it is not just a query language, it covers:
DDL (data definition language). DML (data manipulation language).
SQL can be used for any task inside the DBMS (creating users, creating permissions, granting permissions, controlling concurrency, creating structures to store and access data, etc.)
Introduction
Other characteristics: SQL can be embedded in programs written in general-purpose languages. It is a non-procedural language (we specify what we want, not how to get it).
It does not manage sets of rows (like the theoretical relational model), it manages collections of rows (there is no order, but repeated rows may exist).
Terminology also changes: tables, rows and columns instead of relations, tuples and attributes.
Tables used in the examples
DEPT Column Type Description DEPTNO NUMBER(2) NOTNULL^ Department number or code It is the primary key DNAME VARCHAR2(14) Department name LOC VARCHAR2(13) Municipality or city where the department islocated
EMP Column Type Description EMPNO: NUMBER(4) NOTNULL^ Employee number or code. It is the primary key of the table ENAME VARCHAR2(10) Employee name JOB VARCHAR2(9) Employee job
MGR NUMBER(4) Manager’s code Foreign key that (cyclically) references table EMP
HIREDATE DATE Hire date SAL NUMBER(7, 2) Monthly salary COMM NUMBER(7, 2) Commission
DEPTNO NUMBER(2) Code of the employee’s department. Foreign keythat references table DEPT
PRO Columns Type Description PRONO NUMBER(4) NOTNULL^ Project number/code It is the primary key PNAME VARCHAR2(10) Project name LOC VARCHAR2(13) City where the project is developed DEPTNO NUMBER(2)
Code of the department that manages the project. Foreign key that references table DEPT
EMPPRO Column Type Description EMPNO NUMBER(4) NOT NULL Employee number/code Foreign key that references table EMP PRONO NUMBER(4) NOT NULL Project number/code Foreign key that references table PRO HOURS NUMBER(2) Number of hours that an employee worked in a project
A null in COMM means that the employee does not work on commission (the value is not applicable).
A null in MGR means that the employee does not have a manager (it is also "not applicable")
Primary key of the table
Tables used in the examples
Previous concepts
Null values:
unkown or because it is not applicable.
It must be differentiated from any other value, including 0 in the case of numeric data, or the empty string in the case of character data.
Previous concepts
Expressions^1 :
An expression is the formulation of a sequence of operations, that is, a combination of operators, operands and parentheses that, when executed,
The operands can be constants, column names, functions, other expressions and other elements.
The data type of each operand must be the same. If an operand is null, the result is also null.
Numeric operators: + - * / Alphanumeric operators: || (concatenation of two character strings) Ejemplos: • •^3 ’House’ No son expresiones:
(^1) The definition of expression is restricted to the “Core SQL” version of the standard
Contents
Introduction
Previous concepts
Select statement
Distinct
Order by
Predicates
Functions
Group by
Having
Join
Subqueries
Query composition
Select statement
The SELECT statement is used to select or retrieve data from one or more tables.
It works with one or more tables in the DB and the result is another table, sometimes called result table, but this result table will not be part of the DB.
SELECT [DISTINCT|ALL] {* |
Select statement
Select ‘Nombre: ’ || ename, sal*0. from emp where deptno=10;
The result after this step is
True: keep it
Select statement
Select ‘Nombre: ’ || ename, sal*0. from emp where deptno=10; False False False False False False False False False True: keep it
True: keep it False
False
The result after this step is
The name of a column can be changed.
SELECT
Select statement
select ename as nombre , sal salario , sal+comm as "ingresos mensuales" , hiredate "fecha contratación" from emp;
Contents
Introduction
Previous concepts
Select statement
Distinct
Order by
Predicates
Functions
Group by
Having
Join
Subqueries
Query composition