I have been studying triggers from
[ http://www.tutorialspoint.com/plsql/plsql_triggers.htm][1]
with sqldeveloper and I connected Oracle 11g database. I created customers table successfully. But when I tried to create trigger as :
CREATE OR REPLACE TRIGGER display_salary_changes
BEFORE DELETE OR INSERT OR UPDATE ON customers
FOR EACH ROW
WHEN (NEW.ID > 0)
DECLARE
sal_diff number;
BEGIN
sal_diff := :NEW.salary - :OLD.salary;
dbms_output.put_line('Old salary: ' || :OLD.salary);
dbms_output.put_line('New salary: ' || :NEW.salary);
dbms_output.put_line('Salary difference: ' || sal_diff);
END;
I get these errors:
Error starting at line : 1 in command -
CREATE OR REPLACE TRIGGER display_salary_changes
BEFORE DELETE OR INSERT OR UPDATE ON customers
FOR EACH ROW
WHEN (NEW.ID > 0)
DECLARE
sal_diff number
Error report -
SQL Command: trıgger DISPLAY_SALARY_CHANGES
Failed: Warning: yürütme uyarı ile tamamlandı
Error starting at line : 7 in command -
BEGIN
sal_diff := :NEW.salary - :OLD.salary;
dbms_output.put_line('Old salary: ' || :OLD.salary);
dbms_output.put_line('New salary: ' || :NEW.salary);
dbms_output.put_line('Salary difference: ' || sal_diff);
END;
Error report -
ORA-06550: line 2, column 5:
PLS-00201: identifier 'SAL_DIFF' must be declared
ORA-06550: line 2, column 5:
PL/SQL: Statement ignored
ORA-06550: line 3, column 60:
PLS-00487: Invalid reference to variable 'SQLDEVBIND1Z_2'
ORA-06550: line 3, column 5:
PL/SQL: Statement ignored
ORA-06550: line 4, column 60:
PLS-00487: Invalid reference to variable 'SQLDEVBIND1Z_1'
ORA-06550: line 4, column 5:
PL/SQL: Statement ignored
ORA-06550: line 5, column 51:
PLS-00201: identifier 'SAL_DIFF' must be declared
ORA-06550: line 5, column 5:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
What is wrong with this create trigger block?
It seems to be the same "Securing Literals" feature as described here
http://krisrice.io/2015-09-11-sqlcl-more-secure-now-with-rest/
Related
Create or replace PROCEDURE SSp_EmpHoursInfo
(p_EHrsInfo OUT SYS_REFCURSOR)
AS
BEGIN
OPEN p_EHrsInfo FOR
Select
a.personid, a.first_name, a.last_name,c.hoursworked,d.carecentername, c.break
from person a
join employee b on a.personid = b.empersonid
join employee_assigned_care_center c on b.empersonid = c.empersonid
join care_center d on c.empersonid = d.carecenterid
where hoursworked> 10;
END SSp_EmpHoursInfo;
Everytime I am trying to call the store procedure it is giving me this error msg:
Error starting at line : 225 in command -
BEGIN SSp_EmpHoursInfo (hoursworked> 10); END;
Error report -
ORA-06550: line 1, column 3:
PLS-00201: identifier 'HOURSWORKED' must be declared
ORA-06550: line 1, column 52:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
The problem is very obvious.
BEGIN SSp_EmpHoursInfo (hoursworked> 10); END; is not the proper way of calling it.
The procedure parameter must be the sys_refcursor.
You must use:
DECLARE
OUTPUT_CUR SYS_REFCURSOR;
BEGIN
SSp_EmpHoursInfo (OUTPUT_CUR );
-- USE CURSOR ACCORDINGLY
END;
/
#C:\Users\4\Desktop\dbdrop;
#C:\Users\4\Desktop\dbcreate;
SET SERVEROUTPUT ON;
DECLARE
ORDER_ID ORDERS.ODID%TYPE;
COMPANY_NAME ORDERS.CNAME%TYPE;
ORDER_DATE ORDERS.ODATE%TYPE;
CURSOR ord_cursor IS
SELECT ODID, CNAME, ODATE
FROM ORDERS;
BEGIN
for ord_cursor in
(select odid, cname, odate
from orders
where order_date < trunc(sysdate)
and rownum <= 5
)
loop
dbms_output.put_line('Order ID = ' || ord_cursor.odid);
dbms_output.put_line('Order date = ' || ord_cursor.odate);
dbms_output.put_line('Company = ' || ord_cursor.cname);
end loop;
END;
ORA-06550: line 2, column 24:
PLS-00302: component 'ODID' must be declared
ORA-06550: line 2, column 17:
PL/SQL: Item ignored
ORA-06550: line 3, column 24:
PLS-00302: component 'CNAME' must be declared
ORA-06550: line 3, column 17:
PL/SQL: Item ignored
ORA-06550: line 4, column 24:
PLS-00302: component 'ODATE' must be declared
ORA-06550: line 4, column 17:
PL/SQL: Item ignored
ORA-06550: line 6, column 29:
PL/SQL: ORA-00904: "ODATE": invalid identifier
ORA-06550: line 6, column 9:
PL/SQL: SQL Statement ignored
ORA-06550: line 10, column 25:
PL/SQL: ORA-00904: "ODATE": invalid identifier
ORA-06550: line 10, column 6:
PL/SQL: SQL Statement ignored
ORA-06550: line 16, column 45:
PLS-00364: loop index variable 'ORD_CURSOR' use is invalid
ORA-06550: line 16, column 5:
PL/SQL: Statement ignored
ORA-06550: line 17, column 45:
PLS-00364: loop index variable 'ORD_CURSOR' use is invalid
ORA-06550: line 17, column 5:
PL/SQL: Statement ignored
ORA-06550: line 18, column 45:
PLS-00364: loop index variable 'ORD_CURSOR' use is invalid
ORA-06550: line 18, column 5:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
CREATE OR REPLACE TRIGGER trg_test
AFTER DELETE
ON ADMİN.KULLANICILAR
for each row
DECLARE
v_username := USER;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_username);
END;
Hey guys I'm getting that error always I put every privalege to my user and
it says :
after editing
CREATE OR REPLACE TRIGGER trg_test
AFTER DELETE
ON ADMİN.KULLANICILAR
for each row
DECLARE
v_username nvarchar2(20) := USER;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_username);
END;
and error like that it ll runs on apex but not on oracle sql dev:
BEGIN
DBMS_OUTPUT.PUT_LINE(v_username);
END;
Error report -
ORA-06550: line 2, column 26:
PLS-00201: identifier 'V_USERNAME' must be declared
ORA-06550: line 2, column 5:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
i am learning mysql and have moved onto procedures. I have created a procedure and i am trying to run it. But when I run the procedure i am faced with lots of errors, the error point to lines that have no errors that I can see, can anyone help me out?
This is the procedure I have created
create or replace PROCEDURE AD_AGENCY_INFO(
v_ad_id IN ad_agency.AGENCY_ID%TYPE,
v_cert IN ad_agency.NO_OF_AD_RUNS%TYPE,
v_price IN ad_agency.CREDIT_WORTHY%TYPE,
v_agency_id IN ad_agency.AGENCY_ID%TYPE
) AS
BEGIN
UPDATE AD SET AD_ID = v_ad_id, CERTIFICTAION = v_cert, PRICE = v_price where agency_id = v_agency_id;
INSERT INTO AD_SLOT (AD_ID) VALUES (v_ad_id);
EXCEPTION
WHEN NO_DATA_FOUND THEN
rollback;
END AD_AGENCY_INFO;
This is how I am calling the procedure
DECLARE
V_AGENCY_ID NUMBER:=&Enter_Agency_ID;
V_NO_OF_RUNS NUMBER:=&Enter_No_of_Runs;
V_CREDIT_WORTHY CHAR(3):=&Enter_Credit_Worthy;
V_AVAILABLE_SLOTS NUMBER:=&Enter_Available_Slots;
V_STATUS CHAR(1):=&Enter_Status;
BEGIN
V_AGENCY_ID := NULL;
V_NO_OF_RUNS := NULL;
V_CREDIT_WORTHY := NULL;
V_AVAILABLE_SLOTS := NULL;
V_STATUS := NULL;
AD_AGENCY_INFO(
V_AGENCY_ID => V_AGENCY_ID,
V_NO_OF_RUNS => V_NO_OF_RUNS,
V_CREDIT_WORTHY => V_CREDIT_WORTHY,
V_AVAILABLE_SLOTS => V_AVAILABLE_SLOTS,
V_STATUS => V_STATUS
);
END;
And this is the error log I get after running the procedure
Error report -
ORA-06550: line 4, column 28:
PLS-00201: identifier 'N' must be declared
ORA-06550: line 4, column 19:
PL/SQL: Item ignored
ORA-06550: line 6, column 21:
PLS-00201: identifier 'Y' must be declared
ORA-06550: line 6, column 12:
PL/SQL: Item ignored
ORA-06550: line 10, column 3:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 10, column 3:
PL/SQL: Statement ignored
ORA-06550: line 12, column 3:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 12, column 3:
PL/SQL: Statement ignored
ORA-06550: line 17, column 24:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 14, column 3:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
In the script that you're using to call the procedure, you're using substitution variables. They are replaced by their value before the script is interpreted. This means that a line like V_CREDIT_WORTHY CHAR(3):=&Enter_Credit_Worthy; with the value "no" will be translated into V_CREDIT_WORTHY CHAR(3):=no; You'll notice that "no" is unquoted there. In order to use substitution variables to pass a string to a PL/SQL script, you need to enclose the bind variable in quotes: V_CREDIT_WORTHY CHAR(3):='&Enter_Credit_Worthy';.
An alternative would be to use bind variables. They are interpreted as a part of the script and can therefore be treated as normal variable. To do this, you would simply need to replace the ampersands with colons. The line I referenced above would become V_CREDIT_WORTHY CHAR(3):=:Enter_Credit_Worthy;.
I created a package named sf_timer in sys, then I created a public synonym on this:
create or replace public synonym sf_timer for sys.sf_timer;
select * from all_synonyms where synonym_name = 'SF_TIMER';
Then I call this package from another user:
set serveroutput on
declare
i integer;
j integer;
begin
sf_timer.start_timer;
for i in 1..100000
loop
j := j +1;
end loop;
sf_timer.show_elapsed_time('Test 1');
end;
/
Unfortunately I got error below:
Error report:
ORA-06550: line 5, column 3:
PLS-00201: identifier 'SF_TIMER' must be declared
ORA-06550: line 5, column 3:
PL/SQL: Statement ignored
ORA-06550: line 10, column 3:
PLS-00201: identifier 'SF_TIMER' must be declared
ORA-06550: line 10, column 3:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
I can see this public synonym from all_synonyms but I don't know why I cannot call the package in my schema.
Thanks in advance.
Have you granted permissions?
When running as SYS, do this...
GRANT EXECUTE ON SYS.SF_TIMER TO <user-you're-using>;
As a further note it's generally regarded as bad practise to create objects in the SYS schema :-)