Bad bind variable 'NEW
Hi,
I'm trying to run a script to generate the table. And I'm getting the following error at
create or replace trigger bi_wvufr_applications
before insert on wvufr_applications
for each row
begin
if :new.application_id is null
then select wvufr_applications_seq.nextval
into :new.application_id
from dual;
end if;
:new.created_date := sysdate;
:new.created_by := nvl(wwv_flow.g_user,user);
end;
ERROR at line 7: PLS-00049: bad bind variable 'NEW
Can anybody explain me what I'm doing wrong?
Any help is greatly appreciated
Thanks in advance
- Haritha
Hi,
I'm new to HTML DB and I'm in the initial stage of creating the database(Tables) and I'm getting the above error. Has anybody ran the scripts successfully to generate the tables for Issue Tracking Tutorial? Because the above code snippet for trigger exist in that script. I'm following those scripts to generate the tables and the triggers for my application and I'm getting the above error.
Any help, Please !!
Thanks
- Haritha
Similar Messages
-
Bad bind variable 'NEW.SYS_NC_ROWINFO$
Hi
in order to assist in error resolution when inserting XML data into a XMLTYPE table I have attempted to create a trigger on the table as
SQL> CREATE or replace TRIGGER VALIDATE_PersonAlert3
2 before insert on pa_tab3
3 for each row
4 declare
5 XMLDATA xmltype;
6 begin
7 XMLDATA := :new.sys_nc_rowinfo$;
8 xmltype.schemavalidate(XMLDATA);
9 end;
10 /
Warning: Trigger created with compilation errors.
and get the following
SQL> show errors
Errors for TRIGGER VALIDATE_PERSONALERT3:
4/19 PLS-00049: bad bind variable 'NEW.SYS_NC_ROWINFO$'
SQL> spool off
Anyone know the answer ?
The Trigger example was based on the Oracle 9i XML Developers Guide.
Is there more to adding XDB to database than running catqm.sql ?Hi
To install XDB you should also run catxdbj.sql (in the XDB manual, page A-3, you can find more info...).
I had no problem to create a trigger accoring to the documentation...
Chris -
1. create table t1
(t1ID int,
t1nam varchar2(33)
2. create or replace view t1t2t3
t1id, t1name, t2id, t2nam, t2cty, t2st, aid, aname, bid, bname, t3id, t3nam
as
select * from t1, t2, t1 a, t1 b, t3
where t1.t1ID = t2.id(+)
and T2.CTY = a.t1ID(+)
and t2.sty = b.t1ID(+)
and t1.t1ID = t3.t3id(+)
3. CREATE OR REPLACE TRIGGER t1t2t3
INSTEAD OF INSERT or update
ON t1t2t3
BEGIN
insert into t1
values(:new.t1ID, :new.t1nam);
END t1t2t3;
Get error:
[Error] PLS-00049 (6: 19): PLS-00049: bad bind variable 'NEW.T1NAM'
Pls advise. I am using Toad.
Thanks.tnam1 not belongs to t1t2t3.
:new should be used to te columns of the table on which you are writing the trigger.
Here i think t1t2t3 has t1name field you have to use :new.t1name instead of :new.t1nam(which belongs to table t1) -
PLS-00049: bad bind variable 'NEW.ID' on trigger
Hi guys, I am using Oracle SQL Developer version 2.1.1.64 and having the sql statement like below
CREATE TABLE Zipcodes
zipcode_id NUMBER(10),
zipcode VARCHAR2(10),
district_id NUMBER(10),
PRIMARY KEY(zipcode_id)
CREATE SEQUENCE ZIPCODE_ID_SEQ START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER ZIPCODE_TRIGGER
BEFORE INSERT
ON ZIPCODES
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
SELECT ZIPCODE_ID_SEQ.NEXTVAL INTO :NEW.ZIPCODE_ID FROM DUAL;
END;
And I got errors:
Error(2,40): PLS-00049: bad bind variable 'NEW.ID'
Error(4,5): PL/SQL: Statement ignored
Error(4,39): PLS-00357: Table,View Or Sequence reference 'ZIPCODE_ID_SEQ.NEXTVAL' not allowed in this context
Error(2,36): PLS-00049: bad bind variable 'NEW.ID'
Error(2,2): PL/SQL: SQL Statement ignored
Error(2,9): PL/SQL: ORA-02289: sequence does not exist
Error(5,1): PLS-00103: Encountered the symbol "SHOW"
Firstly, I dont even have the "SHOW" key world in my syntax.
What is it happening ?
Thank you in advance.Hi,
954390 wrote:
Hi guys, I am using Oracle SQL Developer version 2.1.1.64 Thanks; that could be useful information. Even more important is your database version (e.g. 11.2.0.2.0)
and having the sql statement like below
CREATE TABLE Zipcodes
zipcode_id NUMBER(10),
zipcode VARCHAR2(10),
district_id NUMBER(10),
PRIMARY KEY(zipcode_id)
)Don't you need a semicolin or a slash after the CREATE TABLE statement?
CREATE SEQUENCE ZIPCODE_ID_SEQ START WITH 1 INCREMENT BY 1;Did you get a message like "Sequence created" at this point?
CREATE OR REPLACE TRIGGER ZIPCODE_TRIGGER
BEFORE INSERT
ON ZIPCODES
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
SELECT ZIPCODE_ID_SEQ.NEXTVAL INTO :NEW.ZIPCODE_ID FROM DUAL;
END;
And I got errors:
Error(2,40): PLS-00049: bad bind variable 'NEW.ID'
Error(4,5): PL/SQL: Statement ignored
Error(4,39): PLS-00357: Table,View Or Sequence reference 'ZIPCODE_ID_SEQ.NEXTVAL' not allowed in this context
Error(2,36): PLS-00049: bad bind variable 'NEW.ID'
Error(2,2): PL/SQL: SQL Statement ignored
Error(2,9): PL/SQL: ORA-02289: sequence does not exist
Error(5,1): PLS-00103: Encountered the symbol "SHOW"
Firstly, I dont even have the "SHOW" key world in my syntax.
What is it happening ?You don't have anything like NEW.ID, either.
Also, the line numbers in error messages for triggers start with the first DECLARE or BEGIN statement, so this trigger only has 3 lines, yet you're getting line numbers up to 5 in the error messages.
That trigger works fine for me in SQL*Plus (database 10.2.0.1.0).
Are you sure you're showing the complete script, exactly what you're running? If you had some syntax error before the CREATE OR REPLACE TRIGGER statement, that might possibly account for the parser getting confused.
Does your code work in SQL*Plus? -
10/15 PLS-00049: bad bind variable 'NEW.MEMBER'
I have created a view based on 2 tables called member and account which works fine i am then trying to create a trigger to update my member view as
create or replace trigger member_view_update
Instead of update on member_view
for each row
begin
update member set
last_name = :new.last_name,
first_name =:new.first_name,
manager_number= :new.manager_number,
title=:new.title,
address=:new.address,
telephone_1 =:new.telephone_1,
post_code=:new.post_code,
where rowid= :new.member.rowid;
update account set account_balance=:new.account_balance
where rowid=:new.account_rowid;
end;
But this has the following errors
LINE/COL ERROR
2/2 PL/SQL: SQL Statement ignored
10/2 PL/SQL: ORA-01747: invalid user.table.column, table.column, or
column specification
10/15 PLS-00049: bad bind variable 'NEW.MEMBER'
View code
Create or replace view member_view as
select member.rowid member_rowid,
member.member_number,last_name, first_name, manager_number, title, telephone_1, address, post_code,
account.rowid account_rowid,
account_balance
from member, account
WHERE MEMBER.MEMBER_NUMBER = ACCOUNT.MEMBER_NUMBERHello,
I think that you have to replace
where rowid= :new.member.rowid;By
where rowid= :new.member_rowid;Francois -
Error in trigger: PLS-00049: bad bind variable
Hi,
I am trying one of the XML/XDK samples from technet (http://otn.oracle.com/tech/xml/htdocs/XDBDemo2.html) and get this error while compiling the trigger: here's the code snippet
create or replace trigger PURCHASEORDEREXPLOSION
instead of insert on NEWPURCHASEORDER
for each row
declare
begin
DOCUMENT := :new.PODOCUMENT; <--Error here: PLS-00049: bad bind variable 'NEW.PODOCUMENT'
I can't understand why is this happening? Any clues??
Thanks!
-RajeevYou don't specify bind variables with the colon ":" prefix in PL/SQL.
The procedure you posted builds a query using string concatenation. Even if you remove the colon from your variable name you still won't be using bind variables.
If you want to use bind variables you should consider doing the following:
1. Use the DBMS_SQL package.
2. Use EXECUTE IMMEDIATE with the USING clause.
3. Use OPEN <REF CURSOR> FOR <STATEMENT> with the USING clause.
Each one has different advantages/disadvantages.
If looks as if you want to pass in a dynamic IN list. If you use bind variables it will effectively treat the entire list as ONE value enclosed in single quotes. If you truly want a dynamic IN list you need to investigate another method.
Tom Kyte has some information on Dynamic IN lists here: [How can I do a variable in list?|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425] -
Bad bind variable error on creating trigger
hi
im trying to create a trigger on a table in Oracle and I keep gettin this error:
PLS-00049: bad bind variable 'NEW.ID'
TeamID is a primary Key, it creates the sequence fine, but i get the error on the create trigger,
CREATE TABLE TBLTEAMS
TEAMID NUMBER(5),
NAME VARCHAR2(50 BYTE),
MANAGER VARCHAR2(50 BYTE),
COSTCENTRE NUMBER(9),
PARENTTEAMID NUMBER(5)
create sequence seq_Teamsautonumber;
create trigger trg_Teamsautonumber
before insert on tblteams
for each row
begin
select seq_Teamsautonumber.nextval into :new.id from dual;
end;
any ideas?You have said
:new.idthat means you are trying to load the sequence value into a column that doesn't exist in your table.
you would need to use
:new.teamidAssuming you are trying to auto-populate the TEAMID column on your table. -
What's wrong with this script
desc psaudit;
Name Type
AUDIT_OPRID VARCHAR2(30)
AUDIT_STAMP DATE
AUDIT_ACTN VARCHAR2(1)
RECNAME VARCHAR2(15)
FIELDNAME VARCHAR2(18)
OLDVALUE VARCHAR2(65)
NEWVALUE VARCHAR2(65)
KEY1 VARCHAR2(65)
KEY2 VARCHAR2(65)
KEY3 VARCHAR2(65)
KEY4 VARCHAR2(65)
KEY5 VARCHAR2(65)
KEY6 VARCHAR2(65)
KEY7 VARCHAR2(65)
KEY8 VARCHAR2(65)
KEY9 VARCHAR2(65)
KEY10 VARCHAR2(65)
KEY11 VARCHAR2(65)
KEY12 VARCHAR2(65)
KEY13 VARCHAR2(65)
KEY14 VARCHAR2(65)
KEY15 VARCHAR2(65)
22 rows selected
CREATE OR REPLACE TRIGGER JOB_TR
AFTER INSERT OR UPDATE OR DELETE ON PS_JOB_BT
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
V_AUDIT_OPRID VARCHAR2(64);
BEGIN
DBMS_APPLICATION_INFO.READ_CLIENT_INFO(V_AUDIT_OPRID);
IF :OLD.RECNAME IS NULL
THEN
INSERT INTO PSAUDITWRK
VALUES (GET_PS_OPRID(V_AUDIT_OPRID),SYSDATE,'I',:NEWRECNAME,:NEWFIELDNAME,:NEWOLDVALUE,:NEWNEWVALUE,:NEWKEY1,:NEWKEY2,:NEWKEY3,:NEWKEY4,:NEWKEY5,:NEWKEY6,:NEWKEY7,:NEWKEY8,:NEWKEY9,:NEWKEY10,:NEWKEY11,:NEWKEY12,:NEWKEY13,:NEWKEY14,:NEWKEY15);
ELSE
IF :NEWRECNAME IS NULL
THEN
INSERT INTO PSAUDITWRK
VALUES (GET_PS_OPRID(V_AUDIT_OPRID),SYSDATE,'D',:OLD.RECNAME,:OLD.FIELDNAME,:OLD.OLDVALUE,:OLD.NEWVALUE,:OLD.KEY1,:OLD.KEY2,:OLD.KEY3,:OLD.KEY4,:OLD.KEY5,:OLD.KEY6,:OLD.KEY7,:OLD.KEY8,:OLD.KEY9,:OLD.KEY10,:OLD.KEY11,:OLD.KEY12,:OLD.KEY13,:OLD.KEY14,:OLD.KEY15);
ELSE
INSERT INTO PSAUDITWRK
VALUES (GET_PS_OPRID(V_AUDIT_OPRID),SYSDATE,'B',:OLD.RECNAME,:OLD.FIELDNAME,:OLD.OLDVALUE,:OLD.NEWVALUE,:OLD.KEY1,:OLD.KEY2,:OLD.KEY3,:OLD.KEY4,:OLD.KEY5,:OLD.KEY6,:OLD.KEY7,:OLD.KEY8,:OLD.KEY9,:OLD.KEY10,:OLD.KEY11,:OLD.KEY12,:OLD.KEY13,:OLD.KEY14,:OLD.KEY15);
INSERT INTO PSAUDIT
VALUES (GET_PS_OPRID(V_AUDIT_OPRID),SYSDATE,'A',:NEWRECNAME,:NEWFIELDNAME,:NEWOLDVALUE,:NEWNEWVALUE,:NEWKEY1,:NEWKEY2,:NEWKEY3,:NEWKEY4,:NEWKEY5,:NEWKEY6,:NEWKEY7,:NEWKEY8,:NEWKEY9,:NEWKEY10,:NEWKEY11,:NEWKEY12,:NEWKEY13,:NEWKEY14,:NEWKEY15);
END IF;
END IF;
END JOB_TR;
Warning: compiled but with compilation errors
LINE/COL ERROR
5/4 PLS-00049: bad bind variable 'OLD.SYSADM'
8/49 PLS-00049: bad bind variable 'NEW.RECNAME'
8/62 PLS-00049: bad bind variable 'NEW.FIELDNAME'
8/77 PLS-00049: bad bind variable 'NEW.OLDVALUE'
8/91 PLS-00049: bad bind variable 'NEW.NEWVALUE'
8/105 PLS-00049: bad bind variable 'NEW.KEY1'
8/115 PLS-00049: bad bind variable 'NEW.KEY2'
8/125 PLS-00049: bad bind variable 'NEW.KEY3'
8/135 PLS-00049: bad bind variable 'NEW.KEY4'
8/145 PLS-00049: bad bind variable 'NEW.KEY5'
8/155 PLS-00049: bad bind variable 'NEW.KEY6'
LINE/COL ERROR
8/165 PLS-00049: bad bind variable 'NEW.KEY7'
8/175 PLS-00049: bad bind variable 'NEW.KEY8'
8/185 PLS-00049: bad bind variable 'NEW.KEY9'
8/195 PLS-00049: bad bind variable 'NEW.KEY10'
8/206 PLS-00049: bad bind variable 'NEW.KEY11'
8/217 PLS-00049: bad bind variable 'NEW.KEY12'
8/228 PLS-00049: bad bind variable 'NEW.KEY13'
8/239 PLS-00049: bad bind variable 'NEW.KEY14'
8/250 PLS-00049: bad bind variable 'NEW.KEY15'Hi,
Your trigger still don't have any reference to OLD.SYSADM, meaning those compile errors are from something else.
You should
1. Format your trigger (Which you have to some degree)
2. Paste it into SQL*Plus
3. Followed it by alter trigger ... compile
4. And show errors.
5. Paste back everything here
6. Remember to enclose SQL*Plus output in {noformat}{noformat} tags
Regards
Peter
edit:
I take back what I said about formatting. This is how it looks formatted:create or replace trigger job_tr
after insert or update or delete
on ps_job_bt
referencing new as new old as old
for each row
declare
v_audit_oprid varchar2(64);
begin
dbms_application_info.read_client_info(v_audit_oprid);
if :old.recname is null
then
insert into psauditwrk
values (get_ps_oprid(v_audit_oprid)
,sysdate
,'I'
,:newrecname
,:newfieldname
,:newoldvalue
,:newnewvalue
,:newkey1
,:newkey2
,:newkey3
,:newkey4
,:newkey5
,:newkey6
,:newkey7
,:newkey8
,:newkey9
,:newkey10
,:newkey11
,:newkey12
,:newkey13
,:newkey14
,:newkey15);
else
if :newrecname is null
then
insert into psauditwrk
values (get_ps_oprid(v_audit_oprid)
,sysdate
,'D'
,:old.recname
,:old.fieldname
,:old.oldvalue
,:old.newvalue
,:old.key1
,:old.key2
,:old.key3
,:old.key4
,:old.key5
,:old.key6
,:old.key7
,:old.key8
,:old.key9
,:old.key10
,:old.key11
,:old.key12
,:old.key13
,:old.key14
,:old.key15);
else
insert into psauditwrk
values (get_ps_oprid(v_audit_oprid)
,sysdate
,'B'
,:old.recname
,:old.fieldname
,:old.oldvalue
,:old.newvalue
,:old.key1
,:old.key2
,:old.key3
,:old.key4
,:old.key5
,:old.key6
,:old.key7
,:old.key8
,:old.key9
,:old.key10
,:old.key11
,:old.key12
,:old.key13
,:old.key14
,:old.key15);
insert into psaudit
values (get_ps_oprid(v_audit_oprid)
,sysdate
,'A'
,:newrecname
,:newfieldname
,:newoldvalue
,:newnewvalue
,:newkey1
,:newkey2
,:newkey3
,:newkey4
,:newkey5
,:newkey6
,:newkey7
,:newkey8
,:newkey9
,:newkey10
,:newkey11
,:newkey12
,:newkey13
,:newkey14
,:newkey15);
end if;
end if;
end job_tr;
It is immediately seen that this
if :newrecname is null
Should be
if :new.recname is null
And this error isn't even shown in your eledged compile errors.
Edited by: Peter Gjelstrup on Feb 10, 2009 7:00 AM -
please help. I get the below error.
[Error] PLS-00049 (12: 13): PLS-00049: bad bind variable 'NEW.PUBLICATION_DT'
[Error] PLS-00049 (16: 12): PLS-00049: bad bind variable 'OLD.PUBLICATION_DT'
[Error] PLS-00049 (16: 45): PLS-00049: bad bind variable 'NEW.PUBLICATION_DT'
CREATE TABLE PROPOSAL
PROPOSAL_ID NUMBER(18) NOT NULL,
PUBLICATION_DT TIMESTAMP(6),
WORKFLOWPHASE_ID NUMBER(18),
CREATE OR REPLACE TRIGGER TRG_FOR_PROJECT_WORKFLOW
BEFORE INSERT
OR UPDATE
ON PROJECT
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
WHEN (OLD.WORKFLOWPHASE_ID = '15')
BEGIN
If INSERTING THEN
If :NEW.PUBLICATION_DT IS NOT NULL THEN
:NEW.WORKFLOWPHASE_ID := '17';
END IF;
ELSIF UPDATING THEN
If :OLD.PUBLICATION_DT IS NULL AND :NEW.PUBLICATION_DT IS NOT NULL THEN
:NEW.WORKFLOWPHASE_ID := '17';
End If;
END IF;
END;Hi,
Please correct the below
1)The table script you've provided has some errors
2)The trigger you are trying to create is on 'PROJECT' ,I believe it should be on 'PROPOSAL' -
Hi friend,
I do want to use a trigger to update a varchar2 value:
create or replace trigger WORK_STITCH_NAME_TRIG
after insert or update on ASS_WORK_STITCH
for each row
declare
NAME VARCHAR2(100);
begin
if inserting then
select ENAME into NAME from UAMRIS.WORDER where OID=:new.OID;
update UAMRIS.WORDER
set ENAME=(:new.NAME)
where OID=:new.OID;
end if;
end ;
but it gives me error as ':New.Name' bad bind variable.
Can someone help me out with this plz!
Thanks,
Zeeshanuser526055 wrote:
You correction in the trigger created correctly but it is not making any changes to the worder table!If you read my last reply, that was exactly what I said. Now Centinul could be right. Do you have column NAME in triigering table and you want to update WORDER table with column NAME new value? If so, you do not need PL/SQL variable at all:
create or replace trigger WORK_STITCH_NAME_TRIG
after insert or update on ***_WORK_STITCH
for each row
begin
if inserting then
update UAMRIS.WORDER
set ENAME=:new.NAME
where OID=:new.OID;
end if;
end ;
/ SY. -
Hi
I am trying to create a trigger and facing Bad Bind Variable problem.
Plz let me know, what's the problem in this trigger.
CREATE OR REPLACE TRIGGER Tender_tax_update AFTER
INSERT
OR UPDATE
OR DELETE OF ITEM_QTY,ITEM_RATE,TENDER_ACC_QTY ON TENDER_ENQUIRY_ITEM_D REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW
Declare
v_amt TENDER_VENDOR_TAX_D.TAX_AMOUNT%TYPE;
v_tax_ty TENDER_VENDOR_TAX_D.TAX_TYPE%TYPE;
v_tax_cd TENDER_VENDOR_TAX_D.TAX_CODE%TYPE;
v_ven_cd TENDER_VENDOR_TAX_D.VENDOR_CODE%TYPE;
v_item_cd TENDER_VENDOR_TAX_D.item_cd%TYPE;
v_tenno TENDER_VENDOR_TAX_D.tender_enquiry_no%TYPE;
Begin
if inserting then
v_tax_ty:=:new.TAX_TYPE;
v_tax_cd:=:new.TAX_CODE;
v_ven_cd:=:new.vendor_code;
v_item_cd:=:new.item_cd;
v_tenno:=:new.tender_enquiry_no;
select TAX_AMOUNT into v_amt from TENDER_TAX_DETAILS where tender_enquiry_no=v_tenno and TAX_CODE=v_tax_cd and TAX_TYPE=v_tax_ty and item_cd=v_item_cd and vendor_code=v_ven_cd;
update TENDER_VENDOR_TAX_D set TAX_AMOUNT=v_amt where tender_enquiry_no=v_tenno and TAX_CODE=v_tax_cd and TAX_TYPE=v_tax_ty and item_cd=v_item_cd and vendor_code=v_ven_cd;
end if;
End Tender_tax_update;
Database deails are as follows:
TENDER_VENDOR_TAX_D
Name Null? Type
TENDER_ENQUIRY_NO NOT NULL VARCHAR2(8)
VENDOR_CODE NOT NULL VARCHAR2(4)
TAX_CODE NOT NULL VARCHAR2(4)
PERCENTAGE NUMBER(5,2)
TAX_AMOUNT NUMBER(15,2)
ITEM_CD NOT NULL VARCHAR2(10)
TAX_FLAG VARCHAR2(1)
TAX_TYPE CHAR(3)
TENDER_TAX_DETAILS
Name Null? Type
TENDER_ENQUIRY_NO NOT NULL VARCHAR2(8)
VENDOR_CODE VARCHAR2(4)
ITEM_CD VARCHAR2(10)
TAX_CODE NOT NULL VARCHAR2(4)
TAX_TYPE CHAR(3)
TAX_AMOUNT NUMBER
Message was edited by:
user648065facing Band Bind Variable problem.Doesn't the error message tell you which bind variable is the problem?
-
Bad bind variable & best practice for delete
I am working with three tables and very new to SQL. I need to create a procedure that will accept an ID and go through two sub tables and delete child records. Item is the main table. I am passing in the ID into the procedure and I want to use it as below. I keep getting a bad bind variable error message. I have verified that the table is setup as a number and my procedure accepts a number. I also want someone to review this from best practice as I am new to procedures.
PROCEDURE DeleteItem (p_ItemID IN NUMBER, p_RowsAffected OUT number)
IS
p_RowsAffected NUMBER;
-- select the itemdetail for the analysis
CURSOR c_itemdetail
IS
SELECT
itemdetailid
FROM itemDETAIL
WHERE itemid = :p_ItemID;
BEGIN
-- loop through each itemdetail and delete the itemdetailoutlay
FOR r_itemdetail IN c_itemdetail
LOOP
BEGIN
DELETE FROM ITEMDETAILOUTLAY
WHERE itemdetailid = r_itemdetail.itemdetailid;
COMMIT;
END;
END LOOP;
-- delete the itemdetail
BEGIN
DELETE FROM ITEMDETAIL
WHERE itemid = :p_ItemID;
COMMIT;
END;
-- delete the main item
BEGIN
DELETE FROM ITEM
WHERE itemdid = :p_ItemID;
COMMIT;
p_RowsAffected := SQL%ROWCOUNT;
END;
END DeleteItem;Hi,
Welcome to the forum!
As you may notice, this site normally compresses white-space. Whenever you post code, or any formatted text, on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
I don't think you mean to use bind variables anywhere, so don't use colons before any variable names. You were doing this correctly with p_RowsAffected; do the same thing with p_ItemID.
Try this:PROCEDURE DeleteItem (p_ItemID IN NUMBER, p_RowsAffected OUT number)
IS
-- p_RowsAffected NUMBER; -- Don't name local variables the same as arguments
-- select the itemdetail for the analysis
CURSOR c_itemdetail
IS
SELECT
itemdetailid
FROM itemDETAIL
WHERE itemid = p_ItemID; -- No : before p_ItemID
BEGIN
-- loop through each itemdetail and delete the itemdetailoutlay
FOR r_itemdetail IN c_itemdetail
LOOP
BEGIN
DELETE FROM ITEMDETAILOUTLAY
WHERE itemdetailid = r_itemdetail.itemdetailid;
COMMIT;
END;
END LOOP;
-- delete the itemdetail
BEGIN
DELETE FROM ITEMDETAIL
WHERE itemid = p_ItemID; -- No : before p_ItemID
COMMIT;
END;
-- delete the main item
BEGIN
DELETE FROM ITEM
WHERE itemdid = p_ItemID; -- No : before p_ItemID
COMMIT;
p_RowsAffected := SQL%ROWCOUNT;
END;
END DeleteItem;
The most important "best practice" with PL/SQL is to avoid doing it whenever possible.
If SQL offers a way o do the same thing, it's usally best not to code anything in PL/SQL.
Have you considered foreign key constraints, with "ON DELETE CASCADE"? That way, you could simply "DELETE FROM item", and all the dependent rows in the other tables would automatically be deleted. You wouldn't need to remember to call a procedure like this; in fact, you would have no need for a procedure like this.
Given that you do have such a procedure:
You're doing row-by-row processing, which some mad wags like to call "slow-by-slow" processing.
For example, iYou're xplicitly finding each ItemDetailID separately, and deleting each one separately, like this:... CURSOR c_itemdetail
IS
SELECT
itemdetailid
FROM itemDETAIL
WHERE itemid = p_ItemID;
-- loop through each itemdetail and delete the itemdetailoutlay
FOR r_itemdetail IN c_itemdetail
LOOP
BEGIN
DELETE FROM ITEMDETAILOUTLAY
WHERE itemdetailid = r_itemdetail.itemdetailid;
COMMIT;
END;
END LOOP;
It's more efficient for the system (and less coding for you) if you let SQL handle as much as possible, so do this instead... DELETE FROM ItemDetailOutlay
WHERE ItemDetailID IN
( SELECT itemdetailid
FROM itemDETAIL
WHERE itemid = p_ItemID
Do you really want to COMMIT 3 times? 0 or 1 times might be better.
What happens if there is some kind of error, say, after you've delete rows form ItemDetailOutlay and ItemDetail, but before you've delete from Item? Wouldn't you want the entire transaction to fail, and leave all three tables in a consistent state? If so, either have the calling procedure COMMIT, or have a single COMMIT at the end of DelteItem.
Edited by: Frank Kulash on May 6, 2010 2:25 PM -
TRIGGER ERROR: bad bind variable
Hello,
I'm just starting off with oracle and am trying to do the same as auto_increment in mysql is doing by creating this sequence and trigger, but on the trigger I am getting the following error:
error:
PLS-00049: bad bind variable 'TAKEOVER_USERS.TAKEOVER_UID'This is the code for trigger, table and sequence:
trigger:
CREATE OR REPLACE TRIGGER "TAKEOVER_USERS_T1"
BEFORE
insert on "TAKEOVER_USERS"
for each row
begin
select TAKEOVER_UID.nextval into :takeover_users.TAKEOVER_UID from dual;
end;Table:
CREATE TABLE "TAKEOVER_USERS"
( "TAKEOVER_UID" NUMBER NOT NULL ENABLE,
"TAKEOVER_FBID" VARCHAR2(20) NOT NULL ENABLE,
"takeover_accepted_terms" NUMBER(1,1) NOT NULL ENABLE,
"takeover_lastName" VARCHAR2(30),
"takeover_firstName" VARCHAR2(30),
"takeover_country" VARCHAR2(40),
"takeover_session" VARCHAR2(50) NOT NULL ENABLE,
"takeover_created" TIMESTAMP (6) NOT NULL ENABLE,
CONSTRAINT "takeover_users_PK" PRIMARY KEY ("TAKEOVER_UID") ENABLE
)sequence:
CREATE SEQUENCE "TAKEOVER_UID" MINVALUE 1 MAXVALUE 99999999999999 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLEYou got any idea what I need to change to make this work?
Thanks!
Christineif your DB is 11g you can try this
CREATE OR REPLACE TRIGGER "TAKEOVER_USERS_T1"
BEFORE
insert on "TAKEOVER_USERS"
for each row
begin
:NEW.TAKEOVER_UID:=TAKEOVER_UID.nextval;
end;if 10g or older..
CREATE OR REPLACE TRIGGER "TAKEOVER_USERS_T1"
BEFORE
insert on "TAKEOVER_USERS"
for each ROW
BEGIN
SELECT TAKEOVER_UID.NEXTVAL INTO :NEW.TAKEOVER_UID FROM dual;
end;Regards,
Prazy -
Getting Errors in PL/SQL - bad bind variable and encountered the symbol...
CREATE OR REPLACE TRIGGER update_QOH
AFTER INSERT ON ORDERLINE
FOR EACH ROW
DECLARE
QOH_PRODUCT PRODUCT.QOH%TYPE;
BEGIN
SELECT QOH INTO QOH_PRODUCT FROM PRODUCT WHERE :old.product_no = :new.product_no;
IF :new.QTY <= :old.QOH THEN
QOH = :old.QOH - :new.QTY
ELSE
send_email(ord_no, 'Backorder');
INSERT INTO BACKORDER (backorder_no_seq.NEXTVAL, :new.product_no, :new.qty, SYSDATE);
INSERT INTO PRODVENDOR (po_no_seq.NEXTVAL, :new.vendor_no, :new.product_no, :new.vend_qty, :new.shipping_method, SYSDATE, NULL, NULL, NULL);
END IF;
END;
Error(5,17): PLS-00049: bad bind variable 'OLD.QOH'
Error(6,7): PLS-00103: Encountered the symbol "=" when expecting one of the following: := . ( @ % ;
Error(6,9): PLS-00049: bad bind variable 'OLD.QOH'Hi,
Welcome to the forum!
I see 4 mistakes:
851543 wrote:
CREATE OR REPLACE TRIGGER update_QOH
AFTER INSERT ON ORDERLINE
FOR EACH ROW
DECLARE
QOH_PRODUCT PRODUCT.QOH%TYPE;
BEGIN
SELECT QOH INTO QOH_PRODUCT FROM PRODUCT WHERE :old.product_no = :new.product_no;
IF :new.QTY <= :old.QOH THEN
QOH = :old.QOH - :new.QTY(1) The variable qoh isn't declared.
(2) Did you mean the assignment operator, :=, rather than the equality operator, = ?
(3) An assignment statement must end with a semi-colon.
ELSE
send_email(ord_no, 'Backorder');(4) The variable ord_no isn't declared.
INSERT INTO BACKORDER (backorder_no_seq.NEXTVAL, :new.product_no, :new.qty, SYSDATE);
INSERT INTO PRODVENDOR (po_no_seq.NEXTVAL, :new.vendor_no, :new.product_no, :new.vend_qty, :new.shipping_method, SYSDATE, NULL, NULL, NULL);
END IF;
END;
/While you can reference :NEW and :OLD values in the trigger, it doesn't make any sense to reference the :OLD values. On an INSERT (which is the only time this trigger fires), all :OLD values are NULL.
>
Error(5,17): PLS-00049: bad bind variable 'OLD.QOH'
Error(6,7): PLS-00103: Encountered the symbol "=" when expecting one of the following: := . ( @ % ;
Error(6,9): PLS-00049: bad bind variable 'OLD.QOH'I don't believe the code you posted is causing these errors. Each of the errors mentioned above would cause a different message. Post the actual code and error messages.
Whenever you post a question, post all the code necessary for people to re-create the problem and test their ideas.
In this case, that means CREATE statements for any tables or sequences involved, INSERT statements for any tables that need rows (such as product) as they exist before the INSERT, some INSERT statements for orderline, and the contents of all the tables after each of those INSERTs.
Always say which version of Oracle you're using. -
Hi all,
I have created new form based on View.If i'm trying to update the values in base tables,but it is showing me the
Error :BAD BIND VARIABLES 'cs_estimate_details.attribute2'
WHEN-BUTTON-PRESSED i'm writing the code like this
:block_name.item_name := :base_table.column_name;
:xx_discount_manager_v.discount_rate := :cs_estimate_details.attribute2 ;
Can i directly apply into base tables or not ,if any solution plss help me in this,urget
if any bosy having code and which trigger used pls let me know
Regards
SivaIf you want to updated the contents of the view from your form which is based on the view you may want to consider using the "instead of" trigger on the view.
Regards,
Tony
@ Gerd
Welcome back :)
Maybe you are looking for
-
When I export to pdf from indesign 4 the jpg's come out as grey box
However when I use the print to pdf file it is ok. Someone was playing with my acrobat distiller a few days ago to view some artwork in a particular way, is it something to do with this and anyone know what they may have changed. I have never had a p
-
I updated my daughter's nano on Sunday with a software update and then trie to update my touch with new songs but my touch was not able to connect because the apple mobile device was not started. I checked the help section on itunes and uninstalled a
-
Multi color around edges what is it and how to get rid of it
What is the term for a multicolor fringe around an edge..how do you get rid of it Capt
-
Finished DVD Momentarily Hangs In Two Places
I have created a 33 minute slide show in Aperture 3. The show is very good quality but it hangs in two places on the burned DVD. Have dragged plist to trash, exported again, burned disk appromimately 7 times, and each time I get the same thing. It hu
-
Synchronizing caption info in Metadata
Can I synchronize Caption info in Metadata across multiple computers? Our Master images are located on a server at my studio. If I add a caption to an image from my computer, then go to another computer in my studio, and synchronize the folder that t