The Language of SQL- P11

The Language of SQL- P11:Research has shown that, being pressed for time, most readers tend to skip the introduction of any book they happen to read and then proceed immediately to the first real chapter. With that fact firmly in mind, we will only cover relatively unimportant material in the introduction, such as an explanation of what you will and will not learn by reading this book. | 36 Chapter 4 Using Functions Here s an example that covers both functions SELECT UPPER Abraham Lincoln AS Convert to Uppercase LOWER ABRAHAM LINCOLN AS Convert to Lowercase The output is Convert to Uppercase Convert to Lowercase ABRAHAM LINCOLN abraham lincoln Composite Functions An important characteristic of functions whether they are character mathematical or date time is that two or more functions can be combined to create composite functions. A composite function with two functions can be said to be a function of a function. Let s go back to the George Washington query to illustrate. Again you re working from this data President George Washington Remember that the President column is 20 characters long. In other words there are three spaces to the right of the value George Washington. In addition to illustrating composite functions this next example will also cover the RTRIM function mentioned in the previous section. The statement SELECT RIGHT RTRIM President 10 AS Last Name FROM tablel returns this data Last Name Washington Why does this produce the correct value now Let s examine how it works. There are two functions involved RIGHT and RTRIM. When evaluating composite Date Time Functions 37 functions you always start from the inside and work your way out. In this example the innermost function is RTRIM President This function takes the value in the President column and eliminates all spaces on the right. After this is done the RIGHT function is applied to the result to bring back the desired value. Since RTRIM President equals George Washington you can say that SELECT RIGHT RTRIM President 10 is the same as saying SELECT RIGHT George Washington 10 In other words you can obtain the desired result by first applying the RTRIM function to your input data and then adding in the RIGHT function to the expression. DATABASE DIFFERENCES Oracle As mentioned Oracle requires you to use their substr function rather than the right function available in Microsoft SQL .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
36    784    5    02-07-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.