I want to selec column names and convert to pascal case. My column names are like this:
IMG_SAR_NAME
INT_AKT_DESC
I want to split "_" names and convert to:
ImgSarName
IntAktDesc
I can get column names with sql
Select COLUMN_NAME from ALL_COL_COMMENTS WHERE TABLE_NAME="MY_TABLE;
But can not convert to pascalcase.
I don't know if always the underscore is the separator, but if it is, you can do this:
SQL> select replace(initcap('IMG_SAR_NAME'),'_','') from dual ;
REPLACE(IN
----------
ImgSarName
SQL>
The Oracle INITCAP() function sets the first letter of each word in
uppercase, all other letters in lowercase. Words are delimited by
white space or characters that are not alphanumeric. A string whose
first character in each word will be converted to uppercase and the
rest characters will be converted to lowercase.
Related
I'm using oracle and hive db engine and supposed that in a varchar column (phone number), I only want to retrieve record with digit and hyphen '-'
i.e. 03-1234 5678
But how if I want to retrieve if column has special chars (except hyphen) and alphabet using like or rlike.
i.e 03-ABC123$#45XYZ or 03-AB123 Y123#& (with space)
Thanks in advance!
Using RLIKE we can try:
SELECT * FROM yourTable WHERE phone RLIKE '^[0-9 -]+$';
This will match only phone numbers consisting of digits, space, or hyphen.
I have a field in a database table in the format:
111_2222_33333,222_444_3,aaa_bbb_ccc
This is format is uniform to the entire field. Three underscore separated numeric values, a comma, three more underscore separated numeric values, another comma and then three underscore separated text values. No spaces in between
I want to extract the middle value from the second numeric sequence, in the example above I want to get 444
In a SQL query I inherited, the regex used is ^.,(\d+)_.$ but this doesn't seem to do anything.
I've tried to identify the first comma, first number after and the following underscore ,222_ to use as a starting point and from there get the next number without the _ after it
This (,\d*_)(\d+[^_]) selects ,222_444 and is the closest I've gotten
We can try using REGEXP_REPLACE with a capture group:
SELECT
REGEXP_REPLACE(
'111_2222_33333,222_444_3,aaa_bbb_ccc',
'^[^,]+,[^_]+_(.*?)_[^_]+,.*$',
'\1') AS num
FROM yourTable;
Here is a demo showing that the above regex' first capture group contains the quantity you want.
Demo
How to avoid selecting row which has special symbol like mentioned below .
We can use range of ASCII character as below. CHAR(n) returns character value of integer ASCII code n
SELECT *
FROM yourTable
WHERE ID NOT LIKE '%['+CHAR(32) +'-'+CHAR(126)+']%'
OR Name NOT LIKE '%['+CHAR(32) +'-'+CHAR(126)+']%';
Refer ASCII characters
You could use SQL Server's enhanced LIKE operator:
SELECT *
FROM yourTable
WHERE ID NOT LIKE '%[^A-Za-z0-9_-]%' AND Name NOT LIKE '%[^A-Za-z0-9_-]%';
This would select only rows where both ID and Name columns do not contain any special characters. Special characters here are defined as anything other alphanumeric, underscore, and hyphen.
I have the string '1_A_B_C_D_E_1_2_3_4_5' and I am trying to extract the data 'A_B_C_D_E'. I am trying to remove the _1_2_3_4_5 & the 1_ portion from the string. Which is essentially the numeric portion in the string. any special characters after the last alphabet must also be removed. In this example the _ after the character E must also not be present.
and the Query I am trying is as below
SELECT
REGEXP_SUBSTR('1_A_B_C_D_E_1_2_3_4_5','[^0-9]+',1,1)
from dual
The Data I get from the above query is as below: -
_A_B_C_D_E_
I am trying to figure a way to remove the underscore towards the end. Any other way to approach this?
Assuming the "letters" come first and then the "digits", you could do something like this:
select regexp_substr('A_B_C_D_E_1_2_3_4_5','.*[A-Z]') from dual;
This will pull all the characters from the beginning of the string, up to the last upper-case letter in the string (.* is greedy, it will extend as far as possible while still allowing for one more upper-case letter to complete the match).
I have the string '1_A_B_C_D_E_1_2_3_4_5' and I am trying to extract the data 'A_B_C_D_E'
Use REGEXP_REPLACE:
SQL> SELECT trim(BOTH '_' FROM
2 (REGEXP_SUBSTR('1_A_B_C_D_E_1_2_3_4_5','[0-9]+', ''))) str
3 FROM dual;
STR
---------
A_B_C_D_E
How it works:
REGEXP_REPLACE will replace all numeric occurrences '[0-9]+' from the string. Alternatively, you could also use POSIX character class '[^[:digit:]]+'
TRIM BOTH '_' will remove any leading and lagging _ from the string.
Also using REGEXP_SUBSTR:
SELECT trim(BOTH '_' FROM
(REGEXP_SUBSTR('1_A_B_C_D_E_1_2_3_4_5','[^0-9]+'))) str
FROM dual;
STR
---------
A_B_C_D_E
a sql code or function to remove all the special characters from a particular column in a table.
:a oracle code to remove all the special character from a column .for example ABC D.E.F so it should be ABC DEF,space should be maintained between 2 words.
If you want to remove the hyphens and the dots, you can go with translate like so:
select
translate(column_name, 'Q._"?!##$%^&*æ', 'Q')
from
your_table;
The easiest way should be a Regular Expression, this removes anything but spaces and letters a to z:
REGEXP_REPLACE(col, '[^a-z ]','' , 1, 0, 'i')