Discussions
Categories
- 196.8K All Categories
- 2.2K Data
- 235 Big Data Appliance
- 1.9K Data Science
- 449.9K Databases
- 221.6K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 549 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 532 SQLcl
- 4K SQL Developer Data Modeler
- 186.9K SQL & PL/SQL
- 21.3K SQL Developer
- 295.5K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.1K Development Tools
- 104 DevOps
- 3.1K QA/Testing
- 645.9K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 154 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 17 Java Essentials
- 158 Java 8 Questions
- 85.9K Java Programming
- 79 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.2K Java SE
- 13.8K Java Security
- 203 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 401 LiveLabs
- 37 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.6K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 230 Portuguese
PLS-00103: Encountered the symbol "end-of-file" in trigger

I got the message Error at line 31: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
This is my trigger:
create or replace TRIGGER add_fiscaly
AFTER INSERT ON MDW_SCRAP_MDCOPY
FOR EACH ROW
BEGIN
SELECT PR_YEAR||PR_MONTH
INTO :NEW.Fiscaly
from
(SELECT
CASE EXTRACT (MONTH FROM SYSDATE)WHEN 1 THEN EXTRACT(YEAR FROM SYSDATE)-1
WHEN 2 THEN EXTRACT(YEAR FROM SYSDATE)-1
WHEN 3 THEN EXTRACT(YEAR FROM SYSDATE)-1
ELSE EXTRACT(YEAR FROM SYSDATE)
END
AS PR_YEAR ,
CASE EXTRACT (MONTH FROM SYSDATE)
WHEN 04 THEN 1
WHEN 05 THEN 1
WHEN 06 THEN 1
WHEN 07 THEN 1
WHEN 08 THEN 1
WHEN 09 THEN 1
WHEN 10 THEN 2
WHEN 11 THEN 2
WHEN 12 THEN 2
WHEN 01 THEN 2
WHEN 02 THEN 2
WHEN 03 THEN 2
END
AS PR_MONTH
FROM dual)
END;
/
The line 31 is: AS PR_MONTH
I'd appreciate your help
Answers
-
Start with adding a ; after the last FROM dual)
ending the select into ... sentence
-
And I think your determinination of the fiscal period can be done with less code :
check the example
DECLARE
PROCEDURE GET_FISCALY( p_date DATE := sysdate)
IS
new_fiscaly varchar2(10);
new_date DATE;
BEGIN
new_date := ADD_MONTHS(p_date,-3);
new_fiscaly := to_char(new_date,'YYYY') || ROUND(TO_NUMBER(TO_CHAR(new_date,'Q'))/2);
dbms_output.put_line(to_char(p_date, 'DD/MM/YYYY') || ':' ||new_fiscaly);
END;
begin
get_fiscaly;
FOR i IN 1 .. 60 LOOP
get_fiscaly(ADD_MONTHS(sysdate,i));
END LOOP;
end;
-
Hi, @User_R7LP2
The line 31 is: AS PR_MONTH
It would be logical to think that, but actually that's line 28. In triggers, the first BEGIN or DECLARE statement is considered line 1.
Another tricky thing about error messages is that the line number reported is the line where the error was detected. For syntax errors, that can be later than the actual error. For example, if you omit the closing single-quote of a string literal, the error may not be detected for several lines. In this case, the actual error (as Hub said) seems to be missing a semicolon after
FROM dual)
which is actually line 29, but the error wasn't detected until
/
which is line 31.
-
And, to fully clarify the error: How is the parser reading your code? Answer: at the end of your subquery (the closing parenthesis), there is no semicolon; there is the word END, where you might otherwise have an alias for the subquery. The parser accepts that without asking questions (why would it?) It thinks END is the alias for the subquery; then there is a semicolon after END. The parser thinks that is the end of the SELECT ... INTO ... statement. Up to that point THERE IS NO ERROR.
Then it comes straight to the slash terminating the code for the trigger. But wait - where is the END; command? You may think it's there, but it isn't; from the parser's point of view, the END in your code is an alias, and the semicolon after it ends the SELECT ... INTO ... statement - and there is no END; command in the block.