Oracle SQL Search for or find character by its ascii value -


my challenge find characters across multiple tables.

at work db set keep date values in columns named d_date, d_inserteby_id, d_valid_to etc. underscore reserved char in sql right, straight forward '%d_%' wont work.

so when im looking rows containing reference date have bit more creative '%d_%'

i know can: select * table t upper(t.column) '%d_%' escape '\'

but how search d , underscore using ascii value?

you can't search column name in table it's part of, have @ data dictionary , use dynamic sql if schema changes frequently.

you can ...

select table_name,        column_name   all_tab_columns  owner = ? -- insert name of table owner ,    upper(column_name) 'd\_%' escape '\' 

there's no advantage using ascii value of d in search -- obfuscate code. , escape correct approach.

using mixed-case object names considered bad practice in oracle, way.

edit: of course if wanted search strings ascii characters you'd like:

where ascii(substr('d_123',1,1))=68 ,       ascii(substr('d_123',2,1))=95 

or

where ascii(substr('d_123',1,1))||ascii(substr('d_123',2,1))='6895' 

or

where substr(dump(substr('d_123',1,2)),-6) = ' 68,95' 

as ever, lots of ways things wrong way.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -