Presentation is loading. Please wait.

Presentation is loading. Please wait.

Oracle SQL Built-in Functions Chapter 5 in Lab Reference.

Similar presentations


Presentation on theme: "Oracle SQL Built-in Functions Chapter 5 in Lab Reference."— Presentation transcript:

1 Oracle SQL Built-in Functions Chapter 5 in Lab Reference

2 Column Alias Names Example: Select name AS Employee From employee; Built-in Functions2 EMPLOYEE Jamil N.Samir Amani F.Zaki Jihan H.Walid Ramy S.Nabil Joyce A.Eman Ahmad V.Jabbar James B.Baher 7 rows selected.

3 Column Alias Names When you want to include spaces or special characters in alias names, then enclose the alias name in double quotation marks.Example: Select name || ' has an id of ' || ssn "Important information" From employee; Built-in Functions3 IMPORTANT INFORMATION Jamil N.Samir has an id of Amani F.Zaki has an id of Jihan H.Walid has an id of Ahmad V.Jabbar has an id of James B.Baher has an id of rows selected.

4 Table Alias Names Example: Select T.item_id, T.item_desc From item T; Built-in Functions4 ITEM_ID ITEM_DESC LA-101 Box, Small NY-102 Bottle, Large

5 Number Functions ROUND The ROUND function rounds the value you want to modify.Example: Select product_name, product_price, ROUND(product_price,0) From product; Built-in Functions5 PRODUCT_NAME PRODUCT_PRICE ROUND(PRODUCT_PRICE,0) Roco Pencil FABER Pen 5 5 Roco Pad 2.2 2

6 Number Functions TRUNC The TRUNC function truncates precision from a number.Example: Select product_name, product_price, TRUNC(product_price,0) From product; Built-in Functions6 PRODUCT_NAME PRODUCT_PRICE TRUNC(PRODUCT_PRICE,0) Roco Pencil FABER Pen 5 5 Roco Pad 2.2 2

7 Number Functions MOD mod(m,n)Example: Select mod(salary,3) From employee where ssn= ; Built-in Functions7 MOD(SALARY,3)

8 Number Functions POWER power(m,n) number m raised to the power of n.Example: Select power(salary,2) From employee where ssn= ; Built-in Functions8 POWER(SALARY,2)

9 Number Functions SIGN & SQRT sign(n) if n=0 returns 0 if n>0 returns 1 if n<0 returns -1 sqrt(n) returns square root of n.Example: Select sqrt(salary) From employee where ssn= ; Built-in Functions9 SQRT(SALARY)

10 Text Functions UPPER, LOWER & INITCAP These three functions change the case of the text you give them.Example: Select UPPER(product_name) From product;Example: Select LOWER(product_name) From product; Built-in Functions10 UPPER(PRODUCT_NAME) ROCO PENCIL FABER PEN ROCO PAD LOWER(PRODUCT_NAME) roco pencil faber pen roco pad

11 Example: Select INITCAP(product_name) From product; Built-in Functions11 Text Functions UPPER, LOWER & INITCAP INITCAP(PRODUCT_NAME) Roco Pencil Faber Pen Roco Pad

12 To determine the lengths of the data stored in a database column.Example: Select product_name, LENGTH(product_name) AS Name_Length From Product where LENGTH(product_name)>8; Built-in Functions12 Text Functions LENGTH PRODUCT_NAME NAME_LENGTH FABER Pen 9 Roco Pencil 11

13 Text Functions SUBSTR To separate multiple bits of data into discrete segments.Example: Select SUBSTR(item_id,1,2) Location, SUBSTR(item_id,4,3) Number, Item_desc From item; Built-in Functions13 LOCATION NUMBER ITEM_DESC LA 101 Box, Small NY 102 Bottle, Large

14 Text Functions INSTR Useful when you have substrings vary in length. This mean not only is the length of the first substring is unknown, but the starting position of the second substring can also vary.Example: Select item_desc, INSTR(item_desc,,, 1) From item; Built-in Functions14 ITEM_DESC INSTR(ITEM_DESC,,, 1) Box, Small4 Bottle, Large7

15 Text Functions REPLACE Replace(char, str1, str2) Every occurrence of str1 in char is replaced by str2.Example: Select Replace(name,'Jamil','Sara') From employee; Built-in Functions15 REPLACE(NAME,'JAMIL','SARA') Sara N.Samir Amani F.Zaki Jihan H.Walid Ramy S.Nabil Joyce A.Eman Ahmad V.Jabbar James B.Baher 7 rows selected.

16 Text Functions Concatenation operator || To concatenate column names with other column names or with literal characters.Example: Select name || has an id of || ssn From employee; Built-in Functions16 NAME||HAS AN ID OF'||SSN Jamil N.Samir has an id of Amani F.Zaki has an id of Jihan H.Walid has an id of Ramy S.Nabil has an id of Joyce A.Eman has an id of Ahmad V.Jabbar has an id of James B.Baher has an id of rows selected.

17 Date Functions FunctionDescriptionSyntax Sysdate Get current system date and time. INSERT INTO employee VALUES (…………, trunc(sysdate),……….); Add_months(d, n) Adds n months to date d. ADD_MONTHS(starting_date, number_of_months) Months_between(f, s) Difference in months between date f and date s. MONTHS_BETWEEN(later_date, earlier_date) Built-in Functions17

18 Data Conversion Functions Built-in Functions18 FunctionDescription To_char(input_value, format_code) Converts any data type to character data type. To_number(input_value, format_code) Converts a valid set of numeric character data to number data type. To_date(input_value, format_code) Converts character data of the proper format to date data type.

19 Null values Some columns may contain Null values. You can use the NVL function to display actual values instead of null values in a query result. NVL(column|expression, replacement_value) Replacement_value must be of the same data type of the column (if not use data conversion functions). Built-in Functions19

20 Null values Example: Select name, NVL(SUPERSSN, ) From employee; Built-in Functions20 NAME NVL(SUPERSSN, ) Jamil N.Samir Amani F.Zaki Jihan H.Walid Ramy S.Nabil Joyce A.Eman Ahmad V.Jabbar James B.Baher rows selected.


Download ppt "Oracle SQL Built-in Functions Chapter 5 in Lab Reference."

Similar presentations


Ads by Google