How to fetch error codes of oracle or warning codes?
Like when I create a procedure it shows
Procedure created with compilation errors.
For seeing the errors I need to write
show errors;
Is there any way through which I can get these errors or messages through a sql query?
You can use:
select * from all_errors
In this table have all errors:)
More specific:
select * from SYS.USER_ERRORS where NAME = 'YOUR_PROCEDURE_NAME' and type = 'PROCEDURE'
Related
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';
I have a view, which created (ORACLE)
CREATE OR REPLACE FORCE VIEW "OPS$DTEPROD"."DTE_BLMB_TRD_ACCT_VW"
("BB_TRD_ACCT", "DESCRIPTION", "ICI_TRD_ACCT") AS
select rtrim(STRBK_BOOK_NAME) bb_trd_acct,
rtrim(STRBK_DESCRIPTION) description,
trading_acct ici_trd_acct
from spider.sp_struct_books#spdn b1
, dte_trading_acct
where substr(rtrim(STRBK_BOOK_NAME),1,2)=ltrim(rtrim(fits_trading_Acct))
and strbk_last_update_date =
(select max(strbk_last_update_date)
from spider.sp_struct_books#spdn b2
where b2.strbk_book_number = b1.strbk_book_number)
In the package, when I compile it shows me an error
328/117 PL/SQL: ORA-04063: view "OPS$DTEPROD.DTE_BLMB_TRD_ACCT_VW" has
errors
Could you please help me to find the reason?
Thanks
Errors for PACKAGE BODY RATES_2DTE:
LINE/COL ERROR
-------- -----------------------------------------------------------------
328/1 PL/SQL: SQL Statement ignored
328/117 PL/SQL: ORA-04063: view "OPS$DTEPROD.DTE_BLMB_TRD_ACCT_VW" has
errors
Please execute following query with same user which get the outlined error:
Select * from user_errors where name like 'OPS$DTEPROD.DTE_BLMB_TRD_ACCT_VW';
This will give you errors in the view. You can post output for further investigations.
Regards
Abhi
In order to solve such problem I have to work with our DBA. Only they can give access to this database from development server. On production we have everything done.
Thank you all for trying to help me
Their are two probabilities :
1) As another member (#xQbert) suggested - user who is used to created view do not have accesses to table over dB link.
2) Database, used in database link, is not accessible.
Solution:
1) Please execute following statement by same user which is trying to select from view:
Select count(*) from spider.sp_struct_books#spdn ;
This should give same error as original error.
We want to check is read access to destination table is in place.
2) From server/command prompt on database host, where view is created, execute following :
tnsping spdn (or tnsping <database name usec by db link>)
OR
sqlplus <Username>/<Password>#spdn (or <database name usec by db link>)
We want to check if destination database on dBlink is reachable.
Abhi
When compiling a package or stored procedure in SQL*Plus, show errors is used to display any errors from the last compilation.
What is the equivalent SQL query to fetch this information?
You want to look at one of the _ERRORS views - either USER_ERRORS, ALL_ERRORS, or DBA_ERRORS. For example:
SELECT *
FROM DBA_ERRORS
WHERE OWNER = 'YOUR_SCHEMA' AND
NAME = 'WHATEVER'
ORDER BY SEQUENCE
Docs here
Share and enjoy.
If I want to get the errors of a procedure I can find it in the USER_ERRORS table. I am searching for an alternative way for my Java application. I need a query, or a different method, so that I can catch compilation errors of a procedure.
For example the following procedure will compile with an error:
create or replace procedure testprc is
sql_txt varchar2(11);
begin
select count(1) into sql_txt FROM ctsmessages
end;
I can go run select * from user_errors to find out that the error was due to a missing semi-colon. Is there another alternative?
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.