I am trying to run a query for liquibase update and I have a PLSQL block in there, the block has over 500 lines so I only post a few lines where the error is happening for now.
BEGIN
IF NOT EXISTS(select 1 from "public"."eod_report" where "id" = NEW."id") THEN
-- LOADING STRUCTURE SECTION
select "id" into NEW.organization_unit_id from organization_unit where site_id = NEW.organization_unit_id;
orgUnitId := CAST(NEW.organization_unit_id as int8);
--INSERT
IF (NEW.transactions_count is NULL) THEN
NEW.transactions_count := 0;
END IF;
IF (NEW.total_sales is NULL) THEN
NEW.total_sales := 0;
END IF;
INSERT INTO "public"."eod_report"("id",batch,total_sales,transactions_count,organization_unit_id,pos_total_sales,pos_transactions_count,pos_total_points,total_points,transaction_date)
VALUES (NEW."id",NEW.batch,NEW.total_sales,NEW.transactions_count,orgUnitId,NEW.pos_total_sales,NEW.pos_transactions_count,NEW.pos_total_points,NEW.total_points,NEW.transaction_date);
-- updates delay transaction or each batch
select max(id) into lastEodId from "public"."transaction" where transaction_type = 4 and org_unit_id = orgUnitId and id < ;NEW."id";
for eodRow IN
select count(case when transaction_type = 3 then -1 else 1 end) as trCount,sum(case when report_prefix = true then points else -points end) as ptSum,sum(case when report_prefix = true then amount else -amount end) as trSum, batch as trBatch from "public"."transaction"
where id > ;lastEodId and id < ;NEW."id" and report_prefix is not null and org_unit_id = orgUnitId
and batch < ;NEW.batch group by batch
LOOP
UPDATE "public"."eod_report" SET delayed_points =
(delayed_points + eodRow.ptSum),former_delayed_sales =
END LOOP;
END IF;
RETURN NULL;
And I am getting this error when I try to execute the query:
ERROR:
syntax error at or near ";"
LINE 453: ..._type = 4 and org_unit_id = orgUnitId and id < ;NEW."id";
^
SQL state: 42601
Character: 15018
there is a screenshot where the error is highlighted
Looks like the < and > chars are replaced with < ; so the syntax is incorrect.
fix the SQL by replacing all < ; with < to have
... org_unit_id = orgUnitId and id < NEW."id";
Also > ; must be replaced with >
It could happens e.g. because of URL encoding of text sent from UI (browser)
You find the same problem in multiple parts of your query, because HTML entities like "< ;" and "> ;" are not legal in an SQL query, which the error points to. You should change them to "<" and ">" accordingly.
Related
so i want to calculate a sum of a field using adoquery and case statement in delphi ;
the code i use is this :
DataModule2.ADOQuery1_630.sql.clear;
DataModule2.ADOQuery1_630.sql.Add('select STATUT,case when month(DATE_PAI)=1 then sum(MT) else 0 end AS m');
DataModule2.ADOQuery1_630.sql.Add('from table');
DataModule2.ADOQuery1_630.sql.Add('where STATUT in( :dd ,:df) and TYPE_QUIT = :l ');
DataModule2.ADOQuery1_630.sql.Add('group by STATUT');
DataModule2.ADOQuery1_630.Parameters.ParamByName('dd').Value:=pm;
DataModule2.ADOQuery1_630.Parameters.ParamByName('df').Value:=pp;
DataModule2.ADOQuery1_630.Parameters.ParamByName('l').Value:=typeQ;
DataModule2.ADOQuery1_630.prepared := true;
DataModule2.ADOQuery1_630.open;
but i gest an error message :
syntax error operator absent in the expression case when
month(DATE_PAI)=1 then sum(MT) else 0 end
can any one help me please
Try to do :
(group SELECT and FROM in the same DataModule2.ADOQuery1_630.sql.Add())
DataModule2.ADOQuery1_630.sql.clear;
DataModule2.ADOQuery1_630.sql.Add('SELECT STATUT, SUM(case when month(DATE_PAI)=1 then MT ELSE 0 END) AS m FROM table');
DataModule2.ADOQuery1_630.sql.Add('WHERE STATUT in(:dd,:df) and TYPE_QUIT=:l');
DataModule2.ADOQuery1_630.sql.Add('GROUP BY STATUT');
//...
SELECT CASE (SELECT Count(1)
FROM wf_item_activity_statuses_v t
WHERE t.activity_label IN ('WAITING_DISB_REQ',
'LOG_DDE',
'LOG_SENDBACK_DDE')
AND t.item_key IN(
SELECT r.i_item_key
FROM wf_t_item_xref r
WHERE r.sz_appl_uniqueid = '20400000988')
)
WHEN 0 THEN
(
delete
from t_col_val_document_uploaded p
WHERE p.sz_application_no = '20400000988'
AND p.sz_collateral_id = 'PROP000000000PRO1701'
AND p.i_item_key = '648197'
AND p.i_document_srno = '27' )
WHEN 1 THEN
(
DELETE
FROM t_col_val_document_uploaded p
WHERE p.sz_application_no = '20400000988'
AND p.sz_collateral_id = 'PROP000000000PRO1701'
AND p.i_document_srno = '28' )
ELSE NULL
END
FROM dual;
You need to recreate your query and make sure to follow the flow of the clauses properly, please check the next two links to get a better understanding :
[ORA-00936: missing expression tips]
How do I address this ORA-00936 error?
Answer: The Oracle oerr utility notes this about the ORA-00936 error:
ORA-00936 missing expression
Cause: A required part of a clause or expression has been omitted. For example, a SELECT statement may have been entered without a list of columns or expressions or with an incomplete expression. This message is also issued in cases where a reserved word is misused, as in SELECT TABLE.
Action: Check the statement syntax and specify the missing component.
The ORA-00936 happens most frequently:
1 - When you forget list of the column names in your SELECT statement.
2. When you omit the FROM clause of the SQL statement.
ora-00936-missing-expression
I hope this can help you.
You cannot use a simple select query like this. You have to use a PL/SQL block like below -
DECLARE NUM_CNT NUMBER := 0;
BEGIN
SELECT Count(1)
INTO NUM_CNT
FROM wf_item_activity_statuses_v t
WHERE t.activity_label IN ('WAITING_DISB_REQ',
'LOG_DDE',
'LOG_SENDBACK_DDE')
AND t.item_key IN(SELECT r.i_item_key
FROM wf_t_item_xref r
WHERE r.sz_appl_uniqueid = '20400000988');
IF NUM_CNT = 0 THEN
delete
from t_col_val_document_uploaded p
WHERE p.sz_application_no = '20400000988'
AND p.sz_collateral_id = 'PROP000000000PRO1701'
AND p.i_item_key = '648197'
AND p.i_document_srno = '27';
ELSIF NUM_CNT = 1 THEN
DELETE
FROM t_col_val_document_uploaded p
WHERE p.sz_application_no = '20400000988'
AND p.sz_collateral_id = 'PROP000000000PRO1701'
AND p.i_document_srno = '28' )
END IF;
END;
How to run procedure without parameter in Teradata
I'm trying with : call db1.proc_dbOSA()
Error Msg:
Call failed 3707: PROC_DBOSA: Syntax error, expected something
like a name or a Unicode delimited identifier between ‘(‘ and ‘)’
New Procedure with error result.
When i run only code then everything works ok.
REPLACE PROCEDURE db1.proc_dbOSA()
BEGIN
DELETE FROM db1.LOG_dbOSA;
INSERT INTO
db1.LOG_dbOSA
(StoreNo, IDX, Flow, Status, MRP, OSA_IDX, OSA_AC)
WITH a AS (
SELECT
c.StoreCode,
CAST(SUBSTRING(c.ArticleCode FROM 13 FOR 6) AS INT) AS IDX,
RpType,
CASE
WHEN c.MinimumTargetStockWrpl >= l.MinimumTargetStockWrpl THEN CAST(l.MinimumTargetStockWrpl AS INT)
WHEN c.MinimumTargetStockWrpl < l.MinimumTargetStockWrpl THEN CAST(c.MinimumTargetStockWrpl AS INT)
End AS StoreMin,
c.ValUnrestrictedStock
FROM
db1.tab1 c
INNER JOIN
(
SELECT
StoreCode,
ArticleCode,
MinimumTargetStockWrpl
FROM
db1.tab1
WHERE
ProcessingDate = CURRENT_DATE - 14
) l ON c.StoreCode = l.StoreCode AND c.ArticleCode = l.ArticleCode
WHERE
c.ProcessingDate = CURRENT_DATE AND c.MinimumTargetStockWrpl IS NOT NULL AND l.MinimumTargetStockWrpl IS NOT NULL AND l.MinimumTargetStockWrpl > 0
)
, t AS
(
SELECT
CAST(SUBSTRING(ArticleCode FROM 13 FOR 6) AS INT) AS IDX,
RpType,
ArticlesPlanner
FROM
DWH_db_V.STK_B_ARTICLE_DAY_V
WHERE
ProcessingDate = CURRENT_DATE AND StoreCode = 'DR04'
)
SELECT
a.StoreCode,
a.IDX,
t.RpType,
t.ArticlesPlanner,
a.RpType,
CASE
WHEN a.ValUnrestrictedStock > 0 THEN 1
WHEN a.ValUnrestrictedStock <= 0 THEN 0
End AS OSA_IDX,
CASE
WHEN a.ValUnrestrictedStock >= StoreMin THEN 1
WHEN a.ValUnrestrictedStock < StoreMin THEN 0
End AS OSA_AC
FROM
a
LEFT JOIN
t ON t.IDX = a.IDX;
End;
BTEQ Error:
+---------+---------+---------+---------+---------+---------+---------+----
Call proc_dbOSA;
Call proc_dbOSA;
$
* Failure 3707 Syntax error, expected something like '(' between the word
'proc_dbOSA' and ';'.
Statement# 1, Info =18
* Total elapsed time was 1 second.
Call proc_dbOSA();
* Failure 3707 PROC_DBOSA:Syntax error, expected something like a name or
a Unicode delimited identifier between '(' and ')'.
* Total elapsed time was 1 second.
Stored procedures do not support the following:
EXPLAIN and USING request modifiers within a stored procedure
EXECUTE macro statement
WITH clause within a stored procedure.
Stored procedures, as well as macros, do not support the following query logging statements:
BEGIN QUERY LOGGING
END QUERY LOGGING
FLUSH QUERY LOGGING
REPLACE QUERY LOGGING
Hey Guys thanks for the help earlier. I have now ran into a new problem. A few steps later in my homework I needed to add an additional part to this trigger. The trigger needs to subtract one from the number of copies. When the number of copies hits 0 it should display unavailable. I have been trying for the last few hours to figure it out and this is what I came up with. Any help or suggestions would be greatly appreciated!!
CREATE or REPLACE Trigger Unavailable_Rule
BEFORE INSERT ON Transaction
FOR EACH ROW
BEGIN
IF :new.Date_Rented_Out is not null AND :new.Date_Returned is NULL AND Num_Copies=1
THEN
UPDATE Video
set Num_Copies = Num_Copies - 1,
Status = 'Unavailable'
where Vid_Num = :new.Vid_Num;
ELSE
Num_Copies = Num_Copies - 1;
End IF;
END;
/
show errors;
6/4 PL/SQL: SQL Statement ignored
7/15 PL/SQL: ORA-00971: missing SET keyword
13/13 PLS-00103: Encountered the symbol "=" when expecting one of the f ollowing: := . ( # % ;
14/2 PLS-00103: Encountered the symbol "END"
Your update statement is misformed. Instead of:
UPDATE Video
Num_Copies = Num_Copies -1
set Status = 'Unavailable'
where Vid_Num = :new.Vid_Num;
Assign Num_Copies in a set:
UPDATE Video
set Num_Copies = Num_Copies - 1,
Status = 'Unavailable'
where Vid_Num = :new.Vid_Num;
EDIT:
Your if statement can be replaced with:
UPDATE Video
set Num_Copies = Num_Copies - 1,
Status = (case when :new.Date_Rented_Out is not null AND :new.Date_Returned is NULL AND Num_Copies = 1 then 'Unavailable'
else status
end)
where Vid_Num = :new.Vid_Num;
I get an error when trying to compile the following trigger...
CREATE OR REPLACE TRIGGER DegreePart_CreditsMax
BEFORE INSERT OR UPDATE ON DEGREE_MODULE
FOR EACH ROW
BEGIN
IF(SUM(NUMBER_OF_CREDITS) FROM DEGREE_MODULE INNER JOIN MODULE ON DEGREE_MODULE.MODULE_ID = MODULE.MODULE_ID
WHERE OPTIONAL = 'N' AND DEGREE_ID = :NEW.DEGREE_ID > 120)
THEN
RAISE_APPLICATION_ERROR( -- Error Message
-20001,
'Degree must not contain compulsary modules worth over 120 credits.' );
END IF;
END;
/
I'm trying to check that when a module is added the sum of all the current compulsory modules for that degree plus the new module is less than 120???
error is...
Error(2,27): PLS-00103: Encountered the symbol "FROM" when expecting one of the following: ) , * & = - + < / > at in is mod remainder not rem => <> or != or ~= >= <= <> and or like like2 like4 likec as between || multiset member submultiset
You could try ‘rephrasing’ your condition like this:
IF EXISTS (
SELECT SUM(NUMBER_OF_CREDITS)
FROM DEGREE_MODULE
INNER JOIN MODULE ON DEGREE_MODULE.MODULE_ID = MODULE.MODULE_ID
WHERE OPTIONAL = 'N' AND DEGREE_ID = :NEW.DEGREE_ID
HAVING SUM(NUMBER_OF_CREDITS) > 120
)
THEN
…