Let's say I have a database table:
ID | DESCRIPTION
1 | Some value '123' added
2 | Deleted value '333' by 'Someone'
Jpa entity:
@Entity
@Table(name = "LOG")
public class Log {
@Id
@Column(name = "ID")
private Long id;
@Column(name = "DESCRIPTION")
private String description;
...
}
And working jpa query to retrieve first found numeric value inside single quotas:
@Query(value = "select distinct REGEXP_SUBSTR( log.DESCRIPTION, '''(\\d+)''',1,1,'',1) from Log log where 1=1 ", nativeQuery = true)
List<String> findObjectIdsInDescription();
I'm working on Oracle database hence REGEXP_SUBSTR + native query, which is working fine for me right now.
Is there a database independent approach using jpa query only? I'm asking as I also need it for different databases.