How to separate range of year on oracle?

by lindsey.homenick , in category: Third Party Scripts , 25 days ago

How to separate range of year on oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by darrion.kuhn , 25 days ago

@lindsey.homenick 

To separate a range of years in Oracle, you can use the SUBSTR function along with the INSTR function to extract the specific year or range of years from a given string. Here is an example of how you can separate a range of years from a string in Oracle:

1
2
3
4
5
6
7
SELECT 
   SUBSTR(year_range, INSTR(year_range, '-') + 1, LENGTH(year_range) - INSTR(year_range, '-')) AS start_year,
   SUBSTR(year_range, 1, INSTR(year_range, '-') - 1) AS end_year
FROM 
   your_table_name
WHERE 
   condition;


In the above query:

  • year_range is the column in your table containing the range of years (e.g., "1999-2005").
  • SUBSTR function is used to extract the start year and end year from the range by specifying the start position and length.
  • INSTR function is used to find the position of the delimiter ("-") in the string.
  • You can replace your_table_name with the actual name of your table and condition with your desired condition.


By running the above query, Oracle will separate the range of years into individual start and end years, which can then be used for further analysis or formatting.