Here is the example data
nvarchar(5) null,
bigint not null,
nvarchar(5) null
if I'd like to replace nvarchar(5) null to be nvarchar(255) null
then I ctrl+H
Find what : nvarchar(5) null
Replace with : nvarchar(255) null
The result is nvarchar255 null, but I need to be nvarchar(255) null
Please help.
At the bottom of the search dialog are three radio buttons for "Search mode". It sounds like you selected "Regular expression". You should select "Normal" and try again.
Related
While converting Oracle to Postgresql I came to know the following Oracle query need to be converted in Postgres.
Oracle Query: Find pattern and replace with null
select regexp_replace('1', '[^0-9]', null) from dual;
select regexp_replace('a', '[^0-9]', null) from dual;
select regexp_replace('1a1', '[^0-9]', null) from dual;
My try:
As per the postgres document we need to use REGEXP_REPLACE with [[:alpha:]] pattern.
But the statement is replacing with empty string if match found. I'm looking for null instead.
PostgreSQL Query:
select REGEXP_REPLACE('1','[[:alpha:]]','','g') --Correct
select REGEXP_REPLACE('a','[[:alpha:]]','','g') --Wrong: output should be NULL
select REGEXP_REPLACE('1a1','[[:alpha:]]','','g') --Correct
select REGEXP_REPLACE(' ','[[:alpha:]]','','g') --Wrong: output should be NULL
Definitely we can use case statement like following but I want the solution in single line without using case condition.
SELECT case when REGEXP_REPLACE('1a','[[:alpha:]]','','g') = ''
then
null
else
REGEXP_REPLACE('1a','[[:alpha:]]','','g')
end;
please, I have in Oracle table this texts (as 2 records)
"Sample text with replace parameter %1%"
"You reached 90% of your limit"
I need replace %1% with specific text from input parameter in Oracle Function. In fact, I can have more than just one replace parameters. I have also record with "Replace this %12% with real value"
This functionality I have programmed:
IF poc > 0 THEN
FOR i in 1 .. poc LOOP
p := get_param(mString => mbody);
mbody := replace(mbody,
'%' || p || '%', parameters(to_number(p, '99')));
END LOOP;
END IF;
But in this case I have problem with text number 2. This functionality trying replace "90%" also and I then I get this error:
ORA-06502: PL/SQL: numeric or value error: NULL index table key value
It's a possible to avoid try replace "90%"? Many thanks for advice.
Best regards
PS: Oracle version: 10g (OCI Version: 10.2)
Regular expressions can work here. Try the following and build them into your script.
SELECT REGEXP_REPLACE( 'Sample text with replace parameter %1%',
'\%[0-9]+\%',
'db_size' )
FROM DUAL
and
SELECT REGEXP_REPLACE( 'Sample text with replace parameter 1%',
'\%[0-9]+\%',
'db_size' )
FROM DUAL
The pattern is pretty simple; look for patterns where a '%' is followed by 1 or more numbers followed by a '%'.
The only issue here will be if you have more than one replacement to make in each string and each replacement is different. In that case you will need to loop round the string each time replacing the next parameter. To do this add the position and occurrence parameters to REGEXP_REPLACE after the replacement string, e.g.
REGEXP_REPLACE( 'Sample text with replace parameter %88888888888%','\%[0-9]+\%','db_size',0,1 )
You are getting the error because at parameters(to_number(p, '99')). Can you please check the value of p?
Also, if the p=90 then then REPLACE will not try to replace "90%". It will replace "%90%". How have you been sure that it's trying to replace "90%"?
I want to replace a LabelFor command, using the Visual Studio replace tool
From:
#Html.LabelFor(m=>m.myRecords.First().Column1)
#Html.LabelFor(m=>m.myRecords.First().M.M.Column2)
To
#Html.LabelFor(m=>m.myRecords.First().Column1, null, Model.Status)
#Html.LabelFor(m=>m.myRecords.First().M.M.Column2, null, Model.Status)
I have used "Column1" and "Column2" as examples of 2 columns which should remain unchanged after the replacement ie addition of :
, null, Model.Status)
to end of statement.
I suspect I need a regular expression to identify the last ")" and then to replace with
, null, Model.Status)
Thoughts appreciated.
Thanks.
Basically you have to match the last brace, with \)$ (globally and multiline)
Then replace with your string , null, Model.Status)
Regexr solution
I am writing a script to extract and convert SQL statements from a file. I need to convert the sql unloaded froma gupta sqlbase database into sql that SQLServer can understand.
One task is to replace keywords that are not allowed as column names with a compatible name.
In the following code $commands is an array ref that contains sql statements. (There is actually more code here, but I extracted it because it shouldn't be relevant here)
my #KeyWords = ("LEFT", "RIGHT", "PERCENT", "FILE", "PRINT", "CROSS", "PLAN", "TOP", "END", "FILE", "Default", "CHECK", "TEXT");
foreach $cmd (#$commands) {
foreach my $kw (#KeyWords) {
$cmd =~ s/\b$kw\b[^(]/_$kw/gi;
}
push #$converted, $cmd;
}
This works fine for most statements but in the following command "DEFAULT" gets replaced with "_DEFAULT instead of "_DEFAULT". So the second quotation mark is lost.
CREATE TABLE SYSADM.SUBTYPE ( ID_SUBTYPE INTEGER NOT NULL,
ID_TYPE INTEGER NOT NULL,
TYPE VARCHAR(1),
BEZEICH VARCHAR(60),
NUM_COLOR INTEGER,
NUM_TXTCOLOR INTEGER,
"DEFAULT" SMALLINT,
GENER_ARBA SMALLINT,
PROJEKTPLANUNG SMALLINT)
Is there a way to modify the regular expression/substition so this will not remove the second quotation mark? Or an other way?
[^(] matches any single character that is not a left opening paranthesis.
You want to use a negative zero-width lookahead assertion instead:
s/\b$kw\b(?!\()/_$kw/gi;
(Alternatively: (?![(]))
You can also add the replaced character back to the string:
s/\b$kw\b([^(])/_$kw$1/gi;
But note that this will not work in all cases. Especially if there is nothing after the keyword, this pattern will not match whereas zero-width assertion will.
Hi i have the following group:
`group_id` int(10) unsigned NOT NULL,
`right_id` int(10) unsigned NOT NULL,
`group__right_value` enum('allow','deny') NOT NULL DEFAULT 'deny',
KEY `group_id` (`group_id`),
KEY `right_id` (`right_id`)
And i expected the strings to always end with a comma so a did a split based on that. Now i've noticed that in some cases like above the commas should be ignored and the values left as they are:
enum('allow','deny')
How should i exclude the commas between brackets when doing the split?
EDIT:
The expected result should be:
'group_id' int(10) unsigned NOT NULL,
'right_id' int(10) unsigned NOT NULL,
'group__right_value' enum('allow','deny') NOT NULL DEFAULT 'deny',
KEY 'group_id' ('group_id'),
KEY 'right_id' ('right_id')
Matching a comma at the end of the string is done with an anchor:
/,$/m
The /m modifier is used to enable multiline mode, in which $ will match the end of the line instead of the standard end-of-subject.
http://regexr.com?3579s
Hope this help [^\,]+(\,\')?[^\,]+