Check for 6 or more consecutive numbers in a column in oracle sql - sql

I need help with a query to identify unstructured data. I need to identify all the rows which have more than 6 consecutive numbers in their data. I know we can use regular expressions like ^[0-9] for the same.
For example:
I have a column named Address. The address column may contain 6 or more consecutive numbers. I need to identify which rows contain more than 6 consecutive numbersi in them.
675467 should be the output
67433232 should be the output
4453 should not be the output.

I second Egor Skriptunoff, you can the answer on this demo on SQLFiddle

Related

Find Number of times a particular character appears in a string using MDX query

In the Microsoft SSAS, I have a dimension column that contains multiple values separated by the special character | in a single row as below.
Example value of a row: Image|Video|Audio|
Requirement:
So, I need to count the number of values present in the dimension column using the special character.
In this case, I need to get the count of | using the MDX query and my expected answer is 3.
Could someone help me with this? In short, Is there an MDX function that counts the number of times a particular character appears in a string?
Similar question for SQL: Number of times a particular character appears in a string

How do you do multiple substrings for a field in Teradata?

I have a field to pull account numbers which have different lengths and I want to pass the last four digits of the account number. The dilemma I am having is that since they are different lengths I am having trouble in substringing the fields. The standard length is 11 digits but there are accounts with 9 digits and 7 digits.
How do I substring those values in multiple substrings to capture all the account last 4 digits in one query?
This currently what I have:
SELECT SUBSTRING(ACCT_NBR,7,4) AS BNK_ACCT_NBR
FROM NAMEOFTABLE;
I want to have additional substrings to capture the account numbers that don't have 11 digits similar to
SUBSTRING(ACCT_NBR,5,4)
SUBSTRING(ACCT_NBR,4,4)
The results should look like:
76587990891 - 0891
654378908 - 8908
45643456 - 3456
Can you please help me in figuring out how I can do that?
Thanks.
Is ACCT_NBR a VarChar or an INT?
VarChar:
Right (ACCT_NBR,4)
Substr(ACCT_NBR,Char_Length(x)-3)
INT:
ACCT_NBR MOD 10000

SQLite3 Order by highest/lowest numerical value

I am trying to do a query in SQLite3 to order a column by numerical value. Instead of getting the rows ordered by the numerical value of the column, the rows are ordered alphabetically by the first digit's numerical value.
For example in the query below 110 appears before 2 because the first digit (1) is less than two. However the entire number 110 is greater than 2 and I need that to appear after 2.
sqlite> SELECT digit,text FROM test ORDER BY digit;
1|one
110|One Hundred Ten
2|TWO
3|Three
sqlite>
Is there a way to make 110 appear after 2?
It seems like digit is a stored as a string, not as a number. You need to convert it to a number to get the proper ordering. A simple approach uses:
SELECT digit, text
FROM test
ORDER BY digit + 0

How can I "dynamically" split a varchar column by specific characters?

I have a column that stores 2 values. Example below:
| Column 1 |
|some title1 =ExtractThis ; Source Title12 = ExtractThis2|
I want to remove 'ExtractThis' into one column and 'ExtractThis2' into another column. I've tried using a substring but it doesn't work as the data in column 1 is variable and therefore it doesn't always carve out my intended values. SQL below:
SELECT substring(d.Column1,13,24) FROM dbo.Table d
This returns 'Extract This' but for other columns it either takes too much or too little. Is there a function or combination of functions that will allow me to split consistently on the character? This is consistent in my column unlike my length count.
select substring(col1,CHARINDEX('=',col1)+1,CHARINDEX (';',col1)-CHARINDEX ('=',col1)-1) Val1,
substring(col1,CHARINDEX('=',col1,CHARINDEX (';',col1))+1,LEN(col1)) Val2
from #data
there is duplicate calculation that can be reduced from 5 to 3 to each line.
but I want to believe this simple optimization done by SQL SERVER.

Using a query in Microsoft Access to compare two fields and find multiple matching values

I have a problem I am trying to solve using a query instead of VBA.
I have two fields which we'll call "FPC" and "Code". Both fields contain numbers. An FPC value will match a Code value. What I want to make sure is that once an FPC value matches a Code value, the same FPC value does not match up with a DIFFERENT Code Value and vice versa - Once a Code Value is used, I don't want the Code Value to match up with more than one FPC.
It is important to note that there are duplicate values used in both fields.
Here is an example:
FPC CODE
1 12
1 12
1 14
2 16
3 11
3 11
4 17
5 19
6 16
There are two errors here:
1. The FPC "1" is matched up with two different Code Values.
2. The Code "16" is matched up with two different FPC values.
Please let me know your suggestions. I was thinking a query would help, and then running VBA to pull the results (there is tens of thousands of records).
What is the purpose of the query? Just to identify problems? If yes then something like
select FPC, count(distinct(CODE)) from tableName where count(distinct(CODE)) >1 group by FPC
(and the converse query for CODE vs. FPC) should be OK.