dbTalk Databases Forums  

Can this be done with a trigger?

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Can this be done with a trigger? in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
artmerar@yahoo.com
 
Posts: n/a

Default Can this be done with a trigger? - 08-05-2008 , 11:11 AM






Hi,

We have a table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
DATE_ADDED
DATE_MODIFIED

We also have a history table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
SOURCE
DATE_ADDED

We want to put a trigger on the first table such that when a record is
inserted or updated it will make the entry to the history table.
However, the problem is the 'SOURCE' column on the history table. It
is not present or needed in the first table.

Entries into the first table are done through a PL/SQL program. So,
what we want is that when the entry is made into the first table, it
fires the trigger to make the second entry. But, how can this be done
if the columns do not match?

We do not want to code it in the PL/SQL program because then someone
can make an entry to the first table and we cannot record the history
on it, yet the SOURCE column only gets populated in the PL/SQL
program....

And, to make things more complicated, depending on what is being
UPDATED, we may need the values of :NEW or :OLD........

Is there a way to do this?

Reply With Quote
  #2  
Old   
gazzag
 
Posts: n/a

Default Re: Can this be done with a trigger? - 08-05-2008 , 11:43 AM






On 5 Aug, 17:11, artme... (AT) yahoo (DOT) com wrote:
Quote:
Hi,

We have a table like this:

*CUSTOMER_ID
*PRODUCT_ID
*FORMAT
*STATUS
*DATE_ADDED
*DATE_MODIFIED

We also have a history table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
SOURCE
DATE_ADDED

We want to put a trigger on the first table such that when a record is
inserted or updated it will make the entry to the history table.
However, the problem is the 'SOURCE' column on the history table. *It
is not present or needed in the first table.

Entries into the first table are done through a PL/SQL program. *So,
what we want is that when the entry is made into the first table, it
fires the trigger to make the second entry. *But, how can this be done
if the columns do not match?

We do not want to code it in the PL/SQL program because then someone
can make an entry to the first table and we cannot record the history
on it, yet the SOURCE column only gets populated in the PL/SQL
program....

And, to make things more complicated, depending on what is being
UPDATED, we may need the values of :NEW or :OLD........

Is there a way to do this?
Sure there is. What is SOURCE though?


Reply With Quote
  #3  
Old   
gazzag
 
Posts: n/a

Default Re: Can this be done with a trigger? - 08-05-2008 , 11:43 AM



On 5 Aug, 17:11, artme... (AT) yahoo (DOT) com wrote:
Quote:
Hi,

We have a table like this:

*CUSTOMER_ID
*PRODUCT_ID
*FORMAT
*STATUS
*DATE_ADDED
*DATE_MODIFIED

We also have a history table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
SOURCE
DATE_ADDED

We want to put a trigger on the first table such that when a record is
inserted or updated it will make the entry to the history table.
However, the problem is the 'SOURCE' column on the history table. *It
is not present or needed in the first table.

Entries into the first table are done through a PL/SQL program. *So,
what we want is that when the entry is made into the first table, it
fires the trigger to make the second entry. *But, how can this be done
if the columns do not match?

We do not want to code it in the PL/SQL program because then someone
can make an entry to the first table and we cannot record the history
on it, yet the SOURCE column only gets populated in the PL/SQL
program....

And, to make things more complicated, depending on what is being
UPDATED, we may need the values of :NEW or :OLD........

Is there a way to do this?
Sure there is. What is SOURCE though?


Reply With Quote
  #4  
Old   
gazzag
 
Posts: n/a

Default Re: Can this be done with a trigger? - 08-05-2008 , 11:43 AM



On 5 Aug, 17:11, artme... (AT) yahoo (DOT) com wrote:
Quote:
Hi,

We have a table like this:

*CUSTOMER_ID
*PRODUCT_ID
*FORMAT
*STATUS
*DATE_ADDED
*DATE_MODIFIED

We also have a history table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
SOURCE
DATE_ADDED

We want to put a trigger on the first table such that when a record is
inserted or updated it will make the entry to the history table.
However, the problem is the 'SOURCE' column on the history table. *It
is not present or needed in the first table.

