I use the type xsd:dateTime for a long time und faced today a node of this type with this value
-292269055-12-02T17:47:04.192+01:00
, which I thought it was not a valid value, but when I use XML Spy 2017 to validate the value, it telle me, that it is valid.
Can someone explain me, why this value is valid or if it is a wrong implementation of XSD validation in XML Spy?
Thanks!
Dingjun
It looks strange, but it seems legal: quoting from https://www.w3.org/TR/xmlschema-2/#dateTime 3.2.7.1
The ·lexical space· of dateTime consists of finite-length sequences of characters of the form: '-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?, where
'-'? yyyy is a four-or-more digit optionally negative-signed numeral that represents the year; if more than four digits, leading zeros are prohibited, and '0000' is prohibited (see the Note above (§3.2.7); also note that a plus sign is not permitted);
So yes, a year can be negative and can be longer than 4 digits.
Related
How do I write HQL to determine if results from a field have 1st character as alpha and the following four are numeric. (i.e. - the format of the field is 'F5555', so I need to verify all the results returned from the query for this field are following the correct format.
You can try this:
select REGEXP_EXTRACT( 'd55555' , '^[A-Za-z ]?[0-9]{5}$', 0);
Now, in order to understand, please read this and see the next comments:
^ means the beginning of the string(in this mode we mark the beginning);
[A-Za-z] - means any letter: upper or lower case;
? - means that we want only 1 occurrence of the previous character class;
[0-9] - any digit from 0 to 9;
{5} - means that the previous character class ([0-9]) must appear 5 times exactly (no more, no less);
$ - end of the string;
Hope that you understood.
I'm using Visual FoxPro and I need to convert currency amount into numeric. The 2 columns in the table are tranamt(numeric,12,2) and tranamt2(character)
Here's my example:
tranamt2=-$710,000.99
I've tried
replace all tranamt with val(tranamt2)
and
replace all tranamt with val(strtran(tranamt2, ",",""))
both results give me zero. I know it has something to do with the negative sign but I can't figure it out. Any help is appreciated.
Try this:
replace all tranamt with VAL(STRTRAN(STRTRAN(tranamt2, "$", ""), ",", ""))
This removes the dollar sign and comma in one shot.
need to convert currency amount into numeric
tranamt(numeric,12,2) and tranamt2(character)
First of all a neither a Character Field Type nor a Numeric Field type (tranamt2) are Not a VFP Currency Field type
You may be using the value of a Character field to represent currency, but that does not make it a currency value - just a String value.
And typically when that is done, you do NOT store the Dollar Sign '$' and Comma ',' as part of the data.
Instead, you store the 'raw' value (in this case: "-710000.99") and merely format how that 'raw' value is displayed when needed.
So in your Character field you have a value of: -$710,000.99
Do you have the Dollar Sign '$' and the Comma ',' as part of the field data?
If so, to convert it to a Numeric, you will first have to eliminate those extraneous characters prior to the the conversion.
If they are not stored as part of your field value, then you can use the VAL() 'as is'.
Example:
cStr = "-710000.99" && The '$' and ',' are NOT stored as part of Character value
nStr = VAL(cStr)
?nStr
However if you have the Dollar Sign and the Comma as part of the field data itself, then you can use STRTRAN() to eliminate them during the conversion.
Example:
cStr = "-$710,000.99" && Note both '$' and ',' are part of data value
* --- Remove both '$' and ',' and convert with VAL() ---
nStr = VAL(STRTRAN(STRTRAN(cStr,",",""),"$",""))
?nStr
Maybe something like:
REPLACE tranamt WITH VAL(STRTRAN(STRTRAN(tranamt2,",",""),"$",""))
EDIT: Another alternative would be to use CHRTRAN() to remove the '$' and ','
Something like:
cRemoveChar = "$," && Characters to be removed from String
REPLACE tranamt WITH VAL(CHRTRAN(tranamt2,cRemoveChar,""))
Good Luck
A little late but I use this function call
function MoneyToDecimal
LPARAMETER tnAmount
LOCAL lnAmount
IF VARTYPE(tnAmount) = "Y"
lnAmount = VAL(STRTRAN(TRANSFORM(tnAmount), "$", ""))
ELSE
lnAmount = tnAmount
ENDIF
return lnAmount
endfunc
And can be tested with these calls:
wait wind MoneyToDecimal($112.50)
wait wind MoneyToDecimal($-112.50)
Use the built-in MTON() function to convert a currency value into a numeric value:
replace all tranamt with mton(tranamt2)
I'm building a string in oracle, where I get a number from a column and make it a 12 digit number with the LPad function, so the length of it is 12 now.
Example: LPad(nProjectNr,12,'0') and I get 000123856812 (for example).
Now I want to split this string in parts of 3 digit with a "\" as prefix, so that the result will look like this \000\123\856\812.
How can I archive this in a select statement, what function can accomplish this?
Assuming strings of 12 digits, regexp_replace could be a way:
select regexp_replace('000123856812', '(.{3})', '\\\1') from dual
The regexp matches sequences of 3 characters and adds a \ as a prefix
It is much easier to do this using TO_CHAR(number) with the proper format model. Suppose we use \ as the thousands separator.... (alas we can't start a format model with a thousands separator - not allowed in TO_CHAR - so we still need to concatenate a \ to the left):
See also edit below
select 123856812 as n,
'\' || to_char(123856812, 'FM000G000G000G000', 'nls_numeric_characters=.\') as str
from dual
;
N STR
--------- ----------------
123856812 \000\123\856\812
Without the FM format model modifier, TO_CHAR will add a leading space (placeholder for the sign, plus or minus). FM means "shortest possible string representation consistent with the model provided" - that is, in this case, no leading space.
Edit - it just crossed my mind that we can exploit TO_CHAR() even further and not need to concatenate the first \. The thousands separator, G, may not be the first character of the string, but the currency symbol, placeholder L, can!
select 123856812 as n,
to_char(123856812, 'FML000G000G000G000',
'nls_numeric_characters=.\, nls_currency=\') as str
from dual
;
SUBSTR returns a substring of a string passed as the first argument. You can specify where the substring starts and how many characters it should be.
Try
SELECT '\'||SUBSTR('000123856812', 1,3)||'\'||SUBSTR('000123856812', 4,3)||'\'||SUBSTR('000123856812', 7,3)||'\'||SUBSTR('000123856812', 10,3) FROM dual;
I have a timestamp
timestamp = 1466754627
And I want to assert that the first 4 characters are 1466 within a test. If i was to use
timestamp.includes('1466')
This will pass, but 1466 could appear anywhere and not necessarily the first 4 characters. How could i ensure that 1466 are the first 4 characters ?
Thanks
There's a start_with matcher:
expect('1466754627').to start_with('1466')
You might have to convert timestamp to a string via to_s if it is indeed an integer:
timestamp = 1466754627
expect(timestamp.to_s).to start_with('1466')
I'm trying to put MQMD.MsgId to XMLNSC.MsgId field, like this:
SET OutputRoot.XMLNSC.Root.MsgId = InputRoot.MQMD.MsgId;
But I'm getting X'414d51204d39392e5352442e4330302e56c47bd4203b3708' instead of just 414d51204d39392e5352442e4330302e56c47bd4203b3708.
Also i've tried to cast MsgId to CHARACTER, but result is the same.
How to get rid of quotes and 'X'?
I don't have enough reputation to 'add a commment' yet, but working with so many languages, I've learned to dislike SUBSTRING and LENGTH type functions. In the case of answer 'Feb 28 2016 at 10:41' above (yes I found this answer in response to my own search - for the "CAST(InputRoot.MQMD.MsgId AS CHAR)" above, I chose to use this instead:
DECLARE MsgId CHAR RIGHT(LEFT(CAST(InputRoot.MQMD.MsgId AS CHAR),50),48);
This assumes MsgId is always 24 hex pairs long (24x2=48) and goes for LEFT 50 first (taking off the last single quote), then RIGHT 48 (taking off the first X char and the first single quote). Does anyone disagree with the assumption? It also has the bonus of condensing to one line as it's not necessary to have two references to "MsgId" in 'SUBSTRING'
You could try something like this:
DECLARE msgId CHARACTER CAST(InputRoot.MQMD.MsgId AS CHARACTER);
SET OutputRoot.XMLNSC.Root.MsgId = SUBSTRING(msgId FROM 3 FOR LENGTH(msgId) - 3);
With ESQL SUBSTRING you can also use BEFORE and AFTER
DECLARE MsgIdAsChar CHAR SUBSTRING(SUBSTRING(CAST(InputRoot.MQMD.MsgId AS CHAR) AFTER '''') BEFORE '''');
BEFORE and AFTER are also extremely handy when it comes to looking for things in strings.
DECLARE TheHaystack CHAR ‘Where a value is 99 out of a maximum value of 100);
DECLARE TheValue CHAR SUBSTRING(SUBSTRING(TheHaystack AFTER 'value is ') BEFORE ' ');