I am using Oracle SQL Developer. I need to find the rows where column1 starts with ‘987’ or ‘I’. Column1 is a String(18). Some sample patterns in this column include: 9(9), 9(12), and others. I am not familiar with the code to see how a column starts with certain values in Oracle SQL. Sample Code is below. Attempt below.
Code
select * from table1
where column1
Attempt Code
SELECT
REGEXP_SUBSTR(column1,
'987') "REGEXP_SUBSTR"
FROM table1;
asked Jan 7, 2020 at 18:59
devcoder112
1612 gold badges4 silver badges15 bronze badges
-
Are you familiar with the SQL "like" operator?Abra– Abra2020年01月07日 19:06:08 +00:00Commented Jan 7, 2020 at 19:06
3 Answers 3
You can use a regular expression for this:
where regexp_like(column1, '^(987|I)')
answered Jan 7, 2020 at 19:37
Gordon Linoff
1.3m62 gold badges707 silver badges858 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
LysanderM
This one should be marked as a more convenient answer.
You just need to use LIKE.
select *
from table1
where column1 like '987%' or column1 like 'I%';
answered Jan 7, 2020 at 19:05
alexherm
1,3502 gold badges21 silver badges35 bronze badges
Comments
CREATE TABLE hs(WH VARCHAR2(100));
SELECT * FROM hs WHERE REGEXP_LIKE(WH,'^987|^I', 'i') ORDER BY WH;
Comments
lang-sql