Show compilation warnings in Intellij working with Oracle and PL/SQL - oracle

This code generates a Warning: Trigger created with compilation errors. (if for example the column doesn't exist) in iSQL*Plus, but not when executed in the console in Intellij.
CREATE TRIGGER triggerName
INSTEAD OF INSERT ON Table
REFERENCING NEW AS variabel
BEGIN
SELECT
COUNT(*)
INTO variabel
FROM Table
WHERE Table.column = 1;
END;
After I have executed the above I can do SHOW ERRORS in iSQL*Plus and get something like PL/SQL: ORA-00904: "TABLE"."COLUMN": invalid identifier. Trying to do SHOW ERRORS in Intellij leaves me with the SHOW keyword underlined in red which prevents me from executing it.
Is there anyway to have this iSQL*Plus functionality in Intellij?

Using ALL_ERRORS/USER_ERRORS table should help you see the errors, wherever you go!
SELECT * FROM ALL_ERRORS WHERE NAME = 'TRIGGERNAME'
SHOW ERRORS is an iSQL*Plus only feature. It would implicitly query the above table and print the results for us.
I see some plugins available for intellij support. Like one here. They would be using similar approach of SHOW ERRORS.

Related

creating function using liquibase sql changelog is successful but function has compilation warning

I am trying to create function in oracle 12c database using liquibase, below is the sql formatted changelog. I am doing negative testing to see what response i get, purposefully using wrong keyword returns
--liquibase formatted sql
--changeset your.name:1 failOnError:true
CREATE OR REPLACE FUNCTION get_tab1_count RETURNS NUMBER AS
l_count NUMBER;
BEGIN
SELECT COUNT(*)
INTO l_count
FROM person3;
RETURN l_count;
END;
/
This change log gets updated successfully, but as expected in the database I have a function now which has compilation errors,
Compilation errors for FUNCTION GET_TAB1_COUNT
Error: PLS-00103: Encountered the symbol "RETURNS" when expecting one of the following:
( return compress compiled wrapped
my question is am i doing something wrong, that liquibase is giving a "update has been successful" message? Or is this expected behaviour? I have tried adding failOnError:true in the changelog to see if it will actually now fail as there is a compilation error during function creation, but it does not make any difference. I would think that, liquibase would give some sort of failure message when there is a compilation error like the above, am I wrong?
Liquibase is just running your changeset as sql being passed to a JDBC connection.
quoting a colleague: "the jdbc connection gives us for a response and I THINK most databases are just "yes, you created that fine" even though it is not actually valid at this point. But, they don't tell us until we run it"
As a work around you could write a script that checks for compilation errors and fails when it finds any issues. Create an execute change set with runAlways="true"

Unable to create a trigger in Oracle SQL

I want to create a trigger but it is tainted by a warning: trigger created with compilation errors. The query that I am running is:
CREATE OR REPLACE TRIGGER Audit_Salaries
AFTER UPDATE ON EMPLOYEES
FOR EACH ROW
BEGIN
IF (:NEW.Salary > :OLD.Salary*1.20) THEN
INSERT INTO Salary_Audit (EmployeeID, OldSalary, NewSalary,Username, ChangeDate)
VALUES (:NEW.employee_id, :OLD.Salary,:NEW.Salary, user, sysdate);
END IF;
END;
/
Warning: Trigger created with compilation errors.
And this is the result that I am getting:
Warning: Trigger created with compilation errors.
I tried reading other similar answers but the solutions that are given there already exist in mine(syntax).
Due to this, when I log into the different user and run the query, it says the trigger is at fault or not created properly, re-validation failed.
I expect the trigger to be created without any compilation errors along with the understanding of what is wrong in my query.
To see the details of the compilation error, you can query system view USER_ERRORS (or DBA_ERRORS):
SELECT * FROM USER_ERRORS WHERE NAME = 'AUDIT_SALARIES';
I cannot reproduce the error that you are getting, your code compiles successfully when I run it on 11gR2 and 18c. I can only imagine that there is an error in the column names of source table employees or target table salary_audit.
Demo on DB Fiddle
You can see the compilation error using DBA_ERRORS.
SELECT * FROM DBA_ERRORS WHERE NAME = 'AUDIT_SALARIES';
You tagged SQL Developer.
Are you using SQL Developer?
Because if you are...
We automatically do a 'show errors' for you on a compile when errors/warnings are returned. You can also see the compiler messages on the 'Compiler' tab - this should open automatically when you run it.
If you're not seeing this, I'm guessing you're on some version of SQL Developer where a bug is preventing that from happening, but I'm not aware of a version where that would be true.
Try this it will solve you query:
SELECT * FROM DBA_ERRORS WHERE NAME = 'AUDIT_SALARIES'
OR
SELECT * FROM USER_ERRORS WHERE NAME = 'AUDIT_SALARIES';

Oracle SQL Developer - How to generate script in correct order of dependencies

I would want to generate create script that will create all the database views which are very many.
I know how to do it in Oracle SQL Developer already using menu: Tools > Database Exports. However I encounter issues doing the export create views scripts. Below are the issues.
Issue #1 The order of creation of view is not correct. In example below, the MY_VIEW_B is created first in the script before its dependency MY_VIEW_A. How can I generate script that are in correct order of dependencies?
CREATE OR REPLACE MY_VIEW_B ("COLUMN1", "COLUMN2") AS
SELECT "COLUMN1", "COLUMN2"
FROM MY_VIEW_A;
CREATE OR REPLACE MY_VIEW_A ("COLUMN1", "COLUMN2") AS
SELECT "COLUMN1", "COLUMN2"
FROM TABLE_A;
Issue #2 The semicolon ";" is carried over to the last line of the view codes but the problem is it is comment line. So this will get error when I execute the script because there is no closing ";" semicolon since it was moved to the line where the comment is. How can I generate script so that the last line of my view code which is ";" semicolon is not auto carried over to second to the last line of the view code which is a comment?
CREATE OR REPLACE MY_VIEW_C ("COLUMN1", "COLUMN2") AS
SELECT "COLUMN1", "COLUMN2"
FROM TABLE_B
--THIS IS A COMMENT;
CREATE OR REPLACE MY_VIEW_C ("COLUMN1", "COLUMN2") AS
SELECT "COLUMN1", "COLUMN2"
FROM TABLE_C;
Thank you.
As Oracle States here:
FORCE
Specify FORCE if you want to create the view regardless of whether the
base tables of the view or the referenced object types exist or the
owner of the schema containing the view has privileges on them. These
conditions must be true before any SELECT, INSERT, UPDATE, or DELETE
statements can be issued against the view.
If the view definition contains any constraints, CREATE VIEW ... FORCE
will fail if the base table does not exist or the referenced object
type does not exist. CREATE VIEW ... FORCE will also fail if the view
definition names a constraint that does not exist.
also check Terminator and Pretty Print to deal with the second issue;
Tested with Oracle SQL Developer Version 4.1.3.20 Build MAIN-20.78

Running PL/SQL script in PHP

I have a script in PL/SQL , that drop some tables , sequences , triggers, and creating them again in the same script , I need this script in my website for deleting all data from database (and I want to acces this script pressing one button on website) so I tried to do a function / procedure in PL/SQL that read line by line from the script file and executing every line with dynamic sql , everything went ok till one error at:
CREATE OR REPLACE TRIGGER players_bir BEFORE INSERT ON players FOR EACH ROW BEGIN SELECT players_seq.NEXTVAL INTO :new.id FROM dual END
this gave me the error:
ORA-24344: success with compilation error
I searched for solutions, but I didn't find anything.
You are missing the semi-colon after dual on your SELECT statement. This ORA error generally means you compiled some code, but that is has some issue.
CREATE OR REPLACE TRIGGER players_bir
BEFORE INSERT ON players
FOR EACH ROW
BEGIN
SELECT players_seq.nextval
INTO :new.id
FROM dual;
END
Looking in all_errors will show you what the issue is or you could manually compile this trigger in some IDE (like SQL Developer) and that should also make it obvious.
SELECT *
FROM all_errors e
WHERE e.name = 'PLAYERS_BIR'
AND e.type = 'TRIGGER';
Additionally if all you are using your trigger for is to set some identity column and you are on Oracle 12c you can use some of the new features to accomplish this. Triggers are inherently slow and the new identity feature performs about as good as referencing the sequence directly in your INSERT.

Error SQL03120 on Trigger scripts in 2008 DB Project

I'm working on adding a database project in VS2010. I created a SQL 2008 DB Project, pointed at the development server, and it seems to have generated all of the appropriate schema objects. However, all of the CREATE TRIGGER scripts have the following error:
SQL03120: Cannot find element referenced by the supporting statement
Googling that error message doesn't return much, and seems to point to scripts using ALTER instead of CREATE which isn't the case here. This is an example of one of the scripts:
CREATE TRIGGER [TR_t_TABLE_TRIGGERNAME] ON [content].[t_TABLE]
FOR INSERT
AS
BEGIN
IF ( SELECT COUNT(*) FROM inserted) > 0
BEGIN
DECLARE #columnBits VARBINARY(50)
SELECT #columnBits = COLUMNS_UPDATED() | CAST (0 AS BIGINT)
INSERT INTO [history].[t_TABLE]
(
....
)
SELECT
....
FROM inserted
END
END
GO
EXECUTE sp_settriggerorder #triggername = N'[Content].[TR_t_TABLE_TRIGGER]', #order = N'last', #stmttype = N'insert';
The line that Visual Studio is attributing the error to is the last line executing the system proc. What stands out to me is that none of the object exist in the dbo schema. The table is in the Content schema and it has a matching table in the History schema. It would seem like the [Content] and [History] qualifiers would be resolvable though. Can't figure this one out...
Since this post comes up when you search for the above error on Google: another reason for this error is if you've got a stored procedure in a database project which specifies ALTER PROCEDURE rather than CREATE PROCEDURE.

Resources