Entries into the first table are done through a PL/SQL program. *So,
what we want is that when the entry is made into the first table, it
fires the trigger to make the second entry. *But, how can this be done
if the columns do not match?

We do not want to code it in the PL/SQL program because then someone
can make an entry to the first table and we cannot record the history
on it, yet the SOURCE column only gets populated in the PL/SQL
program....

And, to make things more complicated, depending on what is being
UPDATED, we may need the values of :NEW or :OLD........

Is there a way to do this?
Sure there is. What is SOURCE though?


Reply With Quote
  #5  
Old   
gazzag
 
Posts: n/a

Default Re: Can this be done with a trigger? - 08-05-2008 , 11:43 AM



On 5 Aug, 17:11, artme... (AT) yahoo (DOT) com wrote:
Quote:
Hi,

We have a table like this:

*CUSTOMER_ID
*PRODUCT_ID
*FORMAT
*STATUS
*DATE_ADDED
*DATE_MODIFIED

We also have a history table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
SOURCE
DATE_ADDED

We want to put a trigger on the first table such that when a record is
inserted or updated it will make the entry to the history table.
However, the problem is the 'SOURCE' column on the history table. *It
is not present or needed in the first table.

Entries into the first table are done through a PL/SQL program. *So,
what we want is that when the entry is made into the first table, it
fires the trigger to make the second entry. *But, how can this be done
if the columns do not match?

We do not want to code it in the PL/SQL program because then someone
can make an entry to the first table and we cannot record the history
on it, yet the SOURCE column only gets populated in the PL/SQL
program....

And, to make things more complicated, depending on what is being
UPDATED, we may need the values of :NEW or :OLD........

Is there a way to do this?
Sure there is. What is SOURCE though?


Reply With Quote
  #6  
Old   
artmerar@yahoo.com
 
Posts: n/a

Default Re: Can this be done with a trigger? - 08-05-2008 , 11:48 AM



On Aug 5, 11:43 am, gazzag <gar... (AT) jamms (DOT) org> wrote:
Quote:
On 5 Aug, 17:11, artme... (AT) yahoo (DOT) com wrote:



Hi,

We have a table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
DATE_ADDED
DATE_MODIFIED

We also have a history table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
SOURCE
DATE_ADDED

We want to put a trigger on the first table such that when a record is
inserted or updated it will make the entry to the history table.
However, the problem is the 'SOURCE' column on the history table. It
is not present or needed in the first table.

Entries into the first table are done through a PL/SQL program. So,
what we want is that when the entry is made into the first table, it
fires the trigger to make the second entry. But, how can this be done
if the columns do not match?

We do not want to code it in the PL/SQL program because then someone
can make an entry to the first table and we cannot record the history
on it, yet the SOURCE column only gets populated in the PL/SQL
program....

And, to make things more complicated, depending on what is being
UPDATED, we may need the values of :NEW or :OLD........

Is there a way to do this?

Sure there is. What is SOURCE though?
Gazzag,

I am trying to write the trigger. Problem is since you cannot pass
parameters to triggers, where does the trigger get the value for
SOURCE? All I can think of is to update the record from the PL/SQL
procedure once the trigger gets done........

So, say I have a procedure like this:

PROCEDURE ADD (
p_customer_id NUMBER,
p_product_id VARCHAR2,
p_source VARCHAR2 DEFAULT 'U') IS

INSERT INTO customer_config
VALUES (p_customer_id, p_product_id, 'Text', 'Active', SYSDATE);

The SOURCE is not needed in this table. But, this would fire the
trigger where SOURCE is needed. The SOURCE will be derived within the
PL/SQL code. I do not think this is possible. I may have to let the
trigger fire, then go back and update the row.....



Reply With Quote
  #7  
Old   
artmerar@yahoo.com
 
Posts: n/a

Default Re: Can this be done with a trigger? - 08-05-2008 , 11:48 AM



