LN Function in SQLThe LN is a numeric function in SQL which returns the natural logarithm of the specified integer number. Syntax of LN FunctionIn the LN syntax, we have to pass that decimal number whose log base 2 value we want to find. In the Structured Query Language, we can also use the LN function with the column of the table as shown in the following block: In this syntax, we have to define the name and column of that table on which we want to perform the LN function. Examples of LN functionExample 1: This example gets the value of log 1: Output:
Example 2: This example returns the logarithm of 10 in the output: Output:
Example 3: This example returns the logarithm of 8 in the output: Output:
Example 4: This example returns the logarithm of 255 in the output: Output:
Example 5: This example uses the LN function with the SQL table. In this example, we will create the new table through which we will perform the LN function on the numeric fields of the table: The following shows the syntax to create the new table in SQL: The following CREATE statement creates the Product_Details table for storing the price and quantity of products: The following multiple INSERT queries insert the records of products with their selling and purchasing price into the Product_Details table: The following SELECT statement displays the inserted records of the above Product_Details table:
Query 1: The following SELECT query uses the LN function with the Product_Quantity column of the above Product_Details table: This query shows the natural logarithm value of id of each product. Output:
Query 2: The following SELECT query uses the LN function with the Purchasing_Price column of the above Product_Details table: This query shows the natural logarithm value of purchasing price of each product. Output:
Query 3: The following SELECT query uses the LN function with the Product_Rating column of the above Product_Details table: This query shows the natural logarithm value of rating of each product from the above table. Output:
Query 4: The following SELECT query uses the LN function with the and Purchasing_Price and Selling_Price column of the above Product_Details table: This query shows the natural logarithm value of selling price of each product. Output:
Next TopicUNICODE Function in SQL
|