FireBird'de ISNULL ile ilgili
Kuri_YJ24.09.2003 - 15:53:20
Merhaba Arkadaşlar aslında bu bilgiyi sizlerle paylaşmak istedim. Delphi Listesinde bir ara bir mail atmıştım, FireBird'de, MSSQL'deki ISNULL'a benzer veya karşılık bir fonksiyon var mı diye, ancak yanıt alamamıştım ve oturup kendim bir ISNULL UDF'i hazırlamıştım. ISNULL ile birlikte birkaç küçük fonksiyon daha hazırlamıştım. Ancak bugün FireBird'ün Release Notlarına göz atarken ISNULL'ın benzeri bir UDF olduğunu gördüm.

Ekte bulduğum yazının örneği var, FireBird v1.0 Release Notes'tan alıntı,


In the new Firebird UDF library, FBUDF.dll

Development by Claudio Valderrama C., funded by Craig L. Leonardi
Distributed with this release is FBUDF.dll, the first Firebird UDF library using BY DESCRIPTOR syntax to
pass arguments, which provides more versatility. In declaring the functions in SQL, notice the
differences between the multiple declarations that map to the same function.

See, for example, that
INULLIF() is mapped to by both INULLIF() and I64NULLIF().
Author Claudio Valderrama comments that the library is still in beta and warns that it will probably
exhibit some bugs. So far it has not been compiled on any other platform but Windows. Bug reports
and comments are welcome.

The source and the DDL for declarations are in the Firebird CVS tree. To find them, select 'Browse the
CVS tree' from http://sourceforge.net/projects/firebird, click on 'Browse CVS Repository' and then
select Developers | Latest sources | interbase | extlib | fbudf.*.
NVL() functions for both exact precision ('invl') and string ('snvl') parameters

These functions attempt to mimic the NVL function of Oracle, to output an actual value when
the column has a NULL value. They take two arguments, the first being the expression being
tested for NULL, the second the value to output if the first argument is NULL. NVL will return
the first argument if it's not null and the second argument if the first one is null. If both are
null, you get null.

The pair of parameters should be compatible, either two numeric values (smallint, int, int64)
or two string values (char, varchar, cstring). The engine does not honor the parameter types
when using the technique exercised by FBUDF, so mixing a numeric and a string as arguments
will yield wrong results.

NULLIF() for string ('snullif'), integer ('inullif') and INT64 ('i64nullif') parameters
NULLIF should take two arguments, returning NULL if they are equivalent, or the result of the
first expression if they are not equivalent. Because of a shortcoming in the engine which
prevents NULL being returned from a UDF, each of these three functions returns a zeroequivalent.

This non-standard behaviour makes it not useful for "casting" certain values as
NULL in order to have aggregate functions ignore nulls.
NOTE that the function call to both the integer and int64 functions is the same ('inullif').

Day-of-Week functions - one returning a short string ('SDOW'), the other a longer one ('DOW'), from a
timestamp input. The return strings can be localized.
Several functions to add segments of time to a timestamp - 'addDay', 'AddWeek', etc.

A RIGHT() function (like RString in BASIC) to return the rightmost n characters from an input string.
A GetExactTimestamp() function returning the system timestamp with milliseconds precision.

Truncate()and i64truncate() truncate 32-bit and 64-bit integers respectively, taking scaled (exactprecision)
numerics of any range (up to 9 in Dialect 1 or up to 19 in Dialect 3) and returning the wholenumber
portion. They do not work with float or double types.


Herkese kolay gelsin, bu fonksiyona ihtiyaç duyanlara da bir çeşit müjde :)
 
mussimsek24.09.2003 - 16:29:53
bilgi için teşekkürler.

Kolay gelsin.
 
safak14.10.2003 - 16:04:39
WHERE field IS NULL
olarak çalışıyor.
 
Kuri_YJ15.10.2003 - 14:16:58
Merhabalar,

safak arkadaşımıza yardım etmeye çalıştığı için teşekkür ederiz. Ancak bizim kasdettiğimiz ISNULL function'ı farklı bir amaç için kullanılmakta. Yani sadece where clause'unda kullanılmak üzere yapılmış bir function değil !...

Şöyle açıklayayım,

