sql Flashcards

(25 cards)

1
Q

SQL statement categories

A
Data definition language
data control language
data manipulation
transaction control
Session control
system control
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

SQL*Plus

A

environment

oracle proprietary

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

Describe

A

DESC table_name

DESC table_name

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

data types

A
varchar2(size)
char(size)
number(p,s)
date
long
clob
raw / long raw
....
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

select * from table_name;

A

select : what column

from which table

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

sql statements

A

not case sensitive
one or more lines
keywords cannot be abbreviated or split across lines/

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

select + arithmetic operators

A

select sal, sal*2 from emp;

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

column alisas

A

select ename as surname, sal from emp;

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

dual table

A

single column and single row

do calculation -> see result

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

concatenate

A

select first_name || ‘ ‘ || last_name AS “Customer Name” from customers;

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

literal Character Strings

A

literal: char, expression, number in select list
date, char in single quote
select dept || ‘is the number’

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

null value

A

unknown value
not blank string
special value
important to handle null value

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

check null value

A

select * from table where dob IS NULL/ IS NOT NULL;

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

distinguish blank string and null

A

SELECT ename, NVL(com, ‘No commission’) “Commission”

FROM emp;

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

eliminate duplicate rows

A

select DISTINCT job FROM emp;

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

where

A

select ename, job, hiredate from emp

where ename = ‘Smith’;

17
Q

not equal

equal

18
Q

other comparison operators

A

between
in
like
is null

19
Q

between

A

select name, price from table where price between 10 and 15;

20
Q

in

A

select ename, mgr from emp

where mgr in (7566, 7788)

21
Q

like

A

select * from table where first_name like ‘C%’;

note: % -> zero or more
_ one char
use escape char like _

22
Q

not

A

select ename, job from emp

where job NOT IN (‘salemane’, ‘clerk’)

23
Q

soritng

A

ASC / DESC
select enam, job, sal from emp
order by sal;
select enam, job, sal from emp order by sal desc;

24
Q

sorting by column alias

A

select ename, sal*12 “Annual Salary” from emp

order by “annual salary”;

25
sorting multi col
select ename, job, sal from emp order by job, sal DESC;