Nonsense d3 pick syntax error - pick

I made the following queries in d3 and got the following results:
:list product-master with qoh > 99 and with categ eni
[401] no items present.
:list product-master with qoh > 9 and with categ eni
[4] syntax error
Why does the query with the 99 parse, while the query with the 9 generates a syntax error?

The default MD has an item called '9', rather than regarding that value as a literal, it's seeing a definition after the ">", which isn't legal. If you put your literals in quotes it'll work for you.
Similarly, your reference to eni is ambiguous. Do you intend to find a category = "eni", or are you searching for any item that has a non-null category, with a display of the field called ENI? Quotes eliminate all of this ambiguity.
Please flag this as an Answer after you've verified it. Thanks.

Related

oracle add column with value based on condition

I would like to add a column "tag" based on value of "LEASE_ID_count" with ORACLE.
But i get this error :
value too large for column "CUSTOM_LIFETIME_VALUE_TAG"."tag" (actual:
7, maximum: 3) , caused by: OracleDatabaseException: ORA-12899: value
too large for column "CUSTOM_LIFETIME_VALUE_TAG"."tag" (actual: 7,
maximum: 3
select "COMPANY_CODE", "LEASE_ID_count",
(CASE WHEN "LEASE_ID_count" IN ('3','4', '5') THEN '3 à 5vh' WHEN "LEASE_ID_count" ='1' THEN '1vh' WHEN "LEASE_ID_count" ='2' THEN '2vh' END) "tag"
from "CUSTOM_LIFETIME_VALUE_TESR"
Any idea please to help me ? thanks
This is too long for a comment. The error message is referring to "CUSTOM_LIFETIME_VALUE_TAG"."tag". This is from a table that has no obvious reference in the query. Okay, perhaps CUSTOM_LIFETIME_VALUE_TESR is a view that references that table. That is possible.
However, the error message is about storing data into that column, not referencing it. So, my best guess is that you have a query like this:
INSERT INTO CUSTOM_LIFETIME_VALUE_TAG (COMPANY_CODE, LEASE_ID_count, tag)
<your select here>;
And the column tag in this table is defined as 3 characters. Clearly, '3 à 5vh' has 7 characters which is more than 3 which causes an error. Hence the error.
Oracle does have a lot of functionality lurking around. Even so, it is hard for me to think of how a SELECT could cause this error with no DML involved.
As Alex Poole very correctly notes: write the queries without double quotes. Quoted identifiers just make queries harder to write and read.

ORACLE: "Missing right parenthesis" error when using variables

I have a very long Oracle SQL script that filters for article numbers in multiple places, i.e.:
[...]
where article_nr = 12345
[...]
To avoid adjusting 20 lines of code manually when changing the article, I introduced variables, i.e.:
define article_1 = 12345
[...]
where article_nr = &&article_1
[...]
Now, however, I get an error saying that it's "missing right parenthesis". I did not touch anything regarding a parenthesis, just replaced the 12345 by the variable.
Do I have to escape the "&&" somehow?
Sorry for not posting the full code, but its multiple nested selects.
Thanks
EDIT (Working example):
This works:
select * from stores
where
(opening_date >= '21.11.2016')
;
This DOESN'T works (either with one or with two "&"):
define opening = '21.11.2016'
select * from stores
where
(opening_date >= &&opening)
;
==> "missing right parenthesis"
Numeric literals do not require quote marks ...
where article_nr = 12345
but date (and string) literals do ...
(opening_date >= '21.11.2016')
The same rules apply for substitution variables. Numeric assignment:
where article_nr = &&article_1
Date assignment:
(opening_date >= '&&opening')
As others have commented, it's good practice to explicitly cast dates:
(opening_date >= to_date('&&opening', 'dd.mm.yyyy'))

Returning postcodes (varchars) with only one numeric character in them

I've been asked to run a query to return a list of UK post codes from a table full of filters for email reports which only have 1 number at the end. The problem is that UK post codes are of variable length; some are structured 'AA#' or 'AA##' and some are structured 'A#' or 'A##'. I only want those that are either 'AA#' or 'A#'.
I tried running the below SQL, using length and (attempting to) use regex to filter out all results which didn't match what I wanted, but I'm very new to using ranges and it hasn't worked.
SELECT PostCode
FROM ReportFilterTable RFT
WHERE RFT.FilterType = 'Postcode'
AND LEN(RFT.Postcode) < 4
AND RFT.PostCode LIKE '%[0-9]'
I think the way I'm approaching this is flawed, but I'm clueless as to a better way. Could anyone help me out?
Thanks!
EDIT:
Since I helpfully didn't include any example data originally, I've now done so below.
This is a sample of the kind of values in the column I'm returning, with examples of what I need to return and what I don't.
B1 -- Should be returned
B10 -- Should not be returned
B2 -- Should be returned
B20 -- Should not be returned
B3 -- Should be returned
B30 -- Should not be returned
SE1 -- Should be returned
SE10 -- Should not be returned
You could filter for one or two letters (and omit the length check, since it's implicit in the LIKE):
WHERE RFT.FilterType = 'Postcode' AND
(RFT.PostCode LIKE '[A-Z][0-9]' OR RFT.PostCode LIKE '[A-Z][A-Z][0-9]')
If the issue is that you are getting values with multiple digits and you are using SQL Server (as suggested by the syntax), then you can do:
WHERE RFT.FilterType = 'Postcode' AND
LEN(RFT.Postcode) < 4 AND
(RFT.PostCode LIKE '%[0-9]' AND RFT.PostCode NOT LIKE '%[0-9][0-9]')
Or, if you know there are at least two characters, you could use:
WHERE RFT.FilterType = 'Postcode' AND
LEN(RFT.Postcode) < 4 AND
RFT.PostCode LIKE '%[^0-9][0-9]'
Non-digit followed by 1 digit ... LIKE '%[^0-9][0-9]'

Using the Continuation character in a DEFINE statement in Oracle SQL Developer

I have the following code in which I'm using a variable to pass a list of values to multiple SQL statements (I can't save in a table as I don't have authority and don't want to have to maintain the list in all of the various SQL sections).
It works fine as long as all of the values are on a single line... but as I have so many values; I'd like to split it into multiple lines and use the Continuation Character '-'.
I'm running Oracle SQL Developer 2.1.1.64 against Oracle 10g (I also tried this in PL/SQL Developer and it failed there as well)
--=========================================
define subclasses = ('10-1010-10','10-1010-15','10-1010-20', -
'10-1010-25','10-1010-30') --- there are another 60 values...
select item from item_master where ((subclass) in &&subclasses);
Select Price from Item_prices where ((subclass) in &&subclasses);
--=========================================
I get the following error
ORA-01722: invalid number
01722. 00000 - "invalid number"
as it is parsing the code as
select item from item_master where ((subclass) in ('10-1010-10','10-1010-15',
'10-1010-20', -'10-1010-25','10-1010-30'))
...keeping the continuation code '-' in the SQL....tho it DOES go to the 2nd line of values.
If I remove the '-' ... it only processes the values on the first line and parses as
select item from item_master where ((subclass) in ('10-1010-10','10-1010-15','10-1010-20', )
... losing the second to nth line of values (and throwing errors as it ends w/ ',' and doesn't have the final ')'). How do I fix this?
You could do this:
column subc new_value subclasses
select q'[('10-1010-10','10-1010-15','10-1010-20',
'10-1010-25','10-1010-30')]' as subc
from dual;
Now &subclasses. will contain all the codes.
NB I used the q'[...]' quote syntax to avoid have to double up all the quotes in the data.
I noticed that you are trying to substitute a list of string variables into the select statement. You should rewrite your define statement to make it a single list of strings like this:
define subclasses = '''10-1010-10'',''10-1010-15'',''10-1010-20'', -
''10-1010-25'',''10-1010-30'''; --- there are another 60 values...
The - should be fine as a continuation character (see Oracle documentation here).
Now, when you execute your select statements you need to edit the WHERE clause so they are formatted so it will plug those values directly in there as written:
Select item from item_master where subclass in (&subclasses);
Select Price from Item_prices where subclass in (&subclasses);
This will end up being interpreted as if you had written:
Select item from item_master
where subclass in ('10-1010-10','10-1010-15','10-1010-20', '10-1010-25','10-1010-30');
If you have a lot of values though, you might run into limitations for substitution variables if you are using SQL*Plus (i.e. limited to 240 bytes per variable). In that case, you can either split the variables into multiple variables and concatenate them in the SELECT, or if you are in a PL/SQL environment, you can create variables that will hold the larger data size.

