Here’s an example of SQL TO_CHAR function. Here, I’ve explained how to use this function correctly.
How to Use SQL TO_CHAR to Convert DATE to CHAR
Create View Order_V5 AS SELECT Ord_Number, Cust_Number ,TO_CHAR(Order_Date , 'MON, DD, YYYY') AS Order_Date ,TO_CHAR(Order_Total, '999,999.99') AS Total FROM Order_Table ;
Query Result
Ord_Number | Cust_Number | Order_Date | Total |
---|---|---|---|
123456 | 22222222 | MAY, 04, 2000 | 12,347.53 |
123512 | 55555555 | JAN, 01, 2001 | 8,005.91 |
123552 | 31323134 | OCT, 01, 2002 | 5,111.47 |
123585 | 87323456 | OCT, 10, 2003 | 15,231.62 |
123777 | 57896883 | SEP, 09, 1999 | 23,454.84 |
SQL Views and its Advanatges
A view is SQL query of primary need is to protect BASE TABLE data. The view can be created with or without ORDER BY clause.
- A view is a virtual table
- A view may define a subset of columns
- A view can even define a subset of rows if it has a WHERE clause
- A view never duplicates data or stores the data separately
- Views provide security
- An additional level of security is provided
- Helps the business user not miss join conditions
- Help control read and update privileges
- Unaffected when new columns are added to a table
- Unaffected when a column is dropped unless it’s referenced in the view
Related Posts