I'm working with Oracle and JDBC to set up a database with a list of movies. The fields that load are MovieId, MovieTitle, and Genre. Format ex:
MovieId MovieTitle Genre
1 Toy Story (1997) Animated
Now I need to split my MovieTitle to list the year 1997 in a separate column called "Year". I got it to work earlier using this:
SELECT SUBSTR(Movies.MovieTitle, 1, INSTR(Movies.MovieTitle, '(')-1) AS MovieTitle,
SUBSTR(Movies.MovieTitle, INSTR(Movies.MovieTitle, ')')) AS Year
FROM MOVIES;
However that is no good, because some of my movies have parenthesis in their title. So I believe I need to use regex, however I can't get it to work. Here is what I have been playing around with:
WITH TEST AS
(SELECT MovieTitle FROM Movies)
SELECT REGEXP_SUBSTR(Movies.MovieTitle, '^\(\d{4}\)$', 1, 1) MovieTitle,
REGEXP_SUBSTR(Movies.MovieTitle, '^\(\d{4}\)$', 1, 2) Year
FROM Movies;
All that gives me is two null columns for all my movies. Am I on the right track with this or way off? Another concern is that I want this to be an update on my original Movies table, not a new query or table of its own. Thanks for any suggestions.