When the input contains characters not contained within the standard or URL-safe alphabets specified by RFC 4648 the function returns error "Msg 9803, Level 16, State 20, Line 15, Invalid data for type "Base64Decode"".This function ignores whitespace characters: \n, \r, \t, and. The URL-safe alphabet specified within RFC 4648 Table 2 is also accepted. The encoded string's alphabet must be that of RFC 4648 Table 1 and may include padding, though padding is not required. If the input expression is null, the output is null.Varbinary(max) if the input is varchar(max).Transact-SQL syntax conventions Syntax BASE64_DECODE(expression)Īn expression of type varchar (n | max). You can view EDUCBA’s recommended articles for more information.Applies to: SQL Endpoint and Warehouse in Microsoft FabricīASE64_DECODE converts a base64 encoded varchar into the corresponding varbinary. We hope that this EDUCBA information on “SQL DECODE()” was beneficial to you. It is a built-in function in ORACLE / PL SQL database management servers. The function is a close relative of CASE statements. In the above example, we have performed the following task using the DECODE function and have then ordered the result set by college_id.ĭECODE function is used to perform procedural IF-THEN-ELSE logic in SQL. SQL query to categories college fees into affordable and expensive for an Indian student, considering everything above $ 10000 as expensive.ĭECODE(fees,10000,'Affordable','Expensive') In the above example, we have performed the following IF-THEN-ELSE logic statements and then ordered the entire result set by college_id.Ĭode: IF college_name = 'Massachusetts Institute of Technology'ĮLSE IF college_name = 'California Institute of Technology' 'MIT','California Institute of Technology','CalTech','IIT') as college_name SELECT college_id, DECODE(college_name,'Massachusetts Institute of Technology', SQL query to illustrate abbreviation of college names based on the available data using DECODE function. Simple illustration of above mentioned DECODE function is as follows: In this example, we have performed a simple SQL task for categorizing colleges based on their location. Simple SQL query to illustrate use of DECODE function.ĭECODE (college_id, 10003,'Massachusetts, USA', The data in the “college_details” table after performing the above mentioned INSERT operations looks something as shown below: INSERT INTO college_details VALUES (10003, 'Massachusetts Institute of Technology', 'Massachusetts,India', 51520) select * from college_details INSERT INTO college_details VALUES (10004, 'California Institute of Technology', 'California ,USA', 60520) INSERT INTO college_details VALUES (10002, 'Indian Institute of Technology Bombay', 'Mumbai,India', 10000) We can use the following insert statements.Ĭode: INSERT INTO college_details VALUES (10001, 'Indian Institute of Technology Roorkee', 'Roorkee,India', 10000) Having created the table, let us now input some random data in it to work with in the subsequent exercises. We can use the following SQL CREATE TABLE statement to perform the task.Ĭollege_name character varying(255) NOT NULL,Ĭollege_location character varying(255) NOT NULL, Let us first create a ‘college_details’ table which contains college id, college name, location and fees for demonstration purposes. ![]() The simple illustration of the above mentioned decode function is as follows: The functionality of DECODE in ORACLE with following flowchart. ![]() ![]() ![]() And it finally converts back the data_type of result to the data_type of the expression. The DECODE function automatically converts or casts the expression to the data type of the first search argument or search_1. If it’s FALSE then DEFAULT value is returned. The first step is comparison of expression and search_1, if the expression = search_1 is TRUE then result_1 is returned.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |