sqlldr test for number format - numbers

I am loading data into Oracle 12c using sqlldr using a CTL file as below :
OPTIONS (rows=1000, bindsize=100000, readsize=100000, silent=header,feedback)
load data
CHARACTERSET UTF8
insert into table TABLEA
fields terminated by '^' optionally enclosed by ','
trailing nullcols
(
NAME,
VOLUME "decode(:VOLUME,null,0,to_number(:VOLUME,'9999999999D999'))",
TEXT
)
I am facing difficulty when the number field VOLUME defined in table as NUMBER(13,3) comes in different formats.
ABCD^1089.830^CIQ
ABCD^1,089.830^CIQ
ABCD^1.089,830^CIQ
Is there a way to load all three formats of number field in field 2 above using sqlldr ?
Expected value in the table is 1089.830 for the all three cases .
Thanks.

This is a tad ugly but it should work. It assumes your volume value data will always have 3 decimal points and the decimal symbol will be a period (based on your number format). First pass removes all region-specific characters, then second pass puts the period in 3 places from the end:
...
VOLUME decimal external "regexp_replace(regexp_replace(:VOLUME, '[\.,]', ''), '([0-9]+)([0-9]{3})', '\\1.\\2')",
...
You may not need the "decimal external", try it without and see.

Related

Copying contents of columns with Field calculator in Qgis

I have to split the content of a column into 2 differents columns using the QGIS Field Calculator. Basically, my table is something like that:
Basically I have to work with descriptio column omitting characters from 1-12 and then copy next 8 characters (in this case "AgilisSi") into the PresLACAGI column.
The other element to copy is the final number in descriptio column, ranging from 1 to 3 characters. Possibly the best is thing would be a syntax that reproduces in CodiClapa column the number after ": ", including the space in the syntax.
Thanks a lot!
Use the field calculator, check Update existing field and select column from drop down and type in the Expression window for:
PresLACAGI: substr(descriptio,12,8)
CodiClapa: right(descriptio,3)

Delete specific digit in a number using PostgreSQL

I have a column named membership_number varchar(255) in the memberships table.
Here is some sample data:
0000001234
0000002345
0000003456
membership_number must have 10 digits. If a user enters a number that has less than 10 digits, then the missing places are filled with leading zeroes accordingly.
At the moment, I have some data in this column as follows:
00001234.0
00002345.1
00003456.2
I would like to delete the decimal point which is the 2nd to the last digit and then add a leading zero to handle all of these undesired membership numbers. What would be the best way to do this?
I am aware of SUBSTRING() and its parameters but couldn't make it work so far.
Please backup your data before trying this.
Would that work?
UPDATE tablename SET membership_number = concat('0',replace(membership_number,'.','')) WHERE membership_number LIKE '%._'
Substring is not the function you want, you want a combination of REPLACE and LPAD functions:
select lpad( replace (membership_number, '.', ''), 10, '0')
from menberships;
(table name assumed) And why if it must be 10 digits do you define it as length up to 255?

Getting NULL Value in Stored Procedure TEXT Column

Below Query, I am using to get the SP definition but in TEXT column I am getting as NULL Value in IBM DATA Studio but I am able to CALL the SP.
SELECT PROCNAME, TEXT FROM SYSCAT.PROCEDURES WHERE PROCNAME LIKE '%USP_ABC%'
Please Help
You have confirmed that the syscat.procedures.language is SQL, and that your query-tool is able to display a substr() of the text.
Workaround depends on the length(text) of the row of interest:
SELECT PROCNAME, substr(TEXT,1, 1024) FROM SYSCAT.PROCEDURES WHERE PROCNAME LIKE '%USP_ABC%'
You may need to adjust the length of the substr extract depending on the length of the text and your configuration. For example substr(TEXT, 1, 2048 ) or a higher value for the length as necessary that your query-tool can cope with.
You can find the length of the text column with the LENGTH(TEXT) for the row of interest.
You can also CAST a CLOB to char or varchar to a length that fits within their limits and whatever query tool limitations you have.
Another option is to use a different query tool that can work with CLOB.
Are you using the latest version of Data Studio with the latest fix? It sounds like you might have an invalid UTF-8 character in you SP, or as you are using SUBSTR and SUBSTRING you are breaking a mulit-byte character in two.
You could try setting
-Ddb2.jcc.charsetDecoderEncoder=3
in your eclipse.ini to get Java to use a replacment character rather than replace the invalid string with nul
See this tech note
https://www-01.ibm.com/support/docview.wss?uid=swg21684365
Otherwise, do raise this with IBM Suppport

Datastage decimal separator, how can modify?

I am using datastage in order to generate a csv file with teradata source, when i modifu the job properties searching comma as a decimal separator in local categories it dosnt change, what is the correct way to do this change ?
My issues: datasource teradata, with a job action need to transfor and get out a csv file, but had more than 8 decimal files, my datastage configuration have point as a decimal separator and i need comma. In teradata more than 8 oreplaces give u back row over size error.
Solution: Get the source and cast to varchar, and with datastage trasnform used change function converting the replacing comma in place to point, and get out fields with varchar data type with correct decimal separator.

How do I format a number of arbitrary length?

If I have data that includes a numeric column with values into the miillions (eg 63254830038), and I want to format the number as a US Dollar amount (eg. $63,254,830,038), I know I can use:
SELECT numeric_column, to_char(numeric_column, '$999G999G999G999') from table
to format the values, but to do so reliably I either have to include an unnecessarily long text string ('$999G999G999G999') or know the maximum number of possible digits. Is there a way to say, broadly, "group numbers with a comma" instead of explicitly saying "group the hundreds, group the thousands, Oh! and please group the millions"?
You just need cast integer to money type.
E.g.:
tests=> select cast(63254830038 as money);
Or alternative syntax:
tests=> select 6323254830038::money;
And output (I'm from Poland, so money type take my locales and set correct currency symbol):
money
----------------------
63.254.830.038,00 zł
Monetary Types documentation.
You can try something like this (works in sql-server, not sure about postgresql)
select convert(varchar,cast('63254830038' as money),1)
You could do things the hard way using regular expressions: convert the number into a string, reverse it, use regexp_replace to insert commas between pairs of 3 digits, and then reverse it again:
select '$' || reverse(regexp_replace(
reverse(numeric_column::varchar),
E'(\\d\\d\\d)(?=\\d)', '\1,', 'g'))
Explanation
The first argument to regexp_replace is the expression to match, which contains two parts:
(\\d\\d\\d) means 3 digits, which are captured
(?=\\d) is a positive lookahead constraint of a single digit, meaning the match only counts if there is a digit following it. (That is, this digit is checked to exist, but it does not count as part of the match.)
The second argument is what to replace with: the 3 captured digits, plus a comma.
The third argument 'g' is a flag indicating that it should match and replace as many times as possible.
For more information on regular expressions in PostgreSQL, see the documentation.