Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically accessing field items

Status
Not open for further replies.

hs92

Programmer
Nov 7, 2000
11
0
0
US

I am trying to dynamically access the data in :eek:ld and :new fields without having to use the literal :eek:ld.field and :new.field.

The trigger below shows 2 ways of calling the p_addnote procedure. The first, now commented out, works by making a direct call of p_addnote with the literal data.
This works. In the second call I have called a second procedure that will dynamically create the call to p_addnote. This doesn’t work as I can’t access the :new or :eek:ld data.

Is it possible to dynamically get the data that is in the :new and :eek:ld field?


CREATE TRIGGER tr_update
BEFORE UPDATE
ON accounts
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
v_ntype users.notetype%TYPE;
Begin
SELECT notetype
INTO v_ntype
FROM users
WHERE code = lower(user);

IF :new.tb_company != :eek:ld.tb_company THEN
/*
p_addnote:)old.tb_accountid,'AUD',
'Company ''' || substr:)old.tb_company,1,29) ||''' changed by ' || lower(USER) || '.',
v_ntype,0);
p_addnote:)new.tb_accountid,'AUD',
'The new Company is ''' || substr:)new.company,1,29) ||'''' ,
v_ntype,0);

*/
p_updnote('tb_accountid','tb_company','AUD','Company',v_ntype);
END IF;
END tr_update;



CREATE OR REPLACE PROCEDURE p_updnote
(
p_accountid unotes_bcs.not_accountid%TYPE,
p_field VARCHAR2,
p_code unotes_bcs.not_notecode%TYPE,
p_text unotes_bcs.not_text%TYPE,
p_user unotes_bcs.not_user%TYPE
)
IS
v_newfield VARCHAR2(20);
v_oldfield VARCHAR2(20);
BEGIN
v_newfield := ':new.' || p_field;
v_oldfield := ':eek:ld.' || p_field;
p_addnote(p_accountid,p_code,p_text || '''' || v_oldfield || ''' changed by ' || lower(user) || '.',p_user);
p_addnote(p_accountid,p_code,'The new ' || p_text || 'is ''' || v_newfield || '''',p_user);
END p_updnote ;




PROCEDURE P_addnote
(
p_accountid unotes_bcs.not_accountid%TYPE,
p_code unotes_bcs.not_notecode%TYPE,
p_text unotes_bcs.not_text%TYPE,
p_user1 unotes_bcs.not_user%TYPE
)
IS
BEGIN
INSERT INTO tb_audit
(
not_accountid, not_dateofca, not_timeofca, not_text,
not_notecode, not_user, update_not, uptime_not, locked_not
)
VALUES
(
p_accountid, SYSDATE, p_text, p_code, p_user1
);
END;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top