vfp query like command not working

SELECT iif( LIKE(sol,'EM06%'), "other",sol) as solGroup;
FROM dpgift GROUP BY solGroup
The above should give me a column containing unique sol values. In addition, any sol value starting with EM06 should be grouped into "other". It doesn't work though, instead it returns the following.
Solgroup
DM081
EM061
EM081
EM100
EM101
EM105
EM111
TM081
Can anyone see what i'm doing wrong here? the 2nd and 3rd line should be called "other".
I've used this like command many times and it's never done this before. I can't see anything wrong with the syntax and I've tried other variations without success. I've even tried casting in case a certain field type doesn't work but the result is always the same.
edit: using a '*' and putting the wildcard string as the first parameter works. I've actually been making this mistake for a while in the following manner:
iif( (LIKE("4%",sol) OR sol = "4"),"8M","other");
The like does nothing here but i hadn't noticed since the '=' operator returns true if sol starts with '4' (can someone link me a reference to '=' behavior?). The reason i included the sol = "4" is because i assumed % meant one or more char rather than 0 or more.
Anyway, i've gone back and changed all my code to iif(like("wtvr*",string),stringtrue,stringfalse)
I imagine using '=' to compare strings is not recommended since it doesn't seem to be mentioned in the msdn library.
another alternative is to use "$", AT() or ATC()
"$" means if the left side is found ANYWHERE in the right side...
iif( "EM06" $ sol, "other", sol )
AT() is to compare if a string is found in another, but IS CASE-SENSITIVE, returns the character position found in the string (VFP is 1-based, not zero-based)
iif( at( "EM06", sol ) > 0, "other", sol )
or
ATC() -- same as AT(), but is NOT case-sensitive.
If you specifically want the "EM06" to be at the start of the string, you could even just do a LEFT() comparison
iif( left( sol, 4 ) = "EM06", "other", sol )
or even
iif( ATC( "EM06", sol ) = 1, "other", sol )
and yes, these are all valid within SQL-Select..