Oracle Error: stored procedure parameters values not declared - oracle11g

Following is the procedure code snippet:
PRC_UPDATE
BEGIN
UPDATE EMP E SET E.NAME = 'X' WHERE E.E_ID = 'Y';
COMMIT;
EXCEPTION WHEN OTHERS
ROLLBACK;
PRC_ERROR_LOG(E.E_ID,sqlcode,sqlerrm);
RAISE;
END PRC_UPDATE;
I have a procedure which updates the values in a table.I have defined an error logging procedure (PRC_ERROR_LOG)to insert the errors in an Error Logging Table.But while calling PRC_ERROR_LOG it throws an error as "identifier 'E_ID' must be declared". Will it not recognize the Row value in which the error is thrown out.
Basically my requirement is to insert the error and the row where the particular error is caught into the error table .How can I send the particular Row value in the Error Logging Procedure?
Thanks in advance

You should look into using a cursor, the reason that you are experiencing this error is that you have already executed the update statement and the e.e_id is now out of scope. You could also use try-catch to accomplish this.

Related

plsql Trigger error ORA-00604

Following Trigger created in a user anu
create or replace trigger audit_creation1
before create
on schema
begin
insert into audit_creation
values(audit_creation_s1.nextval,
ora_dict_obj_owner,
ora_dict_obj_name,
sysdate);
end;
create table cc(cid number);
ORA-00604: error occurred at recursive SQL level 1
ORA-30511: invalid DDL operation in system triggers
This worked before many times. It was working successfully.
But now it's throwing error.
Throw a command
purge recyclebin;
as your trigger owner (anu in your case).

How to catch all exceptions in PL/SQL script?

Currently I'm writing an update script with error handling. A part of this script contains a call to a table that might not exists. So I'd like to catch the exception. However, when running the script in SQL Developer, it does not seem to catch the exception.
Script (simplified):
BEGIN
SELECT VersionNumber
FROM DbVersion;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line(SQLCODE);
END;
SQL Developer Script Output:
Error starting at line 2 in command:
BEGIN
SELECT VersionNumber
FROM DbVersion;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line(SQLCODE);
END;
Error report:
ORA-06550: line 3, column 10:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 2, column 5:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Why does it not simply display the error code? Thanks!
If You are using non-existing table - that's syntax error - plsql block is invalid, and cannot be run.
Exception handling works when the block is running.
If You need to use table that may not exists, use can use dynamic sql (execute immediate 'select ... from non_existing_table') to avoid compile errors.
Or check for table existance in all_tables view.

How to determine what the actual error is in an Oracle stored procedure, when "execution completed with warning"?

I am using the following code
create or replace procedure phys_last_year_sales_sp (amdm_phys_id number(6))
is
begin
dbms_output.put_line('amdm_phys_id= '||amdm_phys_id);
end;
to create stored procedure but every time I execute above query it shows the following error
java.sql.SQLWarning: Warning: execution completed with warning
How do I find out what the actual error is?

trigger for updating a value

I am a newbie in PLSQL and I would like to create a trigger that checks first if there is a record in a table before making an update.
The code I got so far is:
CREATE OR REPLACE TRIGGER table_bu
BEFORE UPDATE ON employee
FOR EACH ROW
DECLARE
v_employee_id:=employee.employee_ID%TYPE;
BEGIN
SELECT employee_id INTO v_employee_id FROM employee;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR (-20001,'data not found');
END;
How I can create a trigger that checks up if a record exists in the table and if it does not exists does not allow the update.
My table estructure is:
employee_id NUMBER
employee_name VARCHAR(20)
employee_salary NUMBER
...
Thanks
You are on a wrong way. The trigger as it is will throw runtime 'Mutating table' error even after fixing syntax error - you missed semicolon after raise_application_error(also it should take 2 arguments, not one). Correct syntax :
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR (-20001, 'data not found'); -- 1st parameter -error code
Update
As far as I understand the updated version of the question, you want to show error if record doesn't exist. The problem with row level trigger approach is that it won't be executed if nothing is found due to condition in WHERE. The simplest way is to check number of rows affected on client side and raise an error there. Or you can write a procedure that checks sql%rowcount after executing desired update, and then throw an exception if it's 0.
If you prefer to do in a hard way, you can create package variable which of type employee.employee_ID%TYPE, before update statement level trigger that resets variable (say set it to null), after update row level trigger that sets this variable to NEW.employee_ID, and after update statement level trigger that throws an exception if the variable is null. Note: this will properly work for individual updates only.
"How I can create a trigger that checks up if a record exists in the table and if it does not exists does not allow the update."
There is really only one practical way to do this - use a referential constraint (foreign key).

java.sql.SQLSyntaxErrorException: ORA-04098: trigger 'MYTABLE.MY_SEQUENCE_ID' is invalid and failed re-validation

I am creating this oracle 11g statement inside a java String and then executing it in sql developer. I tried running it on the database and got a warning when the trigger
is created. But, when run from the code, I get the error mentioned in my title.
Please tell me where is the mistake and how i can fix it ?
CREATE OR REPLACE TRIGGER myschema.my_sequence_id BEFORE INSERT ON myschema.mytable
FOR EACH ROW BEGIN SELECT my_sequence_id.nextval INTO :new.mycolumn FROM DUAL; end; /
Thanks in advance !
You can't have a trigger named my_sequence_id if you already have a sequence my_sequence_id. They share the same namespace. Your trigger would need to be named something other than the name of the sequence (or any other object in the schema).

Resources