On Aug 5, 11:43 am, gazzag <gar... (AT) jamms (DOT) org> wrote:
Quote:
On 5 Aug, 17:11, artme... (AT) yahoo (DOT) com wrote:



Hi,

We have a table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
DATE_ADDED
DATE_MODIFIED

We also have a history table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
SOURCE
DATE_ADDED

We want to put a trigger on the first table such that when a record is
inserted or updated it will make the entry to the history table.
However, the problem is the 'SOURCE' column on the history table. It
is not present or needed in the first table.

Entries into the first table are done through a PL/SQL program. So,
what we want is that when the entry is made into the first table, it
fires the trigger to make the second entry. But, how can this be done
if the columns do not match?

We do not want to code it in the PL/SQL program because then someone
can make an entry to the first table and we cannot record the history
on it, yet the SOURCE column only gets populated in the PL/SQL
program....

And, to make things more complicated, depending on what is being
UPDATED, we may need the values of :NEW or :OLD........

Is there a way to do this?

Sure there is. What is SOURCE though?
Gazzag,

I am trying to write the trigger. Problem is since you cannot pass
parameters to triggers, where does the trigger get the value for
SOURCE? All I can think of is to update the record from the PL/SQL
procedure once the trigger gets done........

So, say I have a procedure like this:

PROCEDURE ADD (
p_customer_id NUMBER,
p_product_id VARCHAR2,
p_source VARCHAR2 DEFAULT 'U') IS

INSERT INTO customer_config
VALUES (p_customer_id, p_product_id, 'Text', 'Active', SYSDATE);

The SOURCE is not needed in this table. But, this would fire the
trigger where SOURCE is needed. The SOURCE will be derived within the
PL/SQL code. I do not think this is possible. I may have to let the
trigger fire, then go back and update the row.....



Reply With Quote
  #8  
Old   
artmerar@yahoo.com
 
Posts: n/a

Default Re: Can this be done with a trigger? - 08-05-2008 , 11:48 AM



On Aug 5, 11:43 am, gazzag <gar... (AT) jamms (DOT) org> wrote:
Quote:
On 5 Aug, 17:11, artme... (AT) yahoo (DOT) com wrote:



Hi,

We have a table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
DATE_ADDED
DATE_MODIFIED

We also have a history table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
SOURCE
DATE_ADDED

We want to put a trigger on the first table such that when a record is
inserted or updated it will make the entry to the history table.
However, the problem is the 'SOURCE' column on the history table. It
is not present or needed in the first table.

Entries into the first table are done through a PL/SQL program. So,
what we want is that when the entry is made into the first table, it
fires the trigger to make the second entry. But, how can this be done
if the columns do not match?

We do not want to code it in the PL/SQL program because then someone
can make an entry to the first table and we cannot record the history
on it, yet the SOURCE column only gets populated in the PL/SQL
program....

And, to make things more complicated, depending on what is being
UPDATED, we may need the values of :NEW or :OLD........

Is there a way to do this?

Sure there is. What is SOURCE though?
Gazzag,

I am trying to write the trigger. Problem is since you cannot pass
parameters to triggers, where does the trigger get the value for
SOURCE? All I can think of is to update the record from the PL/SQL
procedure once the trigger gets done........

So, say I have a procedure like this:

PROCEDURE ADD (
p_customer_id NUMBER,
p_product_id VARCHAR2,
p_source VARCHAR2 DEFAULT 'U') IS

INSERT INTO customer_config
VALUES (p_customer_id, p_product_id, 'Text', 'Active', SYSDATE);

The SOURCE is not needed in this table. But, this would fire the
trigger where SOURCE is needed. The SOURCE will be derived within the
PL/SQL code. I do not think this is possible. I may have to let the
trigger fire, then go back and update the row.....



Reply With Quote
  #9  
Old   
artmerar@yahoo.com
 
Posts: n/a

Default Re: Can this be done with a trigger? - 08-05-2008 , 11:48 AM



On Aug 5, 11:43 am, gazzag <gar... (AT) jamms (DOT) org> wrote:
Quote:
On 5 Aug, 17:11, artme... (AT) yahoo (DOT) com wrote:



