General functions are very useful while working with SQL and PL/SQL. These functions are used for working with null values and can handle any data type. We have 4 functions available in SQL which comes under general functions.
They are,
--> NVL Function
--> NVL2 function
--> NULLIF function
--> COALESCE function
Basically all these functions are used for avoiding wrong results in SQL statements which involves null
values. For example let us say we have two columns in Employee table named Sal and Bonus. Sal column will have values of employee salary and Bonus column will have values of bonus. If we want to find out total sal of employee we need to sum the values from these two columns.
Let us say we have following values stored in employee table.
Emp1 2000 null
Emp2 1500 200
Emp3 3500 null
Now if we write following query on this table result will be as shown.
SELECT ename,sal+bonus from emp;
Result :: ename sal+bonus
Emp1 null
Emp2 1700
Emp3 null
We can see from the result that total sals for employees Emp1 and Emp3 is coming as null. This is because
we have null values stored for these employees in bonus column and in SQL null means nothing. If we add
some value to null then result will be null only. To get correct results in such type of situations we will use
general functions. Let us discuss these functions now.
NVL Function ::
===========
If any column contains null values then arithmetic expressions involving those columns will give inappropriate results as shown in previous example. To avoid this we need to handle those null values. NVL function can be used to handle null values present in the column while using them in SELECT statements.
SYNTAX :: Syntax for NVL function is,
NVL ( column or expression , default value)
Here column or expression will be the one which we are expecting to contain null values and which we want to handle using NVL function.
default value is corresponding to the value which we want to use in case null value is present in that particular column. We have to provide correct default values depending on requirement to get proper results.
In our previous example to get correct total salary we can use 0 as default value. Then query can be written as following.
SELECT ename, sal+nvl(bonus,0) from emp;
No this will give result as,
Emp1 2000
Emp2 1700
Emp3 3500
Like this we can avoid wrong results in SQL statements involving null values.
NVL2 Function ::
============
This function is bit different from NVL function and will be used rarely in SQL. This functions contains 3 arguments and the result will always be decided on first value.
SYNTAX :: Syntax for this function is,
NVL2(col1 or exp1, col2 or exp2 or val1, col3 or exp3 or val3)
Here first argument corresponds to column or expression based on which we want to decide the result and 2nd argument and 3rd argument will give us the results based on first argument.
How this NVL2 function works is if the value of first argument is not null then this function will give second argument value as result. If value of first argument is null then this function will give third argument as result.
For example if we write query on data present in previous example as below,
SELECT ename, NVL2(bonus,sal,5000) from Emp;
Then result will be as shown below.
Emp1 5000
Emp2 1500
Emp3 5000
For Emp1 and Emp3 bonus is null so 5000 will come as result . For Emp2 bonus is not null so sal value which is 1500 will come as result.
This is how NVL2 Function will work.
NULLIF Function ::
==============
This function is also different from other general functions in the way how it works. Basically this function will be having two arguments as inputs and it will produce the results based on those two arguments.
SYNTAX:: Syntax for this function is,
NULLIF (col1 or exp1, col2 or exp2)
Here both the arguments are responsible for the result. This function will compare the values of the two arguments and returns null if both are equal and returns first argument value if both are not equal.
For example if we write query as,
SELECT NULLIF(col1,col2) from tab;
if values of col1 and col2 are 20 and 30 then result will be 20
if values of columns is 10 and 10 then result will be null.
So, this is how NULLIF function will work.
COALESCE Function ::
=================
This function will work same as the NVL function. But only difference is that it will be having multiple arguments ( more than 2 unlike NVL). It will return first not null value from input argument list .
SYNTAX :: Syntax for this function is,
COALESCE(arg1, arg2, arg3, arg4,...)
Here we can pass any number of columns or expressions as arguments to this function. This will give us the first not null value from left of the argument list as result.
For example,
If values of arguments is like null,null,3,4.. then result will come as 3
If values are like 1,null,null,.... result will be like 1.
So, this works similar to NVL function only but the only difference is that it will have multiple inputs.
So, these are the different General Functions which are available in SQL. Among all these functions NVL is the most used function in SQL queries.
They are,
--> NVL Function
--> NVL2 function
--> NULLIF function
--> COALESCE function
Basically all these functions are used for avoiding wrong results in SQL statements which involves null
values. For example let us say we have two columns in Employee table named Sal and Bonus. Sal column will have values of employee salary and Bonus column will have values of bonus. If we want to find out total sal of employee we need to sum the values from these two columns.
Let us say we have following values stored in employee table.
Emp1 2000 null
Emp2 1500 200
Emp3 3500 null
Now if we write following query on this table result will be as shown.
SELECT ename,sal+bonus from emp;
Result :: ename sal+bonus
Emp1 null
Emp2 1700
Emp3 null
We can see from the result that total sals for employees Emp1 and Emp3 is coming as null. This is because
we have null values stored for these employees in bonus column and in SQL null means nothing. If we add
some value to null then result will be null only. To get correct results in such type of situations we will use
general functions. Let us discuss these functions now.
NVL Function ::
===========
If any column contains null values then arithmetic expressions involving those columns will give inappropriate results as shown in previous example. To avoid this we need to handle those null values. NVL function can be used to handle null values present in the column while using them in SELECT statements.
SYNTAX :: Syntax for NVL function is,
NVL ( column or expression , default value)
Here column or expression will be the one which we are expecting to contain null values and which we want to handle using NVL function.
default value is corresponding to the value which we want to use in case null value is present in that particular column. We have to provide correct default values depending on requirement to get proper results.
In our previous example to get correct total salary we can use 0 as default value. Then query can be written as following.
SELECT ename, sal+nvl(bonus,0) from emp;
No this will give result as,
Emp1 2000
Emp2 1700
Emp3 3500
Like this we can avoid wrong results in SQL statements involving null values.
NVL2 Function ::
============
This function is bit different from NVL function and will be used rarely in SQL. This functions contains 3 arguments and the result will always be decided on first value.
SYNTAX :: Syntax for this function is,
NVL2(col1 or exp1, col2 or exp2 or val1, col3 or exp3 or val3)
Here first argument corresponds to column or expression based on which we want to decide the result and 2nd argument and 3rd argument will give us the results based on first argument.
How this NVL2 function works is if the value of first argument is not null then this function will give second argument value as result. If value of first argument is null then this function will give third argument as result.
For example if we write query on data present in previous example as below,
SELECT ename, NVL2(bonus,sal,5000) from Emp;
Then result will be as shown below.
Emp1 5000
Emp2 1500
Emp3 5000
For Emp1 and Emp3 bonus is null so 5000 will come as result . For Emp2 bonus is not null so sal value which is 1500 will come as result.
This is how NVL2 Function will work.
NULLIF Function ::
==============
This function is also different from other general functions in the way how it works. Basically this function will be having two arguments as inputs and it will produce the results based on those two arguments.
SYNTAX:: Syntax for this function is,
NULLIF (col1 or exp1, col2 or exp2)
Here both the arguments are responsible for the result. This function will compare the values of the two arguments and returns null if both are equal and returns first argument value if both are not equal.
For example if we write query as,
SELECT NULLIF(col1,col2) from tab;
if values of col1 and col2 are 20 and 30 then result will be 20
if values of columns is 10 and 10 then result will be null.
So, this is how NULLIF function will work.
COALESCE Function ::
=================
This function will work same as the NVL function. But only difference is that it will be having multiple arguments ( more than 2 unlike NVL). It will return first not null value from input argument list .
SYNTAX :: Syntax for this function is,
COALESCE(arg1, arg2, arg3, arg4,...)
Here we can pass any number of columns or expressions as arguments to this function. This will give us the first not null value from left of the argument list as result.
For example,
If values of arguments is like null,null,3,4.. then result will come as 3
If values are like 1,null,null,.... result will be like 1.
So, this works similar to NVL function only but the only difference is that it will have multiple inputs.
So, these are the different General Functions which are available in SQL. Among all these functions NVL is the most used function in SQL queries.
Hi, Nice description about SQL Functions.Thanks, its really helped me......
ReplyDelete-Aparna
Theosoft
Hi,
ReplyDeleteIt's good.Easy to understand.
Oracle Training in Chennai
Oracle Training in Chennai
I'm so happy to find the good inofrmation On PL/SQL thanks for your effort .friends learn Oracle PLSQL e-learningOracle PLSQL e-learning By 8 years experienced trainer
ReplyDeleteIt's a nice blog with lot of information,thanks for sharing...
ReplyDeleteHi this is babu, I want to share some information for you,If you want to join any professional course visit this website
oracle training in chennai It's a best place to learn oracle in chennai
thanks, babu
It's a nice blog with lot of information,thanks for sharing...
ReplyDeleteHi this is babu, I want to share some information for you,If you want to join any professional course visit this website
oracle training in Chennai It's a best place
to learn oracle in chennai
thanks, babu
Your blog is really useful for me. Thanks for sharing this informative blog. If anyone wants to get real time Oracle Training Chennai reach FITA Oracle Training Center in Chennai. They give professional and job oriented training for all students.
ReplyDeleteThe information you posted here is useful to make my career better keep updates..I did Salesforce Training in Chennai at FITA academy. Its really useful for me to make bright future in IT industry.
ReplyDeleteSalesforce Developer Training in Chennai | Salesforce Admininistrator Training in Chennai
SAP Training
ReplyDeleteThanks for sharing this valuable information.and I gathered some information from this blog. I did SAP Course in Chennai, at FITA Academy which offer best SAP Training in Chennai with years of experienced professionals.
SAP Training Institute in Chennai
Its really awesome blog..If anyone wants to get Software Testing Training in Chennai visit FITA IT academy located at Chennai. Rated as No.1 Software Testing Training Institutes in Chennai
ReplyDeleteRegards.....
Testing Training in Chennai | QTP Training in Chennai
Nice effort and information..!!!
ReplyDeleteYou can find PL/SQL advance concepts with example from
http://www.oracle-tf-world.in/p/oracle-plsql_20.html
Your comments are most welcome...!!!
Hi , very good article, thanks for providing in-depth information on Oracle SQL PL/SQL Technology. Please continue sharing.
ReplyDeleteCloud is one of the tremendous technology that any company in this world would rely on(cloud computing training). Using this technology many tough tasks can be accomplished easily in no time. Your content are also explaining the same(Cloud computing training institutes in chennai). Thanks for sharing this in here. You are running a great blog, keep up this good work.
ReplyDeleteThere are lots of information about latest technology and how to get trained in them, like Big Data Course in Chennai have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get trained in future technologies(Big Data Training Chennai). By the way you are running a great blog. Thanks for sharing this.
ReplyDeleteBig Data Training in Chennai | Big Data Training
This is amazing step by step guide!
ReplyDeletehttp://www.tekclasses.com/
Great stuff!
ReplyDeletehttp://www.tekclasses.com/
Excellent Work, Clear Step By Step Guide and very depth information on plsql Thank You Ramu Kandimalla http://www.vaysinfotech.com/job/oracle-application-database-administrator/
ReplyDeleteExcellent Post thanks for sharing PL/SQL Online Training
ReplyDeleteThere is a great blog about plsql and thanks for sharing about plsql this information is used for to now the plsql server and sevices plsqlonlinetraining
ReplyDeleteThis blog is very informative.Thanks for sharing.Its helpful.You can also view this video for Sql beginners
ReplyDeleteGood Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
ReplyDeleteRegards,
Oracle apps Training in Chennai|Oracle DBA Training in Chennai
Valuable information thanks for sharing Oracle PL/SQl Online Training
ReplyDeleteExcellent post!!! In this competitive market, customer relationship management plays a significant role in determining a business success. That too, cloud based CRM product offer more flexibility to business owners to main strong relationship with the consumers. Amazon Web Services Training in Chennai | AWS Training
ReplyDeletelenovo laptop service center chennai
ReplyDeletelenovo thinkpad service center chennai
lenovo ideapad service center chennai
lenovo laptop service center in vadapalani
Excellent post!!!
ReplyDeletewebsphere training in chennai
nice.
ReplyDeletecore-java training in chennai
Excellent Post thanks for sharing ...
ReplyDeletesas training in chennai
Good Post! Thank you so much for sharing this post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
ReplyDeleteoracle training in chennai
Thank for sharing this useful information;
ReplyDeleteIt is very useful to me and who are wanted to learn or update their knowledge on Oracle PL/SQL through Oracle PL/SQL online training or offline training.
You have shared useful information about plsql function. Thanks for sharing your valuable knowledge with us.
ReplyDeleteOracle dba training | Oracle dba training syllabus
I've been following your posts for a while. You are doing a great work.
ReplyDeleteSpark Training in Chennai | Spark Training | Spark Training Academy | Spark Training Academy Chennai | Apache Spark Training | Spark Course in Chennai | Spark Training institute in Chennai
Awesome blog. I would thank the blog admin for sharing this info with us.
ReplyDeleteTOEFL Classes in Porur
TOEFL Coaching in Porur
TOEFL Classes in Adyar
TOEFL Class in Thiruvanmiyur
TOEFL Coaching in Anna Nagar
TOEFL Classes in Anna Nagar
TOEFL Coaching in T-Nagar
TOEFL Training in T-Nagar
This is really too useful and have more ideas and keep sharing many techniques. Eagerly waiting for your new blog keep doing more.
ReplyDeleteCCNA Course in Chennai
CCNA Training in Chennai
Cloud Computing Courses in Chennai
AWS Training in Chennai
Data Science Course in Chennai
CCNA Training in Porur
CCNA Training in Adyar
Oh, that's Great Post Thanks for sharing with us. This Big data hadoop training in Bangalore Platform helped me to learn advanced concepts of all the trending technologies out there in the current IT market. really worth trying them.
ReplyDeleteCloud computing is the best technology that every top company in this world are using for their computing purpose. This article provides the information that is more relevant to it. Thanks for sharing this valuable information in here. By the way you are running a great blog here. Keep up this good work.
ReplyDeleteshare more details.
Ai & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
nice post.
ReplyDeleteAndroid training
Ansible training
Appium training
AWS training
Azure DevOps training
Azure training
Chef training
mmorpg oyunlar
ReplyDeleteinstagram takipçi satın al
Tiktok Jeton Hilesi
tiktok jeton hilesi
antalya saç ekimi
referans kimliği nedir
instagram takipçi satın al
metin2 pvp serverlar
instagram takipçi satın al
lisans satın al
ReplyDeleteen son çıkan perde modelleri
minecraft premium
uc satın al
yurtdışı kargo
en son çıkan perde modelleri
nft nasıl alınır
özel ambulans
Success Write content success. Thanks.
ReplyDeletekıbrıs bahis siteleri
canlı slot siteleri
betturkey
betpark
kralbet
betmatik
deneme bonusu
Good content. You write beautiful things.
ReplyDeletehacklink
taksi
korsan taksi
sportsbet
vbet
vbet
hacklink
mrbahis
mrbahis
thanks for sharing this is very helpful
ReplyDeletebetmatik
kralbet
betpark
tipobet
slot siteleri
kibris bahis siteleri
poker siteleri
bonus veren siteler
mobil ödeme bahis
YF4BZY
elf bar
ReplyDeletebinance hesap açma
sms onay
SPDJ
kuşadası
ReplyDeletelara
sivas
çekmeköy
fethiye
WE4W7K
Muğla
ReplyDeleteSamsun
Eskişehir
Sakarya
Kars
ROUJ
Kocaeli
ReplyDeleteDenizli
Bartın
Kocaeli
Adana
74U
yalova
ReplyDeleteyozgat
elazığ
van
sakarya
4UN7VN
57AEA
ReplyDeleteEskişehir Lojistik
Yalova Evden Eve Nakliyat
Afyon Lojistik
Yalova Lojistik
Ağrı Evden Eve Nakliyat
4835E
ReplyDeleteKars Evden Eve Nakliyat
Ankara Asansör Tamiri
Ankara Evden Eve Nakliyat
Aksaray Evden Eve Nakliyat
Bursa Evden Eve Nakliyat
112C4
ReplyDeleteSilivri Fayans Ustası
Tekirdağ Boya Ustası
Burdur Evden Eve Nakliyat
Kalıcı Makyaj
Adana Evden Eve Nakliyat
2A86B
ReplyDeleteBitlis Şehir İçi Nakliyat
Ankara Fayans Ustası
Adana Parça Eşya Taşıma
Burdur Şehir İçi Nakliyat
Bingöl Parça Eşya Taşıma
Iğdır Evden Eve Nakliyat
Denizli Parça Eşya Taşıma
Antalya Şehir İçi Nakliyat
Erzincan Şehir İçi Nakliyat
367FD
ReplyDeleteUrfa Evden Eve Nakliyat
Karabük Şehir İçi Nakliyat
Sivas Şehirler Arası Nakliyat
Ankara Asansör Tamiri
Siirt Şehirler Arası Nakliyat
Bilecik Parça Eşya Taşıma
Pancakeswap Güvenilir mi
Bitlis Lojistik
Çankırı Şehir İçi Nakliyat
F9E8D
ReplyDeleteAntalya Şehir İçi Nakliyat
Aydın Şehir İçi Nakliyat
Iğdır Şehir İçi Nakliyat
Çankırı Şehir İçi Nakliyat
Kırşehir Şehirler Arası Nakliyat
AAX Güvenilir mi
Yozgat Şehir İçi Nakliyat
Samsun Lojistik
Trabzon Şehir İçi Nakliyat
A6B78
ReplyDeleteAydın Evden Eve Nakliyat
https://steroidsbuy.net/steroids/
oxandrolone anavar for sale
Silivri Fayans Ustası
Çerkezköy Çatı Ustası
Bayburt Evden Eve Nakliyat
Çankırı Evden Eve Nakliyat
buy testosterone enanthate
buy testosterone propionat
65079
ReplyDelete%20 binance referans kodu
680F4
ReplyDeletehatay parasız görüntülü sohbet uygulamaları
diyarbakır yabancı görüntülü sohbet
yozgat görüntülü sohbet ücretsiz
konya sohbet chat
çanakkale en iyi sesli sohbet uygulamaları
erzincan ücretsiz sohbet siteleri
van canlı ücretsiz sohbet
adana sesli sohbet odası
kayseri canlı görüntülü sohbet
E622A
ReplyDeleteYeni Çıkacak Coin Nasıl Alınır
Clubhouse Takipçi Hilesi
Binance Nasıl Üye Olunur
Coin Madenciliği Nedir
Binance Komisyon Ne Kadar
Binance Referans Kodu
Shibanomi Coin Hangi Borsada
Tesla Coin Hangi Borsada
Ort Coin Hangi Borsada
شركة مكافحة النمل الابيض بالاحساء eSoaMHGsMt
ReplyDelete