Bir table'da Null fieldlar olabilsin ve bu null fieldlar için matematiksel işlemler gerçekleştirelim.

Table

F1 F2 F3 F4
50 10 Null Null

İşlemimiz de şu şekilde olsun.

F4 := (F1 + F2) - F3 ;

Eğer yukarıdaki işleme Null değeri karışırsa ortaya çıkan sonuç Null olacaktır. Ancak biz F3 fieldı Null olursa 0 (Sıfır) kabul et diyerek formülü uygulamak istiyorsak, burada bir funtion'a ihtiyaç duyuluyor yada bir If Then Else bloğuna ihtiyaç duyuluyor.

F4 := (F1 + F2) - INULLIF(F3,0) ;

şeklinde yazarsak F4'ün sonucu 60 olur. Bizim kasdettiğimiz ISNULL kontrolu bu şekilde. Bilmem açıklayabildim mi!...

Ancak şunu da belirteyim ki yukarıdaki function'lar hernedense düzgün çalışmadı. Ben denemelerini yaptım ama sonuçta yine Null döndü. Zaten yazan kişinin notlarında BUG olabilir diyordu :) Demek ki bir şekilde benim elimdeki versiyonda bu BUG var. Daha derin inceleyip (yada takip edip yeni versiyonlarını bulmak gerekiyor).

Ancak isteyen olursa bizim yazdıklarımızı gönderebilirim.

Kolay gelsin.
 
rsimsek15.10.2003 - 17:04:38
sırası gelmişken bir ek de ben yapayım;

oracle da güzel bir fonksiyon var: DECODE()

decode(değişken, 1.değer, 1.dönecek_değer, 2.değer, 2.dönecek_değer, 3.değer, 3.dönecek_değer, ..., else_durumunda_dönecek_değer)

burada değişken, n.değer e eşitse n.dönecek_değer i alacak aksi halde else durumundaki değeri döndürür.

yani burada verdiğiniz fonksiyonlar biçiminde kullanmak da mümkün.

decode(alan, null, 0);

belki udf olarak da vardır.
 
safak15.10.2003 - 17:30:38
NULL için database değerlendirme tutumu SQL2 standartlarında açıkca belirtilmiş. Tabii sürümlere göre farklılık gösterebilir. Davranışlar NULL değerini gözardı etmek ya da içinde NULL barındıran işlemleri NULL olarak ifade etmek arasında salınıyor. Aslında NULL 'un ele alınışı biraz da tasarımcının sorumluluğunda. Tanımlanan tasarım ortamında NULL (Henüz değer atanmamış) ifadesi gerçekten 0 (sıfır) anlamına geliyorsa, bu durumda ilgili alanlara default olarak 0 atamak ya da 0 da olsa bir değer girmeye zorlamak, daha sonra ortaya çıkabilecek pek çok değerlendirme sorununu daha baştan çözebilir. Eğer tasarım kriterleri sonucunda kaçınılmaz olarak NULL atamak ve buna zaman zaman 0, zaman zaman atanmamış değerlendirmesi yapılmak istenirse, alternativ bir kolay hesaplama yolu olarak, sonuç kümesi üzerinde WHERE ile pass uygulanarak , problemin tanımına göre NULL alanlara hesaplama için gerekli değerler atanması ve sonra istenen sorgulamaların uygulanması yolu da göz önünde bulundurulabilir.

Tabii tasarımın yapısına göre Numerik alanlar dışında NULL atanmış alanların nasıl değerlendirilmesi gerketiği de ayrı bir yaklaşım gerektirebilir.

NULL 'u "henüz tanımlanmamıs" tanımına bağlı kalarak kullanmak bir çok sorunu baştan çözebiliyor. Alanlarda görülen NULL değerleri sadece "henüz değer atanmamış" anlamına gelmeli. Eğer mümküse nümerik alanlar için sıfır, karaker alanlar için bir boşluk (varsa diğer tipler için anlamlı bir değer) atamak kararsız yapıların oluşumunu engelliyor.
 
NOT : Bu sayfa google'un siteyi indekslemesi içindir. www.delphiturkiye.com/forum/ adresini kullanınız!
1998-2006 www.delphiturkiye.com