Hi,

We have a table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
DATE_ADDED
DATE_MODIFIED

We also have a history table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
SOURCE
DATE_ADDED

We want to put a trigger on the first table such that when a record is
inserted or updated it will make the entry to the history table.
However, the problem is the 'SOURCE' column on the history table. It
is not present or needed in the first table.

Entries into the first table are done through a PL/SQL program. So,
what we want is that when the entry is made into the first table, it
fires the trigger to make the second entry. But, how can this be done
if the columns do not match?

We do not want to code it in the PL/SQL program because then someone
can make an entry to the first table and we cannot record the history
on it, yet the SOURCE column only gets populated in the PL/SQL
program....

And, to make things more complicated, depending on what is being
UPDATED, we may need the values of :NEW or :OLD........

Is there a way to do this?

Sure there is. What is SOURCE though?
Gazzag,

I am trying to write the trigger. Problem is since you cannot pass
parameters to triggers, where does the trigger get the value for
SOURCE? All I can think of is to update the record from the PL/SQL
procedure once the trigger gets done........

So, say I have a procedure like this:

PROCEDURE ADD (
p_customer_id NUMBER,
p_product_id VARCHAR2,
p_source VARCHAR2 DEFAULT 'U') IS

INSERT INTO customer_config
VALUES (p_customer_id, p_product_id, 'Text', 'Active', SYSDATE);

The SOURCE is not needed in this table. But, this would fire the
trigger where SOURCE is needed. The SOURCE will be derived within the
PL/SQL code. I do not think this is possible. I may have to let the
trigger fire, then go back and update the row.....



Reply With Quote
  #10  
Old   
Dan Blum
 
Posts: n/a

Default Re: Can this be done with a trigger? - 08-05-2008 , 12:09 PM



artmerar (AT) yahoo (DOT) com wrote:
Quote:
On Aug 5, 11:43 am, gazzag <gar... (AT) jamms (DOT) org> wrote:
On 5 Aug, 17:11, artme... (AT) yahoo (DOT) com wrote:



Hi,

We have a table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
DATE_ADDED
DATE_MODIFIED

We also have a history table like this:

CUSTOMER_ID
PRODUCT_ID
FORMAT
STATUS
SOURCE
DATE_ADDED

We want to put a trigger on the first table such that when a record is
inserted or updated it will make the entry to the history table.
However, the problem is the 'SOURCE' column on the history table. It
is not present or needed in the first table.

Entries into the first table are done through a PL/SQL program. So,
what we want is that when the entry is made into the first table, it
fires the trigger to make the second entry. But, how can this be done
if the columns do not match?

We do not want to code it in the PL/SQL program because then someone
can make an entry to the first table and we cannot record the history
on it, yet the SOURCE column only gets populated in the PL/SQL
program....

And, to make things more complicated, depending on what is being
UPDATED, we may need the values of :NEW or :OLD........

Is there a way to do this?

Sure there is. What is SOURCE though?

Gazzag,

I am trying to write the trigger. Problem is since you cannot pass
parameters to triggers, where does the trigger get the value for
SOURCE? All I can think of is to update the record from the PL/SQL
procedure once the trigger gets done........

So, say I have a procedure like this:

PROCEDURE ADD (
p_customer_id NUMBER,
p_product_id VARCHAR2,
p_source VARCHAR2 DEFAULT 'U') IS

INSERT INTO customer_config
VALUES (p_customer_id, p_product_id, 'Text', 'Active', SYSDATE);

The SOURCE is not needed in this table. But, this would fire the
trigger where SOURCE is needed. The SOURCE will be derived within the
PL/SQL code. I do not think this is possible. I may have to let the
trigger fire, then go back and update the row.....
And if someone inserts a row in the table without using the PL/SQL program
(the scenario you were worried about above), how does SOURCE get populated?
The trigger has to be able to assume a value for SOURCE, or this will not
work.

--
__________________________________________________ _____________________
Dan Blum tool (AT) panix (DOT) com
"I wouldn't have believed it myself if I hadn't just made it up."


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.