Ну, кто ещё не слышал, для тех новость: попробовать APEX 4.0 можно уже сейчас - http://tryapexnow.com/.
Всем приятного тестирования!
Читать далее
Case Study
4 месяца назад
drop table test_merge;
create table test_merge as select 1 m, 2 n from dual;
alter table test_merge add constraint test_merge_chk check (m <= n);
update test_merge set n = m - 1;
rollback;
select * from test_merge;
merge into test_merge tgt
using (select m, m-1 n from test_merge) src
on (tgt.m = src.m)
when matched then update set tgt.n = src.n;
commit;
select * from test_merge;
Таблица создана.
Таблица изменена.
update test_merge set n = m - 1
*
ошибка в строке 1:
ORA-02290: нарушено ограничение целостности CHECK(XXX.TEST_MERGE_CHK)
Откат завершен.
M N
---------- ----------
1 2
1 строка объединена.
Фиксация обновлений завершена.
M N
---------- ----------
1 0
merge into test_merge tgt
using (select m, m-1 n from test_merge) src
on (tgt.m = src.m)
when matched then update set tgt.n = src.n
when not matched then insert (m) values(null) where 1 = 0;
CREATE TABLE tmp(ID NUMBER PRIMARY KEY, d DATE);
declare
d date;
BEGIN
INSERT INTO tmp VALUES(1, to_date('01.12.1900', 'dd.mm.yyyy'));
INSERT INTO tmp VALUES(2, to_date('01.12.-1900', 'dd.mm.syyyy'));
dbms_stats.convert_raw_value(hextoraw('7764057f7f77aa'), d);
INSERT INTO tmp VALUES(3, d);
dbms_stats.convert_raw_value(hextoraw('F7640d01010101'), d);
INSERT INTO tmp VALUES(4, d);
COMMIT;
end;/
Номер байта слева - Компонент
в функции DUMP
1 - столетие + 100
2 - год в столетии + 100
3 - месяц
4 - день
5 - час + 1
6 - минута + 1
7 - секунда + 1
WITH t AS
(SELECT id, DUMP(d) AS dmp
FROM tmp),
comps as
(SELECT id, dmp
, substr(dmp, instr(dmp, ':', 1, 1)+1, instr(dmp, ',', 1, 1) - instr(dmp, ':') - 1) - 100 cc
, substr(dmp, instr(dmp, ',', 1, 1)+1, instr(dmp, ',', 1, 2) - instr(dmp, ',', 1, 1) - 1) - 100 yy
, substr(dmp, instr(dmp, ',', 1, 2)+1, instr(dmp, ',', 1, 3) - instr(dmp, ',', 1, 2) - 1) mm
, substr(dmp, instr(dmp, ',', 1, 3)+1, instr(dmp, ',', 1, 4) - instr(dmp, ',', 1, 3) - 1) dd
, substr(dmp, instr(dmp, ',', 1, 4)+1, instr(dmp, ',', 1, 5) - instr(dmp, ',', 1, 4) - 1) - 1 hh
, substr(dmp, instr(dmp, ',', 1, 5)+1, instr(dmp, ',', 1, 6) - instr(dmp, ',', 1, 5) - 1) - 1 mi
, substr(dmp, instr(dmp, ',', 1, 6)+1) - 1 ss
from t)
select id, dmp from comps
where cc not between -47 and 99
or (yy not between -99 and 99 or (cc = -47 and yy < -12))
or mm not between 1 and 12
or (mm in (1, 3, 5, 7, 8, 10, 12) and dd not between 1 and 31)
or (mm in (4, 6, 9, 11) and dd not between 1 and 30)
or ((mod(cc, 4) = 0 or (mod(cc, 4) <> 0 and mod(yy, 4) = 0)) and mm = 2 and dd not between 1 and 29)
or (mod(cc, 4) <> 0 and mod(yy, 4) <> 0 and mm = 2 and dd not between 1 and 28)
or hh not between 0 and 23
or mi not between 0 and 59
or ss not between 0 and 59;
create or replace function IsDateValid(aDate varchar2, aFormat varchar2) return int
is
d date;
begin
d := to_date(aDate, aFormat);
return 1;
exception
when others then
if sqlcode between -1899 and -1800 then
return 0;
else
raise;
end if;
end IsDateValid;
/
WITH t AS
(SELECT id, DUMP(d) AS dmp
FROM tmp),
comps as
(SELECT id, dmp
, substr(dmp, instr(dmp, ':', 1, 1)+1, instr(dmp, ',', 1, 1) - instr(dmp, ':') - 1) - 100 cc
, substr(dmp, instr(dmp, ',', 1, 1)+1, instr(dmp, ',', 1, 2) - instr(dmp, ',', 1, 1) - 1) - 100 yy
, substr(dmp, instr(dmp, ',', 1, 2)+1, instr(dmp, ',', 1, 3) - instr(dmp, ',', 1, 2) - 1) mm
, substr(dmp, instr(dmp, ',', 1, 3)+1, instr(dmp, ',', 1, 4) - instr(dmp, ',', 1, 3) - 1) dd
, substr(dmp, instr(dmp, ',', 1, 4)+1, instr(dmp, ',', 1, 5) - instr(dmp, ',', 1, 4) - 1) - 1 hh
, substr(dmp, instr(dmp, ',', 1, 5)+1, instr(dmp, ',', 1, 6) - instr(dmp, ',', 1, 5) - 1) - 1 mi
, substr(dmp, instr(dmp, ',', 1, 6)+1) - 1 ss
from t)
select id, dmp
from comps
where IsDateValid( to_char(dd, '900.')||to_char(mm, '900.')||to_char(cc*100+yy, '90000')||to_char(hh, '900')||':'||to_char(mi, '900')||':'||to_char(ss, '900')
, 'DD.MM.SYYYY HH24:MI:SS') = 0;
create or replace function IsDateDumpValid(p_date date)
return integer
is
l_date_str varchar2(32);
l_try_date date;
begin
select to_char(dd, '900.')||to_char(mm, '900.')||to_char(cc*100+yy, '90000')||to_char(hh, '900')||':'||to_char(mi, '900')||':'||to_char(ss, '900')
into l_date_str
from (SELECT substr(dmp, instr(dmp, ':', 1, 1)+1, instr(dmp, ',', 1, 1) - instr(dmp, ':') - 1) - 100 cc
, substr(dmp, instr(dmp, ',', 1, 1)+1, instr(dmp, ',', 1, 2) - instr(dmp, ',', 1, 1) - 1) - 100 yy
, substr(dmp, instr(dmp, ',', 1, 2)+1, instr(dmp, ',', 1, 3) - instr(dmp, ',', 1, 2) - 1) mm
, substr(dmp, instr(dmp, ',', 1, 3)+1, instr(dmp, ',', 1, 4) - instr(dmp, ',', 1, 3) - 1) dd
, substr(dmp, instr(dmp, ',', 1, 4)+1, instr(dmp, ',', 1, 5) - instr(dmp, ',', 1, 4) - 1) - 1 hh
, substr(dmp, instr(dmp, ',', 1, 5)+1, instr(dmp, ',', 1, 6) - instr(dmp, ',', 1, 5) - 1) - 1 mi
, substr(dmp, instr(dmp, ',', 1, 6)+1) - 1 ss
from (select dump(p_date) dmp from dual) t) comps;
begin
l_try_date := to_date(l_date_str, 'DD.MM.SYYYY HH24:MI:SS');
return 1;
exception
when others then
if sqlcode between -1899 and -1800 then
return 0;
else
raise;
end if;
end;
end;
/
select id from tmp where IsDateDumpValid(d) = 0;
select id from tmp
where d <> d + numtodsinterval(trunc(1e8/3),'second') - numtodsinterval(trunc(1e8/3),'second');
/* Сохранить в сессии значение элемента асинхронно */
function saveThisItemAsync(p){
/* создаём пустой вызов к БД - без имени процесса и callback-функции */
var aget = new apex.ajax.ondemand();
/* добавляем нашу переменную-элемент */
aget.ajax.add(p.id, $v(p));
aget._get();
}
/* Сохранить в сессии значение элемента */
function saveThisItem(p){
var get = new apex.ajax.ondemand();
get.ajax.add(p.id, $v(p));
get.ajax.get();
}
apex.ajax = {
...
ondemand : function (pWidget,pReturn){
var that = this;
this.ajax = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS='+pWidget,0);
this._get = _get;
this._set = _set;
this._return = !!pReturn?pReturn:_return;
return;
function _get(pValue){
that.ajax.GetAsync(that._return);
}
function _set(pValue){}
function _return(pValue){}
}
}
<script type='text/javascript' src="http://path/to/jquery" /> <link href='http://path/to/SyntaxHighlighter/styles/shCore.css' rel='stylesheet' type='text/css'/> <link href='http://path/to/SyntaxHighlighter/styles/shThemeRDark.css' rel='stylesheet' type='text/css'/> <script src='http://path/to/SyntaxHighlighter/scripts/shCore.js' type='text/javascript'/> <script src='http://path/to/SyntaxHighlighter/scripts/shBrushBash.js' type='text/javascript'/> <script src='http://path/to/SyntaxHighlighter/scripts/shBrushJScript.js' type='text/javascript'/> <script src='http://path/to/SyntaxHighlighter/scripts/shBrushXml.js' type='text/javascript'/> <script src='http://path/to/SyntaxHighlighter/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://www.google.com/jsapi' type='text/javascript'/>
<script type='text/javascript'> google.load('jquery', '1');</script>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeRDark.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
$(document).ready(
function runSyntaxHighlighter(){
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
SyntaxHighlighter.all();
}
);
<pre class="brush: brushName">ваш код</pre>
<a href="javascript:passBack('');">Это строка с ключом NULL</a>select 'Это строка с ключом NULL' d, null r from dual union all
FUNCTION f_lov_null(p_item_name IN VARCHAR2) Return VARCHAR2 IS
BEGIN
IF v(p_item_name) = 'undefined' THEN
Return(NULL);
ELSE
return(v(p_item_name));
END IF;
END;
nullif(lower(v('YOUR_ITEM_NAME')), 'undefined')Recently I was writing here about Oracle Database, Oracle APEX, Linux. Now I'm more interested in PostgreSQL and AWS, but Oracle will always be in my heart. :) suPPLer