Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / 1-Select+functions.ppt
Скачиваний:
19
Добавлен:
12.05.2015
Размер:
254 Кб
Скачать
☆

Operator Precedence

SQL> SELECT ename, sal, 12*sal+100 2 FROM emp;

ENAME

SAL 12*SAL+100

----------

--------- ----------

KING

5000

60100

BLAKE

2850

34300

CLARK

2450

29500

JONES

2975

35800

MARTIN

1250

15100

ALLEN

1600

19300

...

 

 

14 rows selected.

1-12

Usingi Parentheses

SQL> SELECT ename, sal, 12*(sal+100) 2 FROM emp;

ENAME

SAL

12*(SAL+100)

---------- ---------

-----------

KING

5000

61200

BLAKE

2850

35400

CLARK

2450

30600

JONES

2975

36900

MARTIN

1250

16200

...

 

 

14 rows selected.

1-13

Definingi i a Nullll Valuel

•• A nullll isis a valuel thatt t isis unavailable,il l , unassigned,i , unknown,, orr inapplicablei li le..

•• A nullll isis nott thet same as zeroro orr a blankl space..

 

 

 

 

 

 

 

 

 

 

 

 

 

SQL>

SELECT ename, job, comm

 

 

 

 

 

 

2

FROM

emp;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ENAME

 

JOB

COMM

 

 

 

 

----------

--------- ---------

 

 

 

 

 

 

KING

 

PRESIDENT

 

 

 

 

 

 

 

BLAKE

 

MANAGER

 

 

 

 

 

 

 

...

 

 

 

 

 

 

 

 

 

TURNER

SALESMAN

0

 

 

 

 

 

 

...

 

 

 

 

 

 

14 rows selected.

1-14

Nullll Valuesl inin Arithmetici ic Expressionsi

Arithmetic expressions containing a null value evaluate to null.

 

 

 

 

 

 

SQL>

select

ename NAME, 12*sal+comm

 

 

2

from

emp

 

 

3

WHERE

ename='KING';

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

NAME

12*SAL+COMM

 

 

----------

-----------

 

 

KING

 

 

 

 

 

 

 

 

 

 

1-15

Definingi i a Columnl Aliasli

•• Renames a columnl headingi

•• IsIs usefulf l withith calculationsl l ti

•• ImmediatelyI i t ly followsf llo columnl name;; optionalti l AS keywordrd betweent columnl name and aliasli

•• Requiresir doublele quotationt ti marksr ifif itit containst i spaces orr speciali l charactersr t rs orr isis case sensitiveiti

1-16

Usingi Columnl Aliasesli

SQL> SELECT ename AS name, sal salary 2 FROM emp;

 

 

 

 

 

NAME

SALARY

 

 

-------------

---------

 

 

...

 

 

 

 

 

 

 

 

 

 

SQL> SELECT ename "Name",

2 sal*12 "Annual Salary"

3 FROM emp;

Name Annual Salary

------------- -------------

...

1-17

Concatenationi Operator

•• Concatenatest t columnsl orr characterr t r stringstri toto othert r columnsl

•• IsIs representedr r t by ttwo verticalrti l barsrs (||)(||)

•• Createsr t a resultantr lt t columnl thatt t isis a characterr t r expressionr i

1-18

Usingi the Concatenationi

Operator

 

 

 

 

 

 

SQL>

SELECT

ename||job AS "Employees"

 

 

2

FROM

emp;

 

 

 

 

 

 

 

 

 

 

 

Employees

-------------------

KINGPRESIDENT

BLAKEMANAGER

CLARKMANAGER

JONESMANAGER

MARTINSALESMAN

ALLENSALESMAN

...

14 rows selected.

1-19

Literali l Character Stringsi

•• A literallit r l isis a character,r t r, expression,r i , orr numberr includedi l inin thet SELECT listli t..

•• Datete and characterr t r literallit r l valuesl mustt be enclosedl withinit in singlei le quotationt ti marksr ..

•• Each characterr t r stringtri isis outputt t once forf r each rowro returnedr t r ..

1-20

Usingi Literali l Character Stringsi

SQL> SELECT ename ||''||'is a'||''||job 2 AS "Employee Details"

3 FROM emp;

Employee Details

-------------------------

KING is a PRESIDENT BLAKE is a MANAGER

CLARK is a MANAGER

JONES is a MANAGER

MARTIN is a SALESMAN

...

14 rows selected.

1-21

Соседние файлы в папке 1 - Oracle