标签云
asm恢复 bbed bootstrap$ dul kcbzib_kcrsds_1 kccpb_sanity_check_2 kcratr_nab_less_than_odr MySQL恢复 obet ORA-00312 ORA-00704 ORA-00742 ORA-01110 ORA-01200 ORA-01555 ORA-01578 ORA-01595 ORA-600 2662 ORA-600 2663 ORA-600 3020 ORA-600 4000 ORA-600 4137 ORA-600 4193 ORA-600 4194 ORA-600 16703 ORA-600 kcbzib_kcrsds_1 ORA-600 KCLCHKBLK_4 ORA-600 kcratr_nab_less_than_odr ORA-15042 ORA-15196 ORACLE 12C oracle dul ORACLE PATCH Oracle Recovery Tools oracle加密恢复 oracle勒索 oracle勒索恢复 oracle异常恢复 ORACLE恢复 Oracle 恢复 ORACLE数据库恢复 oracle碎片 OSD-04016 YOUR FILES ARE ENCRYPTED 比特币加密文章分类
- MongoDB (1)
- MongoDB恢复 (1)
- Others (2)
- 中间件 (2)
- WebLogic (2)
- 操作系统 (112)
- 数据库 (1,882)
- DB2 (22)
- MySQL (82)
- Oracle (1,707)
- Data Guard (53)
- EXADATA (8)
- GoldenGate (24)
- ORA-xxxxx (168)
- ORACLE 12C (72)
- ORACLE 18C (6)
- ORACLE 19C (15)
- ORACLE 21C (3)
- Oracle 23ai (8)
- Oracle ASM (72)
- Oracle Bug (8)
- Oracle RAC (56)
- Oracle 安全 (6)
- Oracle 开发 (28)
- Oracle 监听 (29)
- Oracle备份恢复 (661)
- Oracle安装升级 (108)
- Oracle性能优化 (62)
- 专题索引 (5)
- 勒索恢复 (91)
- PostgreSQL (37)
- pdu工具 (7)
- PostgreSQL恢复 (13)
- SQL Server (34)
- SQL Server恢复 (14)
- TimesTen (7)
- 达梦数据库 (5)
- 达梦恢复 (3)
- 生活娱乐 (2)
- 至理名言 (11)
- 虚拟化 (2)
- VMware (2)
- 软件开发 (51)
- Asp.Net (9)
- JavaScript (12)
- PHP (2)
- 小工具 (34)
- MongoDB (1)
-
最近发表
- 断电引起ORA-600 3005故障处理
- 记录一次云存储资源到期之后引起的数据库恢复
- Firebird 损坏数据库数据抢救工具—firebirdext
- Oracle 19c 202610补丁(RUs+OJVM)-19.33
- 由于con$.con#值达到极限,触发数据库增加约束报ORA-600 12807错误
- MongoDB 离线提取工具—mongoext
- .bres勒索病毒加密数据库dmp文件可恢复
- ORA-600 krsm_mrp_rebuild_lf_list.lno_mismatch
- 记录一次0丢失的ORA-00354: 损坏重做日志块标头故障恢复
- 不当数据库恢复操作导致一个月数据丢失
- obet快速修复oracle 位图损坏块
- 不太常见的10.2.0.1的oracle redo损坏恢复
- obet forcecopy功能抢救硬件故障中的数据文件
- kcratr_nab_less_than_odr和system坏块故障处理
- 通过obet 恢复system坏块,打开数据库
- obet dbv功能完整说明
- 分享一例运行在aix上的sap系统数据库恢复过程
- OBET-Oracle Block Editor Tool使用说明
- 几乎动用了所有手段的Oracle故障恢复
- Oracle Block Edit Tool (obet) 功能增强–2026.07
分类目录归档:Oracle 开发
lob类型数据转换为系统文件
1.插入一条blob数据
SQL> create directory ULTLOBDIR as '/home/oracle';
Directory created.
SQL> create table blobtest(col1 BLOB);
Table created.
SQL> declare
a_blob BLOB;
2 3 bfile_name BFILE := BFILENAME('ULTLOBDIR','tt.txt.bak');
4 begin
5 insert into blobtest values (empty_blob())
6 returning col1 into a_blob;
7 dbms_lob.fileopen(bfile_name);
8 dbms_lob.loadfromfile(a_blob, bfile_name, dbms_lob.getlength(bfile_name));
9 dbms_lob.fileclose(bfile_name);
10 commit;
11 end;
12 /
PL/SQL procedure successfully completed.
SQL> select dbms_lob.getlength(col1) from blobtest;
DBMS_LOB.GETLENGTH(COL1)
------------------------
4829
SQL> !pwd
/home/oracle
SQL> !ls -l tt.txt.bak
-rw-r--r-- 1 oracle oinstall 4829 03-19 17:26 tt.txt.bak
2.创建存储过程
CREATE OR REPLACE PROCEDURE RETRIEVE_LOB_TO_FILE(TEMP_BLOB IN BLOB,
FILE_PATH IN VARCHAR2,
FILE_NAME IN VARCHAR2) IS
DATA_BUFFER RAW(32767);
POSITION INTEGER := 1;
FILEHANDLE UTL_FILE.FILE_TYPE;
ERROR_NUMBER NUMBER;
ERROR_MESSAGE VARCHAR2(100);
BLOB_LENGTH INTEGER;
CHUNK_SIZE BINARY_INTEGER := 32767;
BEGIN
BLOB_LENGTH := DBMS_LOB.GETLENGTH(TEMP_BLOB);
FILEHANDLE := UTL_FILE.FOPEN(FILE_PATH, FILE_NAME, 'wb', 1024);
WHILE POSITION < BLOB_LENGTH LOOP
DBMS_LOB.READ(TEMP_BLOB, CHUNK_SIZE, POSITION, DATA_BUFFER);
UTL_FILE.PUT_RAW(FILEHANDLE, DATA_BUFFER);
POSITION := POSITION + CHUNK_SIZE;
DATA_BUFFER := NULL;
END LOOP;
UTL_FILE.FCLOSE(FILEHANDLE);
EXCEPTION
WHEN OTHERS THEN
BEGIN
ERROR_NUMBER := SQLCODE;
ERROR_MESSAGE := SUBSTR(SQLERRM, 1, 100);
DBMS_OUTPUT.PUT_LINE('Error #: ' || ERROR_NUMBER);
DBMS_OUTPUT.PUT_LINE('Error Message: ' || ERROR_MESSAGE);
UTL_FILE.FCLOSE_ALL;
END;
END;
/
3.测试读取blob到系统
SQL> declare 2 tmp_blob blob default empty_blob(); 3 begin 4 dbms_lob.createtemporary(tmp_blob, true); 5 select col1 into tmp_blob from blobtest; 6 retrieve_lob_to_file (tmp_blob, 'ULTLOBDIR','xifenfei.txt'); 7 end; 8 / PL/SQL procedure successfully completed. SQL> !pwd /home/oracle SQL> !ls -l xifenfei.txt -rw-r--r-- 1 oracle oinstall 4829 03-20 23:44 xifenfei.txt
发表在 Oracle 开发
评论关闭
LNNVL函数使用
LNNVL官方解释
LNNVL provides a concise way to evaluate a condition when one or both operands of the condition may be null. The function can be used only in the WHERE clause of a query. It takes as an argument a condition and returns TRUE if the condition is FALSE or UNKNOWN and FALSE if the condition is TRUE. LNNVL can be used anywhere a scalar expression can appear, even in contexts where the IS [NOT] NULL, AND, or OR conditions are not valid but would otherwise be required to account for potential nulls. Oracle Database sometimes uses the LNNVL function internally in this way to rewrite NOT IN conditions as NOT EXISTS conditions. In such cases, output from EXPLAIN PLAN shows this operation in the plan table output. The condition can evaluate any scalar values but cannot be a compound condition containing AND, OR, or BETWEEN.

