midterm Flashcards

(64 cards)

1
Q

math operators

A

*
/
**

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

logical operators

A

AND
OR
NOT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

between

A

min and max value

WHERE colName BETWEEN val1 AND val2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

in clause

A

compare a value to a list of literal values that have been specified

WHERE colName IN (val1, val2, val3, val4)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

LIKE clause

wildcards

A

% represents zero or more characters

_ represents a single character

WHERE FIrst_Name LIKE ‘Herma%’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

DISTINCT clause
eliminates _____ records, fetching only ___ unique records when using a select statement

A

duplicate, unique

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

subquery syntax

A

SELECT emp_ID, name
FROM employees
WHERE salary =
(SELECT MAX(salary) FROM employees);

let you use an aggregate function in the where clause

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

types of joins (6)

A

inner join
left join
right join
full join
cross join
self join

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

input

A

V_name := ‘&name’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

NCHAR vs VARCHAR

A

when you insert a string shorter than the defined length into an NCHAR column, the database pads the string with spaces to math the defined length

varchar does not do this

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

NUMBER vs pls_int

A

number stores more than int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

if statements syntax

A

IF condition THEN
statements;

ELSIF condition THEN
statements;

ELSE
statements;
END IF;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

case statement syntax

A

CASE l_num

WHEN 11 THEN
statements;

WHEN 10 THEN
statements;

ELSE
statements

END CASE;
_________________________-
CASE
WHEN l_num > 11 THEN
statements;

WHEN l_num =10 THEN
statements;

ELSE
statements;

END CASE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

pls_integer vs simple_integer

A

pls_intger can store null values, simple_integer cannot store null values, it does not raise an overflow exception and it wraps around to zero

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

while loop syntax

A

WHILE condition LOOP
statements
END LOOP;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

IN vs OUT parameters

A

IN - read only
OUT - can change the value (write)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

EXCEPTIONS

syntax

A

zero_divide
case_not_found
no_data_found
rowtype_mismatch
too_many_rows
value_error

EXCEPTION
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT>PUT(‘error message’);
END:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

how to define an exception

A

DECLARE
varName EXCEPTION;

EXCEPTION
WHEN varName THEN
print statement
END;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

for loop syntax

A

FOR i IN 1 .. 20 LOOP
statments;
END LOOP;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

cursor declare syntax

A

declare
CURSOR cr IS SELECT cust_ID, cust_first, cust_last FROM SH.customers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

cursor attributes

A

%ISOPEN
%NOTFOUND
%FOUND
%ROWCOUNT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

4 steps in using an explicit cursor

A

declare
open
fetch
close

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

when fetching to a record or list of variables, the variables should be ___________

A

in the same order as the variables in the cursor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

declare record

A

TYPE rec_cust IS RECORD(l_id NUMBER, l_first VARCHAR(20));

