How to trim non-numeric characters with APEX transformation - oracle-apex

During importing a CSV file I want to transform one column with money values so that it will insert them into database without problem.
I have values such as "134,245.99 RUB" and the output should be "134,245.99" or "134245.99" at best.
I tried doing it using transformation but there is no documentation (sic!) on that subject from Oracle how to use it.
Do you have any ideas?

#tweant: You can use regexp_replace function and do this easily. Here's an example:
select trim(regexp_replace(' 2345abc ','\D*$','')) as str from dual;
This will remove all the non digit characters from the end and trim the white spaces.
More information about the function here.

Related

Grok custom pattern for space delimited file

I'm trying to load a file to structured table in Athena. I am using GROK pattern to load it to the table but not able to find the correct pattern. The file format is as below:
L1127 ACTUALS 214171 ON 27649075 -00000000000000000409618.02 601 MBS DAILY VISION - CAN OS
L1127 ACTUALS 412821 ON 27649075 002060 -00000000000000000002657.33 521 MBS DAILY VISION - CAN OS
GROK pattern I'm using:
(?<BusinessUnit>.{5})%{SPACE}(?<Type>.{7})%{SPACE}(?<PSGLAccountNumber>.{6})%{SPACE}(?<Province>.{2})%{SPACE}(?<DepartmentId>.{8})%{SPACE}(?<ProductId>.{6})%{SPACE}(?<Amount>.{27})%{SPACE}(?<TransCode>.{3})%{SPACE}(?<Feed>.{35})
I'm having trouble when the ProductId has no value.
Any help would be appreciated.
(?<ProductId>.{6})%{SPACE} means that you expect the ProductId field to be exactly six characters followed by any number of spaces. From the data you posted it seems to me that what should happen is that in the first row ProductId would end up as six spaces.
If the problem is that it becomes six spaces and you want it to be an empty string, you could for example use (?<ProductId>\S*)%{SPACE} (\S* matches zero or more non-space characters).
If this does not solve your problem, perhaps you could describe in some more detail what trouble you are having, and what you want to happen?
Update: in a comment you indicated that the problem with this solution is that the ProductId column becomes "-00000". The reason for that is that the %{SPACE} pattern before (?ProductId… consumes all the spaces between the DepartmentId and Account fields. To solve this you could for example limit the number of spaces that can appear between the DepartmentId and ProductId fields. In the example data you post there are two spaces, and since the fields are fixed-width I assume this is always the case. Using a pattern like …(?<DepartmentId>.{8})\s{2}(?<ProductId>\S*)%{SPACE}(?<Amount>.{27})… should fix the problem.
I was able to make it work using the below pattern below
%{WORD:BusinessUnit}%{SPACE}%{WORD:Type}%{SPACE}%{POSINT:PSGLAccountNumber}%{SPACE}%{WORD:Province}%{SPACE}%{POSINT:DepartmentId}%{SPACE}%{custompat:ProductId}%{SPACE}%{NUMBER:Amount}%{SPACE}%{NUMBER:TransCode}%{SPACE}(?<Feed>[A-Za-z0-9\-\s]{26})
And using custom pattern:
custompat ([0-9]{6}|\s{6})

Select field with Hyphen in Redshift Spectrum

I am trying to extract a nested field with an Hyphen in the name through Redshift Spectrum
SELECT mystruct.mysubstruct.my-field.id
FROM my_external_schema.my_table
I see in other DBMS is suggested to wrap the field name with double quotes:
"mystruct.mysubstruct.my-field.id"
or back ticks
`mystruct.mysubstruct.my-field.id`
but none of these worked for me.
Any suggesitons?
Since the double quotes permit to escape the special characters, doing "mystruct.mysubstruct.my-field.id" means that you are looking for the column named 'mystruct.mysubstruct.my-field.id' at top level and not as the nested column, because the dot is not used to extract the field.
What you have to do is
SELECT mystruct.mysubstruct."my-field".id
FROM my_external_schema.my_table

Sublime Regex Search and Replace

Trying to use Sublime to update the urls of only some lines in a sql table dump.
in this case the line that I need to single out has the string 'themo_showcase_\d_image' which is easy to match. In the same string what I actually need to replace is the url column so that it reads 'https://www.example.com/' to 'http://www.example.com'
Anyone able to help shed some light on this? I've got thousands of these insert records that I need to modify.
ex:
original string:
('8630', '1328', 'themo_showcase_1_image', 'https://www.example.com/'),
to:
('8630', '1328', 'themo_showcase_1_image', 'http://www.example.com/'),
Find: 'themo_showcase_\d_image', 'http\Ks you could use \d+ if there are more than 1 digit
Replace: LEAVE EMPTY

Trimming text from a multi-line entry in postgres with regex

I have a column "verbatim" where each entry contains multiple lines. Here's an example:
Dummy field1:Text
Tell Us More:Text to capture
Dummy field2:Text
I'd like to capture only Text to capture text in the second line Tell Us More: and put that value into the column verbatim_scrubbed. In the example above, Text to capture would be the entry in verbatim_scrubbed.
I'm not that great with postgres and regexp, so I was hoping somebody could help me out here. Was thinking of something similar to the following:
update TABLE
set verbatim_trimmed = array_to_string(regexp_matches(verbatim,'tell us more:(.*)','gi'));
This doesn't work, but I have a feeling something similar may work.
Perhaps there is a direct way to capture the: Text to capture without the cariage return \r and the new line \n charracters (without using the regexp_replace).
Here is what you can do:
select regexp_replace(array_to_string(regexp_matches(verbatim, '^Tell Us More:(.*)$','n'),'',''), E'[\\r\\n]', '' ) from my_table;

replace headings in a word document

I am looking for a macro or way to replace all headings in a word document with one numeric value so that every heading at every level gets replaced with same numeric value.
Can anyone help?
It came out to be easy.
Use { SEQ heading } field. Copy the field code, select the destination format in Find and use ^c^p in replace. All headings with selected style will get the numeric value. Do the same for rest.