LNNVL官方解释翻译
lnnvl用于某个语句的where子句中的条件,如果条件为true就返回false;如果条件为UNKNOWN或者false就返回true。该函数不能用于复合条件如AND, OR, or BETWEEN中。
模拟测试环境
SQL> create table xifenfei(name varchar2(20),year number);
Table created.
SQL> insert into xifenfei values('xifenfei2001',2001);
1 row created.
SQL> insert into xifenfei values('xifenfei2002',2002);
1 row created.
SQL> insert into xifenfei values('xifenfei2003',2003);
1 row created.
SQL> insert into xifenfei values('xifenfei2004',2004);
1 row created.
SQL> insert into xifenfei values('xifenfei2005',2005);
1 row created.
SQL> insert into xifenfei values('xifenfei2006',2006);
1 row created.
SQL> insert into xifenfei values('xifenfei2007',2007);
1 row created.
SQL> insert into xifenfei values('xifenfei2008',null);
1 row created.
SQL> insert into xifenfei values('xifenfei2009',2009);
1 row created.
SQL> insert into xifenfei values('xifenfei2010',2010);
1 row created.
SQL> insert into xifenfei values('xifenfei2011',2011);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from xifenfei;
NAME YEAR
-------------------- ----------
xifenfei2001 2001
xifenfei2002 2002
xifenfei2003 2003
xifenfei2004 2004
xifenfei2005 2005
xifenfei2006 2006
xifenfei2007 2007
xifenfei2008
xifenfei2009 2009
xifenfei2010 2010
xifenfei2011 2011
11 rows selected.
几种情况测试说明
--年份小于2009(lnnvl表示年份大于或者2009包含null) SQL> select * from xifenfei where lnnvl(year<2009); NAME YEAR -------------------- ---------- xifenfei2008 xifenfei2009 2009 xifenfei2010 2010 xifenfei2011 2011 --year不为null(lnnvl表示年份为null) SQL> select * from xifenfei where lnnvl(year is not null); NAME YEAR -------------------- ---------- xifenfei2008 --年份为null(lnnvl表示年份不为null) SQL> select * from xifenfei where lnnvl(year is null); NAME YEAR -------------------- ---------- xifenfei2001 2001 xifenfei2002 2002 xifenfei2003 2003 xifenfei2004 2004 xifenfei2005 2005 xifenfei2006 2006 xifenfei2007 2007 xifenfei2009 2009 xifenfei2010 2010 xifenfei2011 2011 10 rows selected. --年份为12345(lnnvl表示年份不为12345) SQL> select * from xifenfei where lnnvl(year =12345); NAME YEAR -------------------- ---------- xifenfei2001 2001 xifenfei2002 2002 xifenfei2003 2003 xifenfei2004 2004 xifenfei2005 2005 xifenfei2006 2006 xifenfei2007 2007 xifenfei2008 xifenfei2009 2009 xifenfei2010 2010 xifenfei2011 2011 11 rows selected. --年份不为12345(lnnvl表示年份为12345或者null) SQL> select * from xifenfei where lnnvl(year !=12345); NAME YEAR -------------------- ---------- xifenfei2008
发表在 Oracle 开发
评论关闭
创建含sysdate的函数index
1.模拟环境
创建表插入数据库
[oracle@node1 ~]$ sqlplus chf/xifenfei
SQL*Plus: Release 11.2.0.3.0 Production on Mon Jan 9 16:27:19 2012
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> create table t_xifenfei(id number,intime date);
Table created.
SQL> DECLARE
2 i NUMBER;
3 BEGIN
4 FOR i IN 1..1000 LOOP
5 INSERT INTO t_xifenfei VALUES(i,SYSDATE-i);
6 END LOOP;
7 COMMIT;
8 END;
9 /
PL/SQL procedure successfully completed.
SQL> select count(*) from t_xifenfei;
COUNT(*)
----------
1000
SQL> exec dbms_stats.gather_table_stats(USER,'T_XIFENFEI',cascade => TRUE);
PL/SQL procedure successfully completed.
2.无index查询
SQL> set autot trace exp stat
Execution Plan
----------------------------------------------------------
Plan hash value: 548923532
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 120 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T_XIFENFEI | 10 | 120 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(NVL("INTIME",SYSDATE@!)>=TO_DATE(' 2011-12-31 00:00:00',
'syyyy-mm-dd hh24:mi:ss'))
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
7 consistent gets
0 physical reads
0 redo size
770 bytes sent via SQL*Net to client
519 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
9 rows processed
SQL> set autot off
这里只是做了一个简单的查询,因为这个nvl(intime,sysdate)的条件,无法使用正常的index,所以没有建立intime索引的测试。
3.尝试创建index
SQL> create index in_t_xifenfei on t_xifenfei (nvl(intime,sysdate)) online nologging;
create index in_t_xifenfei on t_xifenfei (nvl(intime,sysdate)) online nologging
*
ERROR at line 1:
ORA-01743: only pure functions can be indexed
SQL> !oerr ora 1743
01743, 00000, "only pure functions can be indexed"
// *Cause: The indexed function uses SYSDATE or the user environment.
// *Action: PL/SQL functions must be pure (RNDS, RNPS, WNDS, WNPS). SQL
// expressions must not use SYSDATE, USER, USERENV(), or anything
// else dependent on the session state. NLS-dependent functions
// are OK.
--因为含有sysdate创建函数index失败
SQL> CREATE OR REPLACE FUNCTION f_xifenfei (itime DATE)
2 RETURN DATE
3 IS
4 otime DATE;
5 BEGIN
6 otime:=NVL(itime,SYSDATE);
7 RETURN otime;
8 END;
9 /
Function created.
--想采用自定义函数屏蔽掉sysdate在创建index时候的影响
SQL> create index in_t_xifenfei on t_xifenfei (f_xifenfei(intime)) online nologging;
create index in_t_xifenfei on t_xifenfei (f_xifenfei(intime)) online nologging
*
ERROR at line 1:
ORA-30553: The function is not deterministic
SQL> !oerr ora 30553
30553, 00000, "The function is not deterministic"
// *Cause: The function on which the index is defined is not deterministic
// *Action: If the function is deterministic, mark it DETERMINISTIC. If it
// is not deterministic (it depends on package state, database state,
// current time, or anything other than the function inputs) then
// do not create the index. The values returned by a deterministic
// function should not change even when the function is rewritten or
// recompiled.
--因为函数缺少deterministic不能使用于index上
SQL> CREATE OR REPLACE FUNCTION f_xifenfei (itime DATE)
2 RETURN DATE deterministic
3 IS
4 otime DATE;
5 BEGIN
6 otime:=NVL(itime,SYSDATE);
7 RETURN otime;
8 END;
9 /
Function created.
SQL> create index in_t_xifenfei on t_xifenfei (f_xifenfei(intime)) online nologging;
Index created.
--创建函数index成功
SQL> exec dbms_stats.gather_table_stats(USER,'T_XIFENFEI',cascade => TRUE);
PL/SQL procedure successfully completed.
4.再次查询
确定已经使用函数index,达到在index中使用sysdate函数index的目的。
SQL> set autot on exp stat
SQL> select * from t_xifenfei where f_xifenfei(intime)>=to_date('2011-12-31','yyyy-mm-dd');
Execution Plan
----------------------------------------------------------
Plan hash value: 2005404611
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 200 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_XIFENFEI | 10 | 200 | 3 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IN_T_XIFENFEI | 10 | | 2 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("CHF"."F_XIFENFEI"("INTIME")>=TO_DATE(' 2011-12-31 00:00:00',
'syyyy-mm-dd hh24:mi:ss'))
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
5 consistent gets
0 physical reads
0 redo size
770 bytes sent via SQL*Net to client
519 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
9 rows processed
5.总结说明
5.1)通过函数屏蔽函数index的时候,不能使用sysdate
5.2)在创建函数时,需要指定deterministic关键字

加我微信(17813235971)
加我QQ(107644445)

