ALTER TRIGGER
Dear Sir,
When I execute Alter Trigger MyDB.Trigger_XXX,
I get the following error:
ORA-00604: error occurred at recursive SQL level 1
ORA-10405:fetched column value is NULL
MyDB.Trigger_XXX is pasted bellow:
DECLARE hash_id_count integer;
hash_id_num NUMBER(38);
BEGIN
. .IF DBMS_REPUTIL.FROM_REMOTE = FALSE THEN
. .. .IF :new.REASON_CODE != 6 THEN
. .. .. .SELECT HASH_ID INTO hash_id_num
. .. .. .. .FROM DNAME_REUSE_TBL
. .. .. .. .WHERE
. .. .. .. .. .CERT_SERIAL_NUM = :new.CERT_SERIAL_NUM AND
. .. .. .. .. .CA_DN_ID = :new.CA_DN_ID;
. .. .. .DELETE
. .. .. .. .FROM DNAME_REUSE_TBL
. .. .. .. .WHERE
. .. .. .. .. .CERT_SERIAL_NUM = :new.CERT_SERIAL_NUM AND
. .. .. .. .. .CA_DN_ID = :new.CA_DN_ID;
. .. .. .SELECT COUNT(HASH_ID) INTO hash_id_count
. .. .. .. .FROM DNAME_REUSE_TBL
. .. .. .. .WHERE HASH_ID = hash_id_num;
. .. .. .IF hash_id_count = 0 THEN
. .. .. .. .DELETE
. .. .. .. .. .FROM UNIQUE_DNAME_CHECK_TBL
. .. .. .. .. .WHERE DNAME_HASH_ID = hash_id_num;
. .. .. .END IF;
. .. .END IF;
. .END IF;
END;
Many Thanks
Xueliang
Message was edited by:
Xueliang
Hi,
>>When I execute Alter Trigger MyDB.Trigger_XXX,
Clarify, alter trigger ... compile ??
Did you try put on your SQL select "where" clause "AND HASH_ID IS NOT NULL" ?
Cheers
Similar Messages
-
Hi All,
I have triggers creating in one schema. I want to edit the triggers now and recompile them, but when I do this, it prompts to me INSUFFICIENT PRIVILEGES. I am able to edit and recompile the packages, procedures and function but not the triggers. How can I check whether I have the privilege to alter the trigger or not to the same schema. And if no privilege is there, then please let me know what is the command to give the PRIVILEGE for ALTER TRIGGER.
Thanks in advanceCheck your system privileges with:
select * from session_privs;See ALTER TRIGGER in SQL Reference http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_4001.htm#SQLRF01101:
>
The trigger must be in your own schema or you must have ALTER ANY TRIGGER system privilege.
In addition, to alter a trigger on DATABASE, you must have the ADMINISTER database events system privilege.
>
Trigger schema owner or DBA like account must run:
grant alter any trigger to <your account>;Edited by: P. Forstmann on 22 nov. 2010 13:40 -
Dear all,
I have a trigger on a table in schemaA.I have grant all on table to schemaB. If I login with schemaB, I was not able to disable the trigger of schemaA. It gave the error,
ORA-04080: trigger 'blah_blah' does not existPlease help me out. I will explain the problem in detail below.
I'm running a flow in Informatica powercenter with a different user from the target table schema owner. I should use a batch user to run the flow which is not the owner. But I want to disable the trigger on the table before I perform the flow and that can be handled using pre SQL in Power Center Designer. But when I ran the flow, I got this error. I tried it even in SQL*Plus by logging in as schemaB and tried to disable. I got this error. Is there anyway out of this?
If the problem gets solved by granting some permissions to schemaB, I'm ready for that. I want gurus to help me out. Is there something called
GRANT DISABLE TRIGGER ON trigger_name TO target_userCheers
DeepaYou may not really want that TRIGGER disabled, as it's disabled for everyone. If you just want to bypass the functionality in the trigger, use a package spec variable (pseudocode, so there are errors I'm sure):
create package global_variables
as
skip_trigger boolean := FALSE;
end global_variables;
create trigger my_trigger_brt
before insert or update or delete
on my_table
for each row
procedure main as
if global_variables.skip_trigger then
return;
end if;
end main;
begin
main;
end;
create trigger my_trigger_ast
after insert or update or delete
on my_table
begin
global_variables.skip_trigger := FALSE;
end;
/-cf -
Recover DDL of altered trigger
Hello everybody,
I've accidentally replaced an existing trigger without taking the back-up of older one on oracle 10g.
Now I wonder if I can get the DDL of older trigger back.
thanks,
Rossy.RocsI just tried your test case but its worked!
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Prod
PL/SQL Release 10.2.0.2.0 - Production
CORE 10.2.0.2.0 Production
TNS for 32-bit Windows: Version 10.2.0.2.0 - Production
NLSRTL Version 10.2.0.2.0 - Production
SQL>
SQL> conn nishant/nis
Connected.
SQL> CREATE TABLE orders (
2 somecolumn VARCHAR2(20),
3 numbercol NUMBER(10),
4 datecol DATE);
Table created.
SQL> CREATE OR REPLACE TRIGGER statement_level
2 BEFORE UPDATE
3 ON orders
4 DECLARE
5 vMsg VARCHAR2(30) := 'Statement Level Trigge
6 BEGIN
7 dbms_output.put_line(vMsg);
8 END statement_level;
9 /
Trigger created.
SQL> set time on
10:10:32 SQL> CREATE OR REPLACE TRIGGER statement_level
10:10:37 2 BEFORE UPDATE
10:10:37 3 ON orders
10:10:37 4 DECLARE
10:10:37 5 vMsg VARCHAR2(30) := 'Statement Level Trigger Fired';
10:10:37 6 BEGIN
10:10:37 7 dbms_output.put_line(vMsg);
10:10:37 8 dbms_output.put_line('A line added'); <--- just made one change here
10:10:37 9 END statement_level;
10:10:37 10 /
Trigger created.
SQL> set time on
10:12:19 SQL> CONN / AS SYSDBA
10:14:06 SQL> SELECT TEXT FROM DBA_SOURCE WHERE NAME='STATEMENT_LEVEL';
TEXT
TRIGGER statement_level
BEFORE UPDATE
ON orders
DECLARE
vMsg VARCHAR2(30) := 'Statement Level Trigger Fired';
BEGIN
dbms_output.put_line(vMsg);
dbms_output.put_line('A line added');
END statement_level;
9 rows selected.
10:14:41 SQL>
10:15:36 SQL> SELECT TEXT FROM DBA_SOURCE as of timestamp to_timestamp('19-jan-2
010 10:09','dd-mon-yyyy hh24:mi') WHERE NAME='STATEMENT_LEVEL';
TEXT
TRIGGER statement_level
BEFORE UPDATE
ON orders
DECLARE
vMsg VARCHAR2(30) := 'Statement Level Trigger Fired';
BEGIN
dbms_output.put_line(vMsg);
END statement_level;
8 rows selected.
10:18:47 SQL> drop trigger nishant.statement_level;
Trigger dropped.
10:19:03 SQL> SELECT TEXT FROM DBA_SOURCE as of timestamp to_timestamp('19-jan-2
010 10:10','dd-mon-yyyy hh24:mi') WHERE NAME='STATEMENT_LEVEL';
TEXT
TRIGGER statement_level
BEFORE UPDATE
ON orders
DECLARE
vMsg VARCHAR2(30) := 'Statement Level Trigger Fired';
BEGIN
dbms_output.put_line(vMsg);
END statement_level;
8 rows selected.
10:19:12 SQL> SELECT TEXT FROM DBA_SOURCE as of timestamp to_timestamp('19-jan-2
010 10:11','dd-mon-yyyy hh24:mi') WHERE NAME='STATEMENT_LEVEL';
TEXT
TRIGGER statement_level
BEFORE UPDATE
ON orders
DECLARE
vMsg VARCHAR2(30) := 'Statement Level Trigger Fired';
BEGIN
dbms_output.put_line(vMsg);
dbms_output.put_line('A line added');
END statement_level;
9 rows selected.
10:19:23 SQL>Thanks
Nishant -
How to get the table name in the trigger definition without hard coding.
CREATE TRIGGER db.mytablename
AFTER UPDATE,INSERT
AS
INSERT INTO table1(col1)
SELECT InsRec.col1
FROM
INSERTED Ins
--Below i am calling one sp for which i have to pass the table name
EXEC myspname 'tablename'
In the above trigger,presently i am hard coding the tablename
but is it possible to get the table name dynamically on which the trigger is defined in order to avoid hard coding the table nameI really liked your audit table concept. You inspired me to modify it so that, the entire recordset gets captured and added a couple of other fields. Wanted to share my end result.
USE [YourDB]
GO
/****** Object: Trigger [dbo].[iudt_AutoAuditChanges] Script Date: 10/18/2013 12:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[iudt_AutoAuditChanges]
ON [dbo].[YourTable]
AFTER INSERT,DELETE,UPDATE
AS
BEGIN
SET NOCOUNT ON;
Declare @v_AuditID bigint
IF OBJECT_ID('dbo.AutoAudit','U') IS NULL BEGIN
CREATE TABLE [dbo].[AutoAudit]
( [AuditID] bigint identity,
[AuditDate] DateTime,
[AuditUserName] varchar(128),
[TableName] varchar(128) NULL,
[OldContent] XML NULL,
[NewContent] XML NULL
ALTER TABLE dbo.AutoAudit ADD CONSTRAINT
PK_AutoAudit PRIMARY KEY CLUSTERED
[AuditID]
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [idx_AutoAudit_TableName_AuditDate] ON [dbo].[AutoAudit]
( [TableName] ASC,
[AuditDate] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
Select * Into #AuditDeleted from deleted
Select * Into #AuditInserted from inserted
While (Select COUNT(*) from #AuditDeleted) > 0 OR (Select COUNT(*) from #AuditInserted) > 0
Begin
INSERT INTO [dbo].[AutoAudit]
( [AuditDate], [AuditUserName], [TableName], [OldContent], [NewContent])
SELECT
GETDATE(),
SUSER_NAME(),
[TableName]=object_name([parent_obj]),
[OldContent]=CAST((SELECT TOP 1 * FROM #AuditDeleted D FOR XML RAW) AS XML),
[NewContent]=CAST((SELECT TOP 1 * FROM #AuditInserted I FOR XML RAW) AS XML)
FROM sysobjects
WHERE
[xtype] = 'tr'
and [name] = OBJECT_NAME(@@PROCID)
Set @v_AuditID = SCOPE_IDENTITY()
Delete from AutoAudit
Where AuditID = @v_AuditID
AND Convert(varchar(max),oldContent) = Convert(varchar(max),NewContent)
Delete top(1) from #AuditDeleted
Delete top(1) from #AuditInserted
End
END -
ORA-00922: missing or invalid option in create seq, trigger
Hi All,
I am trying to create a table, sequence, and trigger with the following SQL and am getting the error:
ORA-00922: missing or invalid option
CREATE TABLE "DATA_INVENTORY"
( "ID" INTEGER NOT NULL ENABLE,
"COE_CONTRACT_NUM" VARCHAR2(30),
"PROJ_AREA" VARCHAR2(30),
"STATE" VARCHAR2(30),
"DATA_DATE" VARCHAR2(30) NOT NULL ENABLE,
"NUM_OF_MEDIA" NUMBER,
"DATA_TYPE" VARCHAR2(30)NOT NULL ENABLE,
"MEDIA_TYPE" VARCHAR2(30)NOT NULL ENABLE,
"EXTERNAL_DRIVE_DESCR" VARCHAR2(200),
"ROOM_NUM" VARCHAR2(10)NOT NULL ENABLE,
"DRAWER_NUM" VARCHAR2(30),
"PROJ_CODE" VARCHAR2(30),
"COMPANY" VARCHAR2(30),
"DESCRIPTION" VARCHAR2(200),
"NOTES" VARCHAR2(500),
"INDEX" VARCHAR2(30),
"INDEX_LINK" VARCHAR2(75),
"DATA_LINK" VARCHAR2(75),
"METADATA" VARCHAR2(75),
"METADATA_LINK" VARCHAR2(75),
"DISTRIBUTE" VARCHAR2(30)NOT NULL ENABLE,
"CORPORATE" VARCHAR2(1)NOT NULL ENABLE,
CONSTRAINT "DATA_INVENTORY_PK" PRIMARY KEY ("ID") ENABLE,
CONSTRAINT "DATA_INVENTORY_UK1" UNIQUE ("COE_CONTRACT_NUM", "PROJ_AREA") ENABLE
CREATE SEQUENCE "DATA_INVENTORY_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 324 CACHE 20 NOORDER NOCYCLE
CREATE OR REPLACE TRIGGER "BI_DATA_INVENTORY"
before insert on "DATA_INVENTORY"
for each row
begin
select "DATA_INVENTORY_SEQ".nextval into :NEW.ID from dual;
end;
ALTER TRIGGER "BI_DATA_INVENTORY" ENABLE
Does anyone see anything wrong with this?
The create table part is alright but when I add the create sequence etc it causes the error
Thanks,
KirkHello Kirk,
Your code work likes a charm. Check your privileges for creating sequences and triggers.
Greetings,
Roel
http://roelhartman.blogspot.com/
http://www.bloggingaboutoracle.org/
http://www.logica.com/ -
SQL 2012 Trigger bulk insert lock
Hi
I have built a proc which basically captures some invalid codes and what I would like to do is use a trigger to fire an email everytime this the table receives information .
;WITH MatchesCTE ( SK_Partial, Matchcode ) AS
(SELECT 1, '1234')
SELECT * INTO match FROM MatchesCTE
ALTER TRIGGER EmailInavildPartials1
ON [dbo].[match]
AFTER INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
IF (@@rowcount > 1)
SET NOCOUNT ON;
--SELECT GETDATE() ;
EXEC Send_email_Invalid_Partials1
END
ALTER PROCEDURE [dbo].[Send_email_Invalid_Partials1]
AS
DECLARE @p_body as nvarchar(max), @p_subject as nvarchar(max)
DECLARE @p_recipients as nvarchar(max), @p_profile_name as nvarchar(max), @p_query as nvarchar(max),
@p_subject_date as nvarchar(max), @fileName as nvarchar(max)
SET @p_profile_name = N'DEV'
SET @p_recipients = N'ROBERT@BLAH;'
Select @p_subject_date = (select DATENAME (weekday, getdate ()))+ ' ' + substring (convert(varchar,getdate(),12), 5,2) +'/' + substring (convert(varchar,getdate(),12), 3,2)+ '/' +
substring (convert(varchar,getdate(),12), 1,2)
SET @filename = 'INVALID MATCH CODES ' + CONVERT(CHAR(8),GETDATE(),112)+ '.csv'
SET @p_subject = @p_subject_date + N' INVALID MATCH CODES'
SET @p_body = 'Please see the invaild Partials List.'
SET @p_query = 'SET NOCOUNT ON;Select * FROM DATABASE..match '
EXEC msdb.dbo.sp_send_dbmail
@profile_name = @p_profile_name,
@recipients = @p_recipients,
@body = @p_body,
@body_format = 'HTML',
@subject = @p_subject,
@query = @p_query,
@attach_query_result_as_file = 1,
@importance = 'High',
@query_attachment_filename =@filename,
@query_result_separator = ',',
@query_result_no_padding = 1
you''ll need to change
@p_profile_name
@p_recipients
@p_query
when you then run the following
INSERT INTO match
SELECT 1,'1234'
UNION
SELECT 1, '5678'
It locks. Is there any way around this ? Any help would be great
ThanksWhile I can debate the wisdom of this approach in general, as well as the selectivity of your logic with respect to the trigger, the rows inserted, the contents of the entire table - I won't.
The short story is that this approach will not work. Your trigger fires within the context of an insert (presumably - perhaps a merge) statement that inserts some unknown number of rows into the target table. Your trigger logic will then execute
a procedure if more than one (but not one or zero rows) is inserted. Your procedure will then attempt to execute a query against the same table and attempt to dump ALL rows in the table into a file for the email. This "dumping" executes in a different
process - hence the blocking.
Is it correct that your procedure will send the email with an attachment of ALL rows, not just the inserted ones (but ignore the insertion of just one row)? I can't say. It would be unusual but stranger things have been done. To get
around that you can use a locking hint as suggested - but that may not be what you desire depending on other factors (is anything else manipulating the contents of the table while this process is running? Are you certain of that answer after evaluating the
range of possibilities?).
Perhaps the best approach is to use a very different one. It appears that you insert rows into the table for a single purpose. So why not just turn that process into the one that does the notification? -
Trigger is not getting disabled
Hi ,
I've a doubt on trigger concept.
I've one table REF_cGSC_T, On this 2 triggers are written
One is Blocking Delete operation Trigger
Second one is Replicating Trigger {means I/U/D Operation trigger}
So now for testing the second trigger(replicating trigger) i disabled the First trigger {blocking trigger)
But in testing the second trigger i'm getting the message "DELETE IS NOT ALLOWED ON THIS TABLE"
Then i checked the status of the Blocking trigger, I was shocked to see the status is ENABLED....
Why it happens???? Do i need to do any changes to make my second trigger working properly....did you check if Ttt.k_ttt.runTests enables the disabled trigger. because disabling trigger must work fine.
SQL> create table t(no integer)
2 /
Table created.
SQL> create or replace trigger t_block_insert before insert on t for each row
2 begin
3 raise_application_error(-20001,'Cannot perform insert');
4 end;
5 /
Trigger created.
SQL> insert into t values(1)
2 /
insert into t values(1)
ERROR at line 1:
ORA-20001: Cannot perform insert
ORA-06512: at "SYSADM.T_BLOCK_INSERT", line 2
ORA-04088: error during execution of trigger 'SYSADM.T_BLOCK_INSERT'
SQL> alter trigger t_block_insert disable
2 /
Trigger altered.
SQL> insert into t values(1)
2 /
1 row created.Edited by: Karthick_Arp on Oct 14, 2008 11:22 PM -
Greetings,
I'm currently writing a very simple trigger... I'm using oracle 10.2
In the query analyser, I wrote:
DROP TRIGGER TRIGMAXPARTIE;
CREATE TRIGGER TRIGMAXPARTIE
BEFORE INSERT
ON PARTIE
FOR EACH ROW
DECLARE nbparties number;
BEGIN
select count(NoR) as nbparties
from PARTIE
group by NoR;
IF (nbparties >= 5)
THEN raise_application_error (-208476, 'Le nombre de parties maximal pouvant être effectué lors d''une rencontre est atteint');
END IF;
END;but it stops entering the trigger after the "DECLARE nbparties number;"
If I enter it manually, my trigger works (right click, alter trigger)
but I need a single run file...
Any ideas what might cause this?
Thanks!A database trigger is not the right tool for the job here. See this test case:
SQL> create table partie (NoR) as select level from dual connect by level <= 4
2 /
Tabel is aangemaakt.
SQL> CREATE TRIGGER TRIGMAXPARTIE
2 BEFORE INSERT ON PARTIE
3 FOR EACH ROW
4 DECLARE
5 nbparties NUMBER;
6 BEGIN
7 SELECT COUNT(NoR) INTO nbparties FROM PARTIE;
8 IF (nbparties >= 5) THEN
9 raise_application_error(-20476,
10 'Le nombre de parties maximal pouvant Ûtre effectuÚ lors d''une rencontre est atteint');
11 END IF;
12 END;
13 /
Trigger is aangemaakt.
SQL> insert into partie values (5)
2 /
1 rij is aangemaakt.
SQL> insert into partie values (6)
2 /
insert into partie values (6)
FOUT in regel 1:
.ORA-20476: Le nombre de parties maximal pouvant Ûtre effectuÚ lors d'une rencontre est atteint
ORA-06512: in "RWIJK.TRIGMAXPARTIE", regel 6
ORA-04088: Fout bij uitvoering van trigger 'RWIJK.TRIGMAXPARTIE'.So it looks like the code is working. But watch what happens when you open a second session:
SQL> remark
SQL> remark Open up a second session and issue:
SQL> remark
SQL> remark insert into partie values (6);
SQL> remark commit;
SQL> remark
SQL> pauseOutput of the second session:
SQL> insert into partie values (6);
1 rij is aangemaakt.
SQL> commit;
Commit is voltooid.And the first session again:
SQL> commit;
Commit is voltooid.
SQL> select count(NoR) from partie
2 /
COUNT(NOR)
6
1 rij is geselecteerd.I doubt this is what you want.
You may want to go with a on commit fast refreshable materialized view that stores the count of records and place a check constraint on the materialized view. But more important, can you state your business rule. Maybe we can find an even better solution.
Regards,
Rob. -
Print insert result to a printer in TSQL trigger after insert - Need help.
Hi,
I am trying to print a record to a printer whenever a new record is inserted into a table called PrintTickets, using TSQL trigger for insert.
Is it possible to print a new inserted record to a printer?
Here is the trigger tsql statement:
ALTER TRIGGER [dbo].[PrintDeal]
ON [dbo].[PrintTickets]
AFTER INSERT
AS
declare @Id numeric(18,0)
,@DealId char(15)
,@ValueDatePeriod1Currency1 datetime
,@Bank1Name char(56)
,@Currency1 char(3)
,@Currency2 char(3)
,@PaymentInstructionP1C1 char(80)
,@DealerId char(6)
,@DealVolumeCurrency1 float
,@CalVolumeP1C2 float
,@ExchangeRatePeriod1 float
declare @tmp table
Id numeric(18,0)
,DealId char(15)
,ValueDatePeriod1Currency1 datetime
,Bank1Name char(56)
,Currency1 char(3)
,Currency2 char(3)
,PaymentInstructionP1C1 char(80)
,DealerId char(6)
,DealVolumeCurrency1 float
,CalVolumeP1C2 float
,ExchangeRatePeriod1 float
PRIMARY KEY (Id)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for trigger here
insert @tmp
select
Id
, DealId
, ValueDatePeriod1Currency1
, Bank1Name
, Currency1
, Currency2
, PaymentInstructionP1C1
, DealerId
, DealVolumeCurrency1
, CalVolumeP1C2
, ExchangeRatePeriod1
FROM dbo.PrintTickets
WHERE ID=@@IDENTITY
select @Id=Id
,@DealId=DealId
,@ValueDatePeriod1Currency1=ValueDatePeriod1Currency1
,@Bank1Name=Bank1Name
,@Currency1=Currency1
,@Currency2=Currency2
,@PaymentInstructionP1C1=PaymentInstructionP1C1
,@DealerId=DealerId
,@DealVolumeCurrency1=DealVolumeCurrency1
,@CalVolumeP1C2=CalVolumeP1C2
,@ExchangeRatePeriod1=ExchangeRatePeriod1
from @tmp
-- Code to print to a physical printer if possible
END
The table is called PrintTickets and it contains the following columns:
Id numeric(18,0)
,DealId char(15)
,ValueDatePeriod1Currency1 datetime
,Bank1Name char(56)
,Currency1 char(3)
,Currency2 char(3)
,PaymentInstructionP1C1 char(80)
,DealerId char(6)
,DealVolumeCurrency1 float
,CalVolumeP1C2 float
,ExchangeRatePeriod1 float
PRIMARY KEY (Id)
The dummy records that I am inserting for testing the results in csv format:
Id,DealId,ValueDatePeriod1Currency1,Bank1Name,Currency1,Currency2,PaymentInstructionP1C1,DealerId,DealVolumeCurrency1,CalVolumeP1C2,ExchangeRatePeriod1
696,XXX#33111 ,2014-03-04 00:00:00.000,HSBC ,USD,EUR,XXXXXXXXXXXXXXXXXXXXXXX ,MAT ,342342,87987,0.3123
697,XXX#33113 ,2014-03-04 00:00:00.000,USB ,EUR,USD,9999999999999999999999,ZXY,2334243,32213,0.3245
698,XXX#33114 ,2014-03-03 00:00:00.000,SWISS BANK ,CHF,USD,99999999999999900000,XYZ ,32423424,342,0.83432
699,XXX#33115 ,2014-03-03 00:00:00.000,UK BANK ,USD,PND,XXXXXXXXXXXXXXXXXXXXXXX ,ABC,9809808,0,0.0349
700,XXX#33116 ,2014-03-04 00:00:00.000,USCF BANK ,XXX,XXX,XXXXXXXXXXXXXXXXXXXXXXX ,ABC,89798797,756756,0.734
I appreciate any help.
Thanks in advance.Is it possible to print a new inserted record to a printer?
From SQL Server?
The task of SQL Server is to manage large of data effciently. It is not a general programming environment. It could possibly be done with a CLR procedure that that talks to the printer, but it is not the correct solution.
A possible design could be to post a message on a Service Broker queue, and then the printing server would poll the queue and print the ticket.
By the way, there are more flaws in your trigger. To find the inserted rows, you need to query the virtual table "inserted" which holds a copy of these rows. Furthermore, since a trigger fires once per statement, the trigger must handle the fact
that multiple rows are inserted.
Erland Sommarskog, SQL Server MVP, [email protected] -
Good day all. I have been trying to get this trigger to work for the past three hours but to no avail. I would greatly appreciate some assistance with the two errors generated from the trigger compilation please.
the code is:
CREATE TABLE "User"
( "userId" NUMBER NOT NULL ENABLE,
"userName" VARCHAR2(20) NOT NULL ENABLE,
"password" VARCHAR2(20) NOT NULL ENABLE,
"fName" VARCHAR2(30) NOT NULL ENABLE,
"lName" VARCHAR2(30) NOT NULL ENABLE,
"dob" Date NOT NULL ENABLE,
"dateCreated" DATE NOT NULL ENABLE,
"userType" VARCHAR2(20) NOT NULL ENABLE,
CONSTRAINT "USER_PK" PRIMARY KEY ("userId") ENABLE,
CONSTRAINT "uSER_FK1" FOREIGN KEY ("userType")
REFERENCES "UserTypeLookUp" ("userType") ENABLE)
CREATE SEQUENCE "User_SEQ" MINVALUE 1 MAXVALUE 9999999 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE
CREATE OR REPLACE TRIGGER "BI_User"
before insert on "User"
for each row
begin
select "User_SEQ".nextval into :NEW.userId from dual
end;
ALTER TRIGGER "BI_User" ENABLE;
the error when i compile the trigger is;
Line Position Text
2 35 PLS-00049: bad bind variable 'NEW.USERID'
4 1 PLS-00103: Encountered the symbol "/" when expecting one of the following: begin case declare end exception exit for goto if loop mod null pragma raise return select update while with
When i try to do and insert on the table i get this error;
ORA-04098: trigger 'CSR.BI_User' is invalid and failed re-validation
Error Unable to process row of table User.
OKFirst close your SELECT with ";"
-
Trigger not found after import
Hello,
I copied couple of schemas from one database to another using exp and imp. Both my source and destination databases are 9.2.0.0.7. Everything loaded correctly; however, when I issue the 'alter trigger ... compile' command on those invalid objects, Oracle complains that the trigger is not found. I can use 'Quest SQL Navigator' to compile these invalid objects. If a trigger is already in 'valid' state, I can use this 'alter ... compile' command.
So why can't I use 'alter trigger ... compile' to compile invalid objects. Thank you.
alter trigger dsp.fici compile
ERROR at line 1:
ORA-04080: trigger 'FICI' does not existWhen I searched for 'fici' or 'FICI', the result of the query was 'no rows' but as soon as I searched for 'FICi' it found the row. So the case of the object name mattered.
Thank you.
SQL> select * from dba_objects where object_name ='FICI';
no rows selected
SQL> select * from dba_objects where object_name = 'FICi';
OWNER
OBJECT_NAME
SUBOBJECT_NAME OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE
CREATED LAST_DDL_ TIMESTAMP STATUS T G S
DSP
FICi
46693 TRIGGER
19-JUN-06 19-JUN-06 2006-06-19:12:26:09 INVALID N N N -
Trigger is not working while updating the values of UDF
Dear Freind,
I have created one Trigger for ORDR for Sales order. It is working fine. For that i have created two UDF to Title level. When i fill all fields it shows the correct result in DocTotal. But problem is that, while updateing specific record it also update but only refresh the DocTotal.
Means suppose i change the value of UDF fields that time it is not working it gives following error.
"There is difference between the document total and component total"
ALTER TRIGGER AmountForPC1
ON dbo.ORDR
AFTER INSERT,
UPDATE
AS
SET NOCOUNT ON
UPDATE x
SET x.DocTotal = COALESCE(i.DocTotalSy, 0) + COALESCE(i.U_Ref, 0) + COALESCE(i.U_Sub, 0)
FROM dbo.ORDR AS x
INNER JOIN inserted AS i ON i.DocEntry = x.DocEntry
Thanks
SwapnilHi Swapnil,
Are you aware that you might run into trouble, at least when it comes to a support case, because you have created triggers?
Accordingly to note [896891|https://websmp230.sap-ag.de/sap(bD1lbiZjPTAwMSZ3PTU4ODAwMDAr)/bc/bsp/spn/smb_searchnotes/display.htm?note_langu=E¬e_numm=896891] triggers are not supported.
Regards
Mario -
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 -
Trigger setting value when updating
I need to have a row-level trigger set a value only when an update parameter is not specified in the query. The following trigger doesn't work as expected in SQL Developer - :new.prj_sync_modified_by seems to be the prior value in the row. I need to have :new.prj_sync_modified_by set to 0 whever an update does not specify a value for the prj_sync_modified_by column.
CREATE OR REPLACE TRIGGER "MQSR"."TR_PROJECT_IU"
before insert or update
on PROJECT
referencing old as old new as new
for each row
begin
if inserting then
:new.prj_sync_created_dt := sysdate;
if :new.prj_sync_created_by is null then
:new.prj_sync_created_by := 0;
end if;
end if;
:new.prj_sync_modified_dt := sysdate;
if :new.prj_sync_modified_by is null then
:new.prj_sync_modified_by := 0;
end if;
end TR_PROJECT_IU;
ALTER TRIGGER "MQSR"."TR_PROJECT_IU" ENABLE;
Thanks in advance,
DaveThanks. I found the right syntax for the update part:
if not updating('prj_sync_modified_by') then
:new.prj_sync_modified_by := 0;
end if;
I need to overwrite the prior prj_sync_modified_by value with 0 if no value is specified (not just at row initialization). Between setting a column default and the above (for inserts), I think I'm set.
Message was edited by:
user625389
Maybe you are looking for
-
How do I set up a seperate account for my wife?
We finally purchased a nice new iPhone for my wife. But she would like her own iTunes account. How do I set up a seperate account for her? She has her own laptop, with an iTunes account on it that I was using. Should I just un-install that iTunes pac
-
Multiple useage of indrect material in production
Dear Experts, Please help in mapping the following scenario in SAP. Scenario. We are procuring and stocking a non valuated material ( Angle - 15 x 15 x 4mm thk X 200 long) in nos. This angle will be used as stiffners during fabrication process a
-
Grouping of purchase requisioner as requisioner grp
Can any body tell me is their any way to customise the grp of purchase requisioner is added into some specific Requisioner grp in ECC 6.0? If yes pls explain.
-
Syncing keeps backing up my iPod touch
When I install new application, movie, or music, my mac keeps syncing by backing up my iPod touch everytime. Is this normal or can I change something in the preference.
-
Whats the best way to expose this in memory database? (ArrayList)
Hello everyone. I was looking for advice on how I should implement this...currently I have the following ArrayList that stores ClassEntity objects. I'm going to write 2 classes that need to access this ClassEntity Object arrayList because they are go