– instance of record
Cust rec_cust

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
create a table of records create table using existing table structure
TYPE arr_cust IS TABLE OF rec_cust; --instance of arr_cust l_cust arr_cust TYPE arr_cust IS TABLE OF sh.customers%ROWTYPE; l_cust arr_cust;
26
bulk update syntax
OPEN cr; FETCH cr BULK COLLECT INTO l_cust; CLOSE cr; FORALL i IN 1 .. l_cust.LAST UPDATE MyCustomer SET Cust_city = 'Toronto' WHERE cust_ID = l_cust(i).cust_id;
27
stored procedures, functions and triggers ___ ___ more efficiently and effectively than SQL
manipulate data more efficiently and effectively than SQL
28
functions and procedures do not remain in the database after it is created (t/f)
f, remains in the database until it is dropped
29
stored procedures syntax
CREATE OR REPLACE PROCEDURE hello(l_name IN VARCHAR2) IS l_greeting VARCHAR2(24); BEGIN statement END;
30
how to execute a procedure
EXECUTE hello('myName)
31
how to call a procedure (3)
CALL procedureName(params); call from another script BEGIN procedureName(params); END; association operator BEGIn procedureName(param2 => val2, param1 => val1);
32
procedure notations
positional notation(the same order) named notation greeting(name => 'John', text => 'dear') mixed notation positional first, named second
33
INOUT meaning
both readable and writable
34
select and bulk collect syntax
SELECT * BULK COLLECT INTO l_tbl FROM sh.customers;
35
why do we use cursors steps
lets you manipulate the data before inserting into a table use cursor to collect data put data into created table put data into database table from created table
36
function vs procedure
A function ALWAYS returns 1 value A function cannot make changes to the database (INSERT, UPDATE, DELETE) a procedure does not have to return a value
37
It rarely makes sense to use ____ ____ for a function why
output parameters cannot edit the data
38
function syntax
CREATE OR REPLACE FUNCTION functionName(varName IN NUMBER) RETURN NUMBER IS varName2 NUMBER(12,2) BEGIN statements END;
39
A ___ is a named block of PL/SQL code that is executed or fired automatically when a particular type of SQL is executed mostly used with ____, ___, ___ can be used with DDL statements such as ____, ___, ___
trigger insert, update, delete cerate, alter, drop
40
trigger syntax
CREATE OR REPLACE TRIGGER triggerName BEFORE/AFTER/INSTEAD OF INSERT/UPDATE/DELETE OF colName ON tableName FOR EACH ROW BEGIN statements END; :NEW.colName to reference new value
41
Dynamic SQL composes a DML or DDL statement at ___ ___ useful when: you need to run a ___ your sql can only be formed at __ __
run time ddl run time
42
dynamic sql
CREATE OR REPLACE PROCEDURE example(employee_id NUMBER) IS sqlStatement VARCHAR2(100); empName VARCHAR(20); BEGIN sqlStatement := 'SELECT first_name FROM EMPLOYEES WHERE emp_ID = :id'; EXECUTE IMEEDIATE sqlStatement INTO empName USING employee_id END;
43
dynamic sql alter table, add constraint syntax
sqlStatement := 'ALTER TABLE ' || tableName || ' ADD CONSTRAINT PK_' || tableName || ' PRIMARY KEY (' || colName || ')'; EXECUTE IMEEDIATE sqlStatement; make sure to add appropriate spaces to the string
44
package syntax
CREATE OR REPLACE PACKAGE pkg AS PROCEDURE procedureName1(params); PROCEDURE procedureName2(params); END pkg; CREATE OR REPLACE PACKAGE BODY pkg AS PROCEDURE procedureName1(params) IS BEGIN statements END procedureName1); PROCEDURE procedureName2(params) IS BEGIN statements END procedureName2); END pkg;
45
how to use a procedure in a package
pkgName.procedureName(params)
46
Integration is the process of ____ data from different __ __ to support business needs
consolidating data sources
47
There are three techniques that form the building blocks of any integration approach: * Data ___ * Data ____ * Data __
Consolidation Federation Propagation
48
data consolidation Usually done for _____ ___ using Extract Transform Load (ETL) techniques ___-___ databases flexibility: ____ requires constant __ ___ to refresh the warehouse
Data Warehousing read only databases not flexible (has a fixed schema) batch processes
49
Data warehousing is the process of constructing and using a data warehouse. A data warehouse is constructed by ___ data from multiple ___ __that support analytical reporting, structured and/or ad hoc queries, and decision making Warehousing is to ___ data in one database that is optimized for __
integrating heterogeneous sources consolidate, reads
50
Data federation is the creation of a ___ database that ___ data from distributed sources giving them a ___ ___ ___. It is an approach to data integration that provides a single source of data for front end applications flexibility: __ ___ on demand provides ___ views to consolidated data only copies or transforms data when need can affect the performance of the transactional ___ databases
virtual, aggregates, common data model flexible consolidation virtual OLTP
51
ETL what is it
Is a process that is used to integrate data or move data from one source to another
51
Data propagation Is the mechanism of copying data within the ___ __. By sharing data among cases, you save time and provide relevant information to caseworkers. Data propagation is not limited to subcases. Data can also be propagated when creating spin- off cases. Data propagation happens on __ __ data is ___ across the database can be ___ (data is consistent) or ___ too many ___
case hierarchy case creation replicated synchronous or asynchronous duplicates
52
ETL extract Process of getting data from the data sources Usually the data will be extracted to a _____ repository (staging database). It is a common practice to first load the extracted data into an intermediate storage area. This intermediate storage is often referred to as a "staging database" or "temporary repository ___ extract is when the whole data is copied
temporary Static Incremental extract is when the deltas(mean new or modified records)- the changes are copied
53
ETL - cleanse extracted data Integrating different sources of data exposes ___ issues in the original data sets Extract process should have processes that expose and reject ___ ___ Extract process must not __ the errors. Instead it will send an error report to the owners of the data source to fix the data at the source
quality erroneous data fix
54
ETL - Transform - record level * ____: Restricting rows using the WHERE clause in the select statement) * ___: Projecting columns from more than one table) * ___: think of it as the opposite of joining. Convert tables that are not in the third normal form to smaller tables that do not have redundancies * ___: converting data from more detailed to summary statistics on the data
Selection Joining Normalization Aggregation
55
ETL - TRANSFORM – FIELD LEVEL ___ ___ change Use functions and algorithms to ___ data from source to destination
data type change change (for example change US dollars to Canadian dollars)
56
ETL - load ___ the transformed data to its final destination (usually data warehouse or a data mart) build ___ if required
Insert
57
Data mart is a subset of __ __ uses ___ ___ centered around ___ ___
data warehouse use dimensional models one subject (sale, inventory)
58
data warehouse ___ Oriented: is focused on business entities ___: Comes from multiple systems and need to fit one structure ____-___: show change over time ____ Only: can not be updated. Has to be reloaded or refreshed
Subject Integrated Time-Variant Read
59
need for data warehouse
when we need to integrate data from multiple systems Separating reporting databases from operational databases (OLTP) enhances the performance NEED FOR DATA WAREHOUSE
60
star schema facts table: has ___ values, contains ___ ___ of dimension tables dimension tables: has ___ and their descriptions all primary keys of the dimension tables should be ___ keys (system generated keys)
quantitative, foreign keys categories surrogate
61
star schema grain of the fact table The minimum unit of reporting should be an ________________ The grain is a crucial concept in data warehousing, influencing how data is ___ and ____ in conjunction with dimension attributes Think of the fact table as an associative entity. This means that its primary key is a composite key that contains all the foreign keys of the entities that associates it which is the dimension tables
intersection of all the dimensions aggregated and analyzed
62
how to create and use a star schema syntax
--create tables CREATE TABLE Fact_Emp( J_ID NUMBER, P_ID NUMBER, D_ID NUMBER, SALARY NUMBER(10,2), Commission_PCT(4,2)): CREATE TABLE Dim_Job( J_ID NUMBER, Job_ID VARCHAR2(30), Job_title VARCHAR2(40)); CREATE TABLE Dim_Period( P_ID NUMBER, P_Year NUMBER); CREATE TABLE Dim_Department( D_ID NUMBER Department_ID NUMBER, Department_name (VARCHAR2(40)); CREATE SEQUENCE Dim_ID; INSERT INTO Dim_Job SELECT Dim_ID.NEXTVAL, Job_ID, Job_title FROM hr.jobs; -- in the select, it is all the fields other than the first ID create table of fact_table using %rowtype, create instance create a cursor than selects all the fields that the fact table has, inner join all tables, group by the dimension ids FROM hr.employees e INNER JOIN Dim_job j ON e.jobID = j.JobID INNER JOIN Dim_department d ON e.departmentID = d.DepartmentID group by J-ID, P_ID, D_ID; open cr, bulk collect into created table, clsoe cr. use forall to insert the data in the created table into the fact table
63