I want to find/replace a character/pattern ONLY inside SQL comments ( single line comments — and block comments /* */). The source string is an SQL script.
At the moment I am searching for a semi-colon (;) within comments and want to replace it with blank space.
Source
CREATE OR REPLACE PROCEDURE TESTDBA.PROC_REUSING_BINDED_VAR_N_DSQL
AS
a NUMBER:=2;
b NUMBER:=3; -- jladjfljaf; lakjflajf
-- alksdjflkjaf ladkjf
v_plsql_tx VARCHAR2(2000);
begin
v_plsql_tx := 'BEGIN ' || ' :1 := :1 + :2; ' || 'END;';
execute immediate v_plsql_tx
using in out a, b;
insert into testdba.NEW_TESTING_TABLE(CHARACTER_VALUE) VALUES('a='||a);
end PROC_REUSING_BINDED_VAR_N_DSQL;
-- lajdflajf
/*lakjdfljalfdk; alkdjf*/
/*asdf
;
asdfa*/
/*
adf
asd asdf
*/
Can you please suggest something.
Thanks
I would do this like this :
The above will give you all comments without ‘;’. Then I would iterate line by line through the sql file and when I encountered a line which had a comment I would check to see if that line is in my list of matches – if not then I would search replace ; with ‘ ‘ in the whole comment. Of course you will have to find where the comment ends but this is easy — ends in the same line and /* and when the first */ is found. This way you can change any number of ; with the same code.