{"id":21,"date":"2020-01-13T12:00:48","date_gmt":"2020-01-13T12:00:48","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=21"},"modified":"2024-02-09T13:39:10","modified_gmt":"2024-02-09T18:39:10","slug":"oracle-decode-function","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/oracle-decode-function\/","title":{"rendered":"Oracle decode() function"},"content":{"rendered":"\n<p>Decode function has the same functionality as an IF-THEN-ELSE statement. It is present in Oracle 9i and above. It has the syntax<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>decode(column\/expression, value, substitute, default value)<\/code><\/pre>\n\n\n\n<p>For example,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>decode(gender, 'M', 'Male', 'F', 'Female', gender) gndr<\/code><\/pre>\n\n\n\n<p>This is like saying the following in PL\/SQL:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>IF gender = 'M' THEN\n  gndr := 'Male';\nELSIF gender = 'F' THEN\n  gndr := 'Female';\nELSE\n  gndr := gender;\nEND IF;<\/code><\/pre>\n\n\n\n<p>An SQL example,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>select name, decode(gender, 'M', 'Male', 'F', 'Female', gender) gndr from employee;<\/code><\/pre>\n\n\n\n<p>Decode can have a maximum of 255 comma separated components. I you have so many components, then you might need to rethink the SQL you are writing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Decode function has the same functionality as an IF-THEN-ELSE statement. It is present in Oracle 9i and above. It has the syntax For example, This is like saying the following in PL\/SQL: An SQL example, Decode can have a maximum of 255 comma separated components. I you have so many components, then you might need [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,515],"tags":[14,3],"class_list":["post-21","post","type-post","status-publish","format-standard","hentry","category-database","category-oracle","tag-database","tag-oracle"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/21","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=21"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/21\/revisions"}],"predecessor-version":[{"id":22,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/21\/revisions\/22"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}