檢視資料所佔空間的兩個函式:
-- 檢視所佔位元組數large object,用來儲存大資料。select length('你好,世界') from dual;
-- 檢視所佔字元數,即多少個字母,多少個漢字
select lengthb('您好,美女') from dual;
-- 比如
create table aaa (a varchar2(6));
insert into aaa values ('aaa');
insert into aaa values ('你好');
select a, length(a), lengthb(a) from aaa;
rowid
rowid 是 oracle 中的偽列。可以通過下面語句顯示:
select d.rowid, d.* from dept d它是唯一的,不可變的,固定長度的。
它是資料儲存實體地址的一種對映。一共有18位,前6位表示物件id,後3位表示fno,後6位表示塊編號,最後3位表示行編號。 所以,通過rowid可以最快速度地定位到資料所在的位置。
aaao0f
aafaaaalm
aaa物件號(6個字元)
檔案號(3個字元)
塊號(6個字元)
行號(3個字元)
rowid 是 oracle 特有的。
不建議使用 rowid 作為表的主鍵。遷移的需求,有改變的風險。
rownum
列出每一行資料的行數,從1開始,自然增長。
-- 基本用法它是 oracle 中非常特殊的一種型別。它表示不確定,表示沒有值。並且它能轉化成所有的型別。 向資料庫中插入空字串時,oracle 會把它自動轉化為 null 型別。所以,在查詢空字元的時候:select rownum, d.* from dept;
select rownum, d.* from dept d where rownum < 3; -- 顯示前兩條
select * from (select rownum rn, d.* from dept d) t where t.rn = 3; -- 只顯示第三條
select * from (select * from emp order by sal desc) where rownum<=3; -- 顯示 emp 表中工資前三位的雇員資訊。
select * from n3 where s = '';上面的語句是非法,不合適的。應該這樣查:
select * from n3 where s is null;建立表的時候,為了約束插入的資料不能為空,應該在字段的後面寫上 not null 約束。select * from n3 where s is not null;
create table n5 (s varchar2(20) not null);跟 null 做任何的運算,結果仍然是 null.
select null + '' from dual; -- null
SQL語句 資料定義
1.模式的定義與刪除 定義乙個模式 create schema 模式名 authorization 使用者名稱 為使用者haha定義乙個模式a create schema a authorization haha 刪除乙個模式 drop schema 模式名 cascade restrict cas...
SQL語句 資料操作
表中資料的變化牽一髮而動全身,會同時導致到索引中資料的變化。因此如果查詢語句不需要索引,就應該刪除無用的索引以提高效率。1 基本插入語句 insert用於向表中輸入資料,其具體的語法結構如下 insert into 表名稱 values 值1,值2,我們也可以指定所要插入資料的列 insert in...
SQL語句 資料操作
表中資料的變化牽一髮而動全身,會同時導致到索引中資料的變化。因此如果查詢語句不需要索引,就應該刪除無用的索引以提高效率。1 基本插入語句 insert用於向表中輸入資料,其具體的語法結構如下 insert into 表名稱 values 值1,值2,我們也可以指定所要插入資料的列 insert in...