Oracle Database 12c: SQL Workshop I: 02 Retrieving Data Using the SQL SELECT Statement

6 篇文章 0 订阅

Retrieving Data Using the SQL SELECT Statement

Basic SELECT Statement

SELECT {*|[DISTINCT] column|expression [alias],...}
FROM table;

NULL values in the SELECT statement

Null is a value that is unavailable, unassigned, unknown, or inapplicable. Null is not the same as zero or a blank space. Zero is a number and blank space is a character.
Columns of any data type can contain nulls. However, some constraints (NOT NULL and PRIMARY KEY) prevent nulls from being used in the column.
If any column value in an arithmetic expression is null, the result is null.

Column aliases

SQL> select riqi from t1;

RIQI
-------------------
2018-08-07 22:21:54
2001-01-01 00:00:00

SQL> select riqi hiredate from t1;

HIREDATE
-------------------
2018-08-07 22:21:54
2001-01-01 00:00:00

SQL> select riqi as hiredate from t1;

HIREDATE
-------------------
2018-08-07 22:21:54
2001-01-01 00:00:00

SQL> select riqi "hiredate" from t1;

hiredate
-------------------
2018-08-07 22:21:54
2001-01-01 00:00:00

SQL> select riqi as "Hire Date" from t1;

Hire Date
-------------------
2018-08-07 22:21:54
2001-01-01 00:00:00

SQL> select riqi "Hire Date" from t1;

Hire Date
-------------------
2018-08-07 22:21:54
2001-01-01 00:00:00

Use of concatenation operator, alternative quote operator

SQL> select t2name||id quantity from t2;

QUANTITY
--------------------------------------------------------------------------------
coat1

SQL> select t2name||' amt is '||id from t2;

T2NAME||'AMTIS'||ID
--------------------------------------------------------------------------------
coat amt is 1

SQL> select t2name||'s amount is||id from t2;
ERROR:
ORA-01756: quoted string not properly terminated

SQL> select t2name||q'< 's amt is >'||id from t2;

T2NAME||Q'<'SAMTIS>'||ID
--------------------------------------------------------------------------------
coat 's amt is 1

SQL> select t2name||q'[ 's amt is ]'||id from t2;

T2NAME||Q'['SAMTIS]'||ID
--------------------------------------------------------------------------------
coat 's amt is 1

SQL> select t2name||q'{ 's amt is }'||id from t2;

T2NAME||Q'{'SAMTIS}'||ID
--------------------------------------------------------------------------------
coat 's amt is 1

SQL> select t2name||q'( 's amt is )'||id from t2;

T2NAME||Q'('SAMTIS)'||ID
--------------------------------------------------------------------------------
coat 's amt is 1

SQL> select t2name||q'< 's >'||amt is ||id from t2;
select t2name||q'< 's >'||amt is ||id from t2
                              *
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

SQL> select t2name||q'< 's >'||'amt is '||id from t2;

T2NAME||Q'<'S>'||'AMTIS'||ID
--------------------------------------------------------------------------------
coat 's amt is 1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值