Showing posts with label Oracle. Show all posts
Showing posts with label Oracle. Show all posts

Friday, January 30, 2015

Oracle - Function Based Index

A function-based index computes the value of an expression that involves one or more columns and stores it in the index. The index expression can be an arithmetic expression or an expression that contains a SQL function, PL/SQL function, package function, or C callout.[1]
Oracle generates a column name of the format "SYS_NC?????$" in all_ind_columns table.

If you want to find the corresponding expression for the index, you can like this.

Execute:

SELECT a.index_name, a.column_name, b.column_expression FROM all_ind_columns a LEFT JOIN all_ind_expressions b ON A.index_name = b.index_name AND A.column_position = b.column_position WHERE a.index_name='table_name$unique_index_name';



Result:

table_name$unique_index_name  SYS_NC00031$   TRUNC("UPDATE_DATE")


References


  1. https://docs.oracle.com/cd/E11882_01/appdev.112/e41502/adfns_indexes.htm#ADFNS00505


Create a Successful Online Store at Bigcommerce! Try it Free Now!

Wednesday, January 28, 2015

Oracle - Find Time Difference (in Seconds) of Two Timestamp Columns

Suppose you have two timestamp columns in an Oracle table, from_timestamp and to_timestamp, and you want to find the difference in seconds of the two columns. 

You can achieve it by using the following SQL statement:


SELECT FROM_TIMESTAMP, TO_TIMESTAMP, 

  (

  to_number(TO_CHAR(FROM_TIMESTAMP, 'J') * 86400 + TO_CHAR(FROM_TIMESTAMP, 'SSSSS')) - 

  to_number(TO_CHAR(TO_TIMESTAMP, 'J') * 86400 + TO_CHAR(TO_TIMESTAMP, 'SSSSS'))

  ) 

  TIME_DIFF

FROM SOME_TABLE; 




Create a Successful Online Store at Bigcommerce! Try it Free Now!