- 給表增加字段時,要注意相關視圖,如果視圖的創建如
create or replace view house as
select b.*, .......
b.*這樣,就要重新運行下視圖,否則會++報指定的列名數無效++這樣的錯誤。
- oracle通過in查詢的數據為亂序,如果要順序,可以使用decode
select * from table_name t
where t.id in
(
'235',
'dsafas',
'fsafsa',
'gdghdh',
'her',
'fw',
'fsafa'
)
order by decode
(
t.id,
'235',1,
'dsafas',2,
'fsafsa',3,
'gdghdh',4,
'her',5,
'fw',6,
'fsafa',7
);
也可以用instr
select * from lessee where id = '123' or id = '124' order by instr('123,124', id);
- 使用REGEXP_SUBSTR函數進行字符串分割
SELECT REGEXP_SUBSTR ('hello my phone is 520 ', '[0-9]+') FROM dual; --520
http://blog.csdn.net/zz87250976/article/details/22856829
http://blog.csdn.net/itmyhome1990/article/details/50380749
- instr函數返回字符串str中子字符串substr第一次出現的位置,在sql中第一字符的位置Z是1,如果 str不含substr返回0。
我想查找承租人簽訂了哪些合同,因為合同表中承租人id是分號拼接的,用全模糊效率太低,用instr如果返回大于0,則說明那份合同有這個承租人。
select * b where a.name='group1' and instr(a.id,b.id)>0;
- 獲取date數據的月份差months_between
starttime := to_char(startdate, 'yyyy-mm');
endtime := to_char(enddate, 'yyyy-mm');
select months_between(to_date(endtime, 'yyyy-mm'), to_date(starttime, 'yyyy-mm')) into accountmonth from dual;
-
ORA-01795: 列表中的最大表達式數為 1000
in ()的數量不能超過1000,最好inselect語句。
oracle存儲過程中update不成功的一個原因。存儲中,變量名不能和表字段名一樣。我遇到在update時變量名和字段名稱一樣,結果那個字段update失敗,但其他字段更新成功。
ORA-12899 通過dblink進行數據插入時(同樣的表),出現這個錯誤
12899::ORA-12899: 列 "IMPORTUSER"."BA_RESIDENTHMTSZ"."REGISTRAR" 的值太大 (實際值: 51, 最大值: 50)
ORA-02063: 緊接著 line (起自 BAWGB28)
后來一調查,發現是跟oracle的字符集編碼有關:如果是以下字符集,一個漢字占用2個字節: SIMPLIFIED CHINESE_CHINA.ZHS16GBK 如果是以下字符集,一個漢字占用3個字節: SIMPLIFIED CHINESE_CHINA.AL32UTF8
(1)查看oracle字符集可以用下面的sql文查看: select userenv('language') from dual
(2)查看當前oracle環境中一個漢字占多少個字節可以用下面的sql文查看: select lengthb('啊') from dual。
刪除上千萬數據的時候,不能直接delete,可以進行遍歷,沒刪除1000個數據進行commit操作。