Oracle SQL REPLACE '[' [closed] - sql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am trying to make changes to a "FORMULA" column in a table with SQL using REPLACE(FORMULA, '[H2]', '(2H)'); but it doesn't change the [H2] text. Going the other direction, REPLACE(FORMULA, '(H2)', '[2H]'); works fine.
I have to assume that '[' and ']' have special meanings in Oracle SQL, though I've not been able to find clues yet.
Suggestions welcome!

Are you trying to replace only [H2] to (2H) or everything like [AB122] TO (122AB) ?
if only [H2] then
with datas as ( select '[AA2][AH33][H2][AH267]' AS FORMULA FROM DUAL )
select REGEXP_REPLACE(FORMULA,'\[H2\]','(2H)') from datas;
if Everything then
with datas as ( select '[AA2][AH33][AH267]' AS FORMULA FROM DUAL )
select REGEXP_REPLACE(FORMULA,'\[([A-Z]+)([0-9]+)\]','(\2\1)') from datas;
Now without some sample data, it's hard to make sure that it fits all your cases
PS : your original replace works on my database

Related

A newbie in SQL asking about functions [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
How can I find data that dont end with letter 'g' without using NOT LIKE function, please help
select * from table where right(column, 1) != 'g'
Since you asked how to do it using "not like," I'll answer that. The function version provided by #Zoories would be more efficient.
This works at w3schools.com
SELECT * FROM Customers where CustomerName not like '%g';

Is there any way to put WHERE filter inside the SELECT statement in SQL? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I got a task that i need to know how can i put WHERE clause inside the SELECT statement (like SELECT .... WHERE.... FROM...) . hope you guys could help me. thank you :)
'Where' is used to filter the data based on a condition.
The general syntax is:-
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Here you can get a better overview.

using mid function in bigquery [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a column that has data like this:
TEXT000612
TEXT721
TEXT8
Expected output:
000612
721
8
The column only has a 4 letter text text and its only at the beginning at the cell. But the numbers can vary in length. Also, I want to make sure the numbers are string.
There is no mid function in BQ.
Also, if you dont like my question or think it needs to be improve please give me a chance to improve it before flagging it.
Few options for BigQuery Standard SQL
#standardSQL
SELECT col,
SUBSTR(col, 5),
REGEXP_REPLACE(col, r'^TEXT', '')
FROM `project.dataset.table`
If you just want the numbers, use substr():
substr(col, 5)
You can cast() this to a number if you want.

how to merge a row data into above row..?which have few column same [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a table like.
And i want to answer like a table below:-
I think you want to use aggregation, like this:
select empcode, coode, finyear, wef,
max(cl_opn_bal) as cl_open_bal,
. . .
from table t
group by empcode, coode, finyear, wef;

Fill with zero to complete a defined number in sql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I need to complete cards numbers in sql. I have the prefix =11111 and the number of the card which is variable, therefore it could be '25' or '2130' but at the end I must have 14 numbers. So I need to fill spaces with zeros.
I've read about 'LPAD' but I don't understand very well this method.
You could use lpad, but if you're starting with a number you could use a 9-digit format model instead, and concatenate that onto your prefix:
select '11111' || to_char(25, 'FM000000000') from dual;
11111000000025
The FM format modifier stops Oracle adding a space for a potential +/- sign indicator.
SQL Fiddle demo
Use the ZEROFILL attribute.
But your database should only be responsible for saving data and not changing it before saving.
The best way would be to send the zerofilled data to the database server.