GROUP BY syntax is causing "missing expression" error - sql

Please explain why the following query:
select in.status as "no_installments"
, count(in.id) as "installment"
FROM instalsched.instalment in
GROUP BY in.status;
returns
ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:
Error at Line: 1 Column: 12

in is a key word in SQL. It is used as part of a where clause, such as where person_id in (1,2,3,4). To remedy, simply change the alias.
select
in1.status as "no_installments",
count(in1.id) as "installment"
FROM instalsched.instalment in1
GROUP BY in1.status;

in is a keyword. Use a different alias or wrap it in double quotes.

"in" is a reserved word in SQL syntax. You should try to use other non-reserved word like "inst" or something similar.

Related

SQL Error: ORA-00917: missing comma 00917. 00000 - "missing comma" *Cause: *Action:

I'm trying to add a new row to a Products table with this:
INSERT INTO Products_mgs( product_id,category_id,product_code,product_name,
description,list_price,discount_percent,date_added)
VALUES ( 11, 4,'YDP162R','Yamaha Arius YDP162R Traditional Console Style Digital Piano',
'The best keyboard on the market. Offers excellent sound rendering
that truly separates it from the rest of the pack.',1599.99,10,'2020-10-25'()));
but I keep getting this error message:
Error at Command Line : 23 Column : 77 Error report - SQL Error:
ORA-00917: missing comma
00917. 00000 - "missing comma"
*Cause:
*Action:
There are extra parentheses at the end of the statement that make no sense. I would also recommend using an explicit literal date for column date_added rather than relying on implicit conversion (assuming, of course, that this column is of date datatype).
So:
INSERT INTO Products_mgs (
product_id,
category_id,
product_code,
product_name,
description,
list_price,
discount_percent,
date_added
) VALUES (
11,
4,
'YDP162R',
'Yamaha Arius YDP162R Traditional Console Style Digital Piano',
'The best keyboard on the market. Offers excellent sound rendering that truly separates it from the rest of the pack.',
1599.99,
10,
DATE '2020-10-25' --> literal date
); -- trailing parentheses removed

hive equivalent of group concatenation

what is the wrong with this hive query ..trying to do group concatenation
select ID,source_sys, group_concat(Quote||'_'||Quote_size::Integer||'#'||price::Numeric(30,4)
||'_'||quote2_size::Integer||'#'||quote2_price::Numeric(30,4),'|') as quotes from xyz_table
I am getting the following error
Analysis Exception: Syntax error on line 2:undefined: ...Quote||'_'||Quote_size::Integer||'#'||price ... ^Encountered::Expected: ADD,ALTER .....
Syntax error
in group_concat just use comma.. I believe only in oracle they use || for concatenation.
select group_concat(Quote,'_',Quote_size::Int,..) from yourtable
See more examples here https://docs.cloudera.com/documentation/enterprise/5-5-x/topics/impala_group_concat.html

Missing Keyword when trying to Select into

So I have a function to return an Average of a column such as
CREATE OR REPLACE FUNCTION avgCol
RETURN DEC IS avgNum DEC;
BEGIN
SELECT AVG(myCol)
INTO avgNum
FROM MyTable;
RETURN avgNum;
END;
/
While trying to test the results, i have the following
SELECT avgCol
INTO RESULT
FROM DUAL;
but it gives me the error
ORA-00905: missing keyword
00905. 00000 - "missing keyword"
*Cause:
*Action:
Error at Line: 175 Column: 6
Where line 175 is INTO RESULT. As far as I know, this is a scalar function and I'm trying to return a signal variable so it should work right? What keyword am I missing here?
Also I know I can just use AVG(), but I am learning how to create a scalar function. this is strictly for learning purposes.
While testing your code (which should be ok), you need
SELECT avgCol AS result FROM DUAL;
'INTO' assigns the result value to a PL/SQL variable; 'AS' creates an alias/name for a SQL SELECT (not PL/SQL) result column/field.

Error on query with "Replace"

I Have an error on a oracle server but I don't understand why is not work.
I use the software oracle sql developer.
The query is:
SELECT * FROM TestView WHERE REPLACE(TestView.Row2, '.', ',') > 0 ;
The value who is in TestVue.Row2 : '46.08','-46.47','1084.05','66500',...
"TestView" is a view who check to return a row without empty value
When I Execute the query I have always an error who says:
ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause:
*Action:
Thanks for your help
Zoners
You have a row in your table, which cannot be parsed into number format. Most likely it is a blank column.
SELECT * FROM TestVue WHERE TestVue.Row2 IS NULL ;
Use a NVL Function to avoid errors caused by null field and a TO_NUMBER function to cast into a number before comparision with zero
SELECT * FROM TestView WHERE TO_NUMBER(REPLACE(NVL(TestView.Row2,'0'), '.', ',')) > 0 ;
You should be able to find the row with something like:
select Row2
from TestVuw
where length(trim(translate(Row2, '+-.,0123456789', ' '))) = 0
Of course, this allows multiple +, -, ., and ,. It can be further refined using a regular expression, but this usually works to find the bad ones.

Assistance with SQL View

I'm having a little trouble with this sql view.
CREATE OR REPLACE VIEW view_themed_booking AS
SELECT tb.*,
CASE
WHEN (tb.themed_party_size % 2) = 0 THEN
(tb.themed_party_size-2)/2
ELSE ((tb.themed_party_size-2)/2) + 0.5
END themed_tables
FROM themed_booking tb;
Can anyone help me here? I'm trying to add a column to the end of the view that the natural number result of (S-2)/2 where S is the themed_party_size.
When i say natural number result i mean like round up the answers that end in .5 so if S=7 the answer would be 3 and not 2.5.
The error I get when I try and run the above code is
Error starting at line 1 in command:
CREATE OR REPLACE VIEW view_themed_booking AS
SELECT tb.*,
CASE WHEN (tb.themed_party_size % 2) = 0
THEN (tb.themed_party_size-2)/2
ELSE ((tb.themed_party_size-2)/2) + 0.5
END themed_tables
FROM themed_booking tb
Error at Command Line:3 Column:34
Error report:
SQL Error: ORA-00911: invalid character
00911. 00000 - "invalid character"
*Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
*Action:
If it makes a difference I am using sqldeveloper connected to an oracle server so I can use PL/SQL.
The error message is telling you what the problem is.
Look at Line:3 Column:34
It is an invalid character
CREATE OR REPLACE VIEW view_themed_booking AS
SELECT tb.*,
CASE WHEN (tb.themed_party_size % 2) = 0
^
My suspicion is that you are trying to use the modulo operator.
Since you are using oracle PL/SQL, you should use mod
Here is a reference Oracle/PLSQL: Mod Function
I think you can simplify with the CEIL() or ROUND() function:
CREATE OR REPLACE VIEW view_themed_booking AS
SELECT tb.*,
ROUND((tb.themed_party_size-2)/2) AS themed_tables
FROM themed_booking tb;
Not sure why you get that error. Perhaps it's the % operator that is not available in Oracle. This links suggests so: Fundamentals of PL/SQL. There seems to be a MOD() function though.