Query on trigger.
create or replace trigger trig_name before update of sal on emp for each row
Declare
excep exception;
begin
if (:new.sal=3500) then
dbms_output.put_line('value is more than 3500 okay');
else
--:new.sal:=3500
--update emp set sal=3500 where empno=:new.empno;
raise excep;
--raise_application_error(-20400,'update can''t be done');
--dbms_output.put_line('now sal value is set to 3500');
end if;
exception
when excep then
dbms_output.put_line('update can''t be done');
end;
in the above trigger I want to raise when updating sal is not equal to 3500.
1)Actually my intention is if it is not 3500 i want to make it ti 3500 and update it.. So I tried assigning 3500 to :new.sal(it gav error so left it)
2)then for the same i row i gav another update statement inside trigger body with sal=3500(it raised mutating error)
3) so I cudn't update the value i intented I decided to stop the update by raising a exception whenever sal vaue is not 3500..(this raises the given exception and at the same updates the value in the table)..
Please help me if I have to do above three transactions using trigger...
As I am abeginner pls excuse me if i have made any basic mistakes...
thanks in advance..
by
Prabu....
(this raises the given exception and at the same updates the value in the table)..That's because you trapped the exception in your exception...uhh...handler.
Get rid of your entire exception section. It's hiding your errors.
SQL> select * from t;
C
3
SQL> create or replace
2 trigger tr
3 before update of c on t
4 for each row
5 begin
6 if :new.c = 0 then
7 raise_application_error(-20400,'c can never be 0');
8 end if;
9 exception
10 when others then null; --< one of the worst lines in all pl/sql
11 end;
12 /
Trigger created.
SQL> update t set c = 0;
1 row updated.
SQL> select * from t;
C
0
Similar Messages
-
Query mode trigger....
Hello folks,
I have this problem, i need when-validate-item to fire in query mode, in the help they say this trigger can't be fired in query mode is there any way to produce the same effect or validation in query mode, what i need is when a user fill a text item and before to query the datablock to test thsi text item... and thank you...I would say pre_query is a better place to test your query condition, or set your query condition if nessary.
or if you need the same check fire normal mode, you could the checking in a program unit and call it from pre_query and when_validate_item trigger.
hedy -
Enter query form trigger from MENU
Hi .
I am using Oracle Developer 9i , I have coded KEY-ENTQRY for some validation.
I have created MENU using Menu builder . On Enter query Menu I have Coded normal 'ENTER_QUERY' code. When I run the form, form is not calling my KEY-ENTQRY code. How can I perform this task.
ThanxHave you used do_key on the enter query menu?
Use do_key(''ENTER_QUERY') and it should work.
Please mark answer as helpful / correct, if it helps you
Navnit -
Creating a correct trigger condition
hi All,
I have a problem in my trigger condition in my query.
The background:
1. I have a List view with a Data insertion (Lead Select) into a ROW.
2. Also, I have 5 different queries which are triggered based on a selection of a Radio button.
Now, my req is that Query1 should load either on
change of Lead select in List View
OR if the chosen Radio button is 1
Query2 should load either on
change of Lead select in List View
OR if the chosen Radio button is 2
& so on.
Can you please help me with a valid trigger condition. ? The concatenate is not working as the Xcel only allows Value Change or Value Becomes.
Currently, I am launching all the 6 queries at once using CONCATENATE + VALUE CHANGE. This is a huge hit on performance.
Cheers
KiranWhat if you have 5 different cells (one for each query) and you only have the trigger cell for Query 1 show the list select value only if the chosen radio button is 1 and so on?
Formula for Query 1 Trigger Cell: =If(=1,,"")
Formula for Query 2 Trigger Cell: =If(=2,,"")
~~~~~~~~~~~~~~~
Formula for Query 5 Trigger Cell: =If(=5,,"")
Then, the value in any given cell should update any time the radio button is changed (from "" to the ListSelectValue) and anytime the ListSelect value changes (assuming that radio button is selected). -
To connect a datablock to a query - stored procedure: problem
I have the following table...
CREATE TABLE I_TIPOLOGIA (
CODICE NUMBER(6),
DESCRIZIONE VARCHAR2(100),
CONSTRAINT I_TIPOLOGIA_PK PRIMARY KEY (CODICE) );
and the following package to connect a datablock to
previous table with a stored procedure...
CREATE or REPLACE PACKAGE DATABANKER_TIPOLOGIE AS
TYPE TipTableOfRec IS TABLE OF I_TIPOLOGIA%ROWTYPE;
PROCEDURE leggi(resultset IN OUT TipTableOfRec);
END DATABANKER_TIPOLOGIE;
CREATE or REPLACE PACKAGE BODY DATABANKER_TIPOLOGIE AS
PROCEDURE leggi(resultset IN OUT TipTableOfRec) AS
BEGIN
SELECT * BULK COLLECT INTO resultset
FROM I_TIPOLOGIA;
END leggi;
END DATABANKER_TIPOLOGIE;
When I compile the form I receive in QUERY-PROCEDURE trigger
en error 306: "number or type of arguments are wrong in POPULATE_BLOCK"
I post the trigger auto generated by Forms Builder 6i...
DECLARE
bk_data DATABANKER_TIPOLOGIE.TIPTABLEOFREC;
BEGIN
DATABANKER_TIPOLOGIE.leggi3(bk_data);
PLSQL_TABLE.POPULATE_BLOCK(bk_data, 'BLOCCO50'); -- <- error here
END;
How can I solve this problem? Maybe there is a bug?
P.S. I'm using Oracle Database 9iCREATE or REPLACE PACKAGE DATABANKER_TIPOLOGIE AS
TYPE TipTableOfRec IS TABLE OF I_TIPOLOGIA%ROWTYPE;
PROCEDURE leggi(resultset IN OUT TipTableOfRec);
END DATABANKER_TIPOLOGIE;I have solved with this replacement 1) -> 2)
1) TYPE TipTableOfRec IS TABLE OF I_TIPOLOGIA%ROWTYPE;
2) TYPE TipTableOfRec IS TABLE OF I_TIPOLOGIA%ROWTYPE
INDEX BY BINARY_INTEGER;
with 2) now works.
Now I have stored-procedures for query, insert, delete
and update.
I have some problems with delete and update of the records
because it seems that they are locked.
I think that it is due to the absence of lock
stored-procedure... there's someone that can help me with
the lock SP implementation? -
How to use update trigger in sql server 2008 with specific column
Hello friends currently my trigger updates on table update, and I need to change this to only fire when specific column changes.
/****** Object: Table [dbo].[User_Detail] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[User_Detail](
[sno] [int] IDENTITY(1,1) NOT NULL,
[userid] [nvarchar](50) NULL,
[name] [nvarchar](max) NULL,
[jointype] [nvarchar](50) NULL,
[joinside] [nvarchar](50) NULL,
[lleg] [nvarchar](50) NULL,
[rleg] [nvarchar](50) NULL,
[ljoining] [int] NULL,
[rjoining] [int] NULL,
[pair] [int] NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[User_Detail] table data ******/
SET IDENTITY_INSERT [dbo].[User_Detail] ON
INSERT [dbo].[User_Detail] values (1, N'LDS', N'LDS Rajput', N'free', N'Left', N'jyoti123', N'SUNIL', 6, 4, 4)
INSERT [dbo].[User_Detail] VALUES (2, N'jyoti123', N'jyoti rajput', N'free', N'Left', N'mhesh123', N'priya123', 3, 2, 2)
SET IDENTITY_INSERT [dbo].[User_Detail] OFF
/****** Object: Table [dbo].[User_Detail] trigger ******/
CREATE TRIGGER triggAfterUpdate ON User_Detail
FOR UPDATE
AS
declare @userid nvarchar(50);
declare @pair varchar(100);
select @userid=i.userid from inserted i;
select @pair=i.pair from inserted i;
SET NOCOUNT ON
if update(pair)
begin
insert into Complete_Pairs(userid,pair)
values(@userid,1);
end
GO
/****** Object: Table [dbo].[Complete_Pairs] Script Date: 05/22/2014 21:20:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Complete_Pairs](
[Sno] [int] IDENTITY(1,1) NOT NULL,
[userid] [nvarchar](50) NULL,
[pair] [int] NULL
) ON [PRIMARY]
GO
my query is TRIGGER triggAfterUpdate is fired only when pair column in User_Details table is update only and when we update other column like ljoin or rjoin then my trigger is not fired
please any one can suggest us how it can done or provide solution
Jitendra Kumar Sr. Software Developer at Ruvixo Technologies 7895253402>select @userid=i.userid
frominserted i;
select
@pair=i.pair
frominserted i;
The code above assumes a single row UPDATE.
You have to setup the trigger for set processing like when 100 rows are updated in a single statement.
UPDATE trigger example: http://www.sqlusa.com/bestpractices2005/timestamptrigger/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
One of our projects here has a requirement where they'd like to modify, at runtime, the named query defined in the Mapping Workbench.
One example is to set the refresh depth level (cascadePrivateParts, cascadeAll, for example) for the named query so that the defined query could be used in different scenarios with slightly different query options to get different query results.
To support this, we will need to clone the query. See the sample code below:
ObjectLevelReadQuery toplinkQuery = null;
ObjectLevelReadQuery queryClone = null;
Descriptor descriptor = session.getDescriptor(targetClass);
DescriptorQueryManager queryManager = descriptor.getQueryManager();
toplinkQuery = (ObjectLevelReadQuery)queryManager.getQuery(queryName);
queryClone = (ObjectLevelReadQuery)toplinkQuery.clone();
We try to use the clone method in DatabaseQuery. It seems to be working fine from the unit testing.
Could someone provide me some information regarding the overhead (performance penalty) the clone method introduces?
Thanks.
HaiweiJames,
Thanks very much for your quick response.
"The difference between using the clone vs not using the clone, is that clone (and changing the query) will trigger the query to no longer be prepared. This means that the query will need to re-generate the SQL for every execution."
Is this always true or it depends on what query options got changed?
I tried the cloneQuery with cloneQuery.cascadePrivateParts(). It seems that (from the trace) it still uses the prepared SQL. Here is the trace:
in testQuery .....
[3/8/05 15:27:47:027 EST] d510d51 SystemOut O 2005.03.08 03:27:47.027--ServerSession(1090797828)--Thread[Servlet.Engine.Transports : 1,5,main]--Connection(290525521)--SELECT * FROM QUOTE WHERE ID IN (?,?)
bind => [1, 2]
[3/8/05 15:27:47:037 EST] d510d51 SystemOut O 2005.03.08 03:27:47.037--ServerSession(1090797828)--Thread[Servlet.Engine.Transports : 1,5,main]--Connection(759639367)--SELECT NAME, ID, VERSION FROM USER04.SUBQUOTE WHERE (QUOTE_ID = ?)
bind => [1]
[3/8/05 15:27:47:037 EST] d510d51 SystemOut O 2005.03.08 03:27:47.037--ClientSession(219090191)--Thread[Servlet.Engine.Transports : 1,5,main]--client released
A separate question, the cascade option is not configurable in the Mapping Workbench, is this something that TopLink deliberately does not provide?
Thanks again for your assistance. -
Determine analog input task trigger status
I am writing a basic analog input function, which will be triggered via a start trigger sent by another instrument. Is there a way to programmatically deteremine if the Analog Input task has been triggered? I would like to have a Boolean indicator that shows "True" after the Analog Input task is triggered, but I couldn't find out how. Does anyone have a suggestion? Thanks!
Is this a continuous acquisition?
I am not aware of a function querying the trigger state of a task. Nevertheless, i don't think this is necessary as you usually start reading right after starting the input task.
So in case a trigger is late, you will/should run in a time out error. Otherwise, you will get some data which is a clear indication that the task is running....
Norbert
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it. -
Tuning querying and indirection
We have a legacy design where everything is highly normalized, even in the object model, and uses indirection for all contained parts of an object. This works well for most of the needs in the application. However, we are trying to perform a calculation that starts with a result set of root objects and navigates through the owned parts of the root object (1 to many relationships AND 1 to 1 relationships) to calculate an aggregate value. Depending on the business rules and the state of the root object, different parts of the root object are required when doing the calculation for the aggregated sum (hence the difficulty of using partial object reads via ReportQuery).
Is there any way to tune a query to trigger indirection on an object for all its owned parts (i.e. load them into memory immediately)? Loading everything into memory when we query for the root objects would be fine. Delayed querying would be more expensive, we believe. We also don't want to change the descriptors globally because indirection is appropriate for many of the other scenarios in the code.
Other recommendations for doing the calculation without the overhead of indirection and its multitude of queries would also be appreciated.TopLink provide its "batch reading" feature to optmized the loading of a large graph of objects. The main cost in traversing a large graph of objects is that you get a lot of small queries. Refer to the documentation section on batch reading and the query API addBatchReadAttribute.
If you have A->1-m->B->1-1->C and initially read n As that each have m Bs, normally reading will require 1+n+n*m queries (if n was 100 and m 10 = 1101). With batch reading this can be converted to 3 queries giving a huge performance benifit.
To force indirection to fire to a certain level, you can either walk your object yourself, or call the TopLink API, copyObject(level) to force instantiation. -
Please help me solve the query
CREATE TABLE SPONSER_UPDATION
MEMBER VARCHAR2(12),
SPONSER VARCHAR2(10),
POINT NUMBER(10)
MEMBER SPONSER POINT
a AS 10
b a 10
c b 10
d c 10
e d 10
f e 10
i want a query or trigger on updating a single row all the row corresponding to it also gets updated example if i update a row with member f then its sponser e should also be updated and if sponser is is updatd then its sponser d should also be updated and if d is updated its spnser c should also be updated untill the last one through a single query
i have written the trigger
CREATE OR REPLACE TRIGGER points_updation
AFTER UPDATE
ON sponser_updation
FOR EACH ROW
DECLARE
v_username varchar2(10);
BEGIN
update sponser_updation
set
point=point+10
where
:new.member=:old.sponser;
END;
after updation of any row error message is comming
ORA-04098: trigger 'INVENT.SPONSER_UPDATION1' is invalid and failed re-validation
thanks & Regards,
anuj kumar singh!You can not insert, delete or update into this trigger type.
try this:
CREATE OR REPLACE TRIGGER points_updation BEFORE UPDATE ON sponser_updation FOR EACH ROW
BEGIN
if :new.member = :old.sponser then
:new.point:=:new.point+10;
end if;
END; -
Have LabView react to a scope trigger
I have LavbView 6.1 connected to a TDS7104 scope via GPIB. What I'd like to do is have LV react directly to the scope's trigger. IE, the scope triggers, that causes a programatic change in my VI, which I then use elsewhere in my VI. I've got an indirect way to do this, but we're not fully satisfied with it. We'd strongly prefer a direct way to do this, if it's possible.
If anyone knows the TDS7104 really well, is there a command I can send the scope to query its trigger status?
I have what looks like a full set of drivers from Tektronix, but none look like they might do this.Hello;
There isn't a formal way to use Occurrences to wait and interrupt the CPU upon a digital event. What you can do to workaround that is to use the attached VI; that is an Analog Trigger VI, and set the analog trigger level to be the TTL levels. So, when the digital trigger arrives, your analog circuitry will trigger of the Analog input readings.
Hope this helps.
Filipe A.
Applications Engineer
National Instruments
Attachments:
occurrence.zip 70 KB -
Forms6i question - Do you want to save the changes you have made !!
Hi,
I'm developing a custom master-detail form for 11i e-Business Suite. The requirement is to programmatically default values for some of the base table items when entering the master record.. Both the master and the detail blocks are base table blocks and defined the relation between these 2 as well..
So i have coded my defaulting logic in the "when-new-record-instance " trigger only when the "(:system.record_status IN ('NEW','INSERT' ) AND :system.mode <> 'ENTER-QUERY')"..
This is working but the problem is even when i do not change any values in the master block and i try to exit out of the form, getting a message "Do you want to save the changes you have made ".. I want to get that message only when some thing else is changed/entered in the master block or when any new detail records has been entered for that master block.
Thanks in advance
ShreeShree,
It sounds like you have a Post-Query (PQ) trigger that is populating items in your Form. This is the typical reason why you would see this message when you close your form and no User changes have been made. The best solution would be to move your non-base table items from your data blocks to a control block so the PQ trigger won't mark the block or record as "Changed".
Hope this helps.
Craig... -
Giving error of insufficient privileges while creating triggers
Hi all,
I am facing the problem of insuffcient privilege on base tables while creating triggers. I have three schemas say A, B, C in my database.
Base tables are in schema A. I have given all the grants on base table to schema B and C.
grant all on base_table_name to B;
grant all on base_table_name to C;
I have created synonym also on that base table.
And i m creating triggers in schema B.
When i execute the query for trigger the it giving following error :
+AFTER INSERT OR UPDATE OR DELETE ON BASE_TBALE_NAME *+
ERROR at line 3:
ORA-01031: insufficient privileges
even i have checked in dba_tab_privs for that base_table.....it is showing all the grants to USER B and C.
What should I do now?
please suggest.......
Regards,
Andy.Hi karan,
You are right. While searching docs i got the solution of my problem.
Privileges Required to Use Triggers
To create a trigger in your schema:
+•You must have the CREATE TRIGGER system privilege+
+•One of the following must be true:+
+◦You own the table specified in the triggering statement+
+◦You have the ALTER privilege for the table specified in the triggering statement+
+◦You have the ALTER ANY TABLE system privilege+
To create a trigger in another schema, or to reference a table in another schema from a trigger in your schema:
+•You must have the CREATE ANY TRIGGER system privilege.+
+•You must have the EXECUTE privilege on the referenced subprograms or packages.+
To create a trigger on the database, you must have the ADMINISTER DATABASE TRIGGER privilege. If this privilege is later revoked, you can drop the trigger but not alter it.
The object privileges to the schema objects referenced in the trigger body must be granted to the trigger owner explicitly (not through a role). The statements in the trigger body operate under the privilege domain of the trigger owner, not the privilege domain of the user issuing the triggering statement (this is similar to the privilege model for stored subprograms).
I have to grant only create any trigger to user.
Problem solved.
Thanks to all for ur help.
Regards,
Andy. -
DOCUMENT CLASSIFICATION AND CTXRULE INDEX TYPES IN ORACLE9I TEXT
제품 : ORACLE SERVER
작성날짜 : 2004-05-27
DOCUMENT CLASSIFICATION AND CTXRULE INDEX TYPES IN ORACLE9I TEXT
================================================================
PURPOSE
이 문서는 Oracle9i 에서 추가된 새로운 기능으로 Oracle Text 에서의
문서 분류기능(Document Classification) 에 대해 소개한다.
Explanation
Oracle9i Text 에서는 CTXRULE index type을 이용하여 각 문서를 분류하는 기능을
구현할 수 있다. 이 CTXRULE index type은 각 분류별로 define 된 rule에 따라
문서를 indexing하고, 이러한 기능을 위해 MATCHES operator를 제공한다.
이 Oracle9i Text 는 일반 Text, XML, HTML 문서에 대해 이 document classification
기능을 지원한다.
1. Create a Table of Queries
먼저 다음과 같이 조회를 위해 분류할 category를 저장할 table을 생성한다.
CREATE TABLE myqueries (
queryid NUMBER PRIMARY KEY,
category VARCHAR2(30),
query VARCHAR2(2000) );
아래와 같이 조회시에 문서의 category name과 query시 사용할 구문을 저장한다.
INSERT INTO myqueries VALUES(1, 'US Politics', 'democrat or republican');
INSERT INTO myqueries VALUES(2, 'Music', 'ABOUT(music)');
INSERT INTO myqueries VALUES(3, 'Soccer', 'ABOUT(soccer)');
2. Create the CTXRULE Index
CTXRULE index를 이용하여 이 table에 Text index를 생성한다.
CREATE INDEX myqueries_idx ON myqueries(query)
INDEXTYPE IS CTXRULE
PARAMETERS('lexer lexer_pref
storage storage_pref');
이 CTXRULE에는 filter, memory, datastore, stoplist 는 지정할 수 없다.
3. Classifying a Document
아래와 같이 실제 데이타가 저장되는 table을 생성한다.
CREATE TABLE news (
newsid NUMBER,
author VARCHAR2(30),
source VARCHAR2(30),
article CLOB);
이 Table에 data를 insert하기 전에 MATCHES operator 를 이용하여 지정한 내용에
대해 문서를 분류하여 query table에 저장하는 trigger 를 생성한다.
You can create a before insert trigger with MATCHES to route each document to
another table news_route based on its classification:
CREATE TRIGGER NEWS_MATCH_TRG
BEFORE INSERT ON NEWS
FOR EACH ROW
BEGIN
-- find matching queries
FOR c1 IN (select category
from myqueries
where MATCHES(query, :new.article)>0)
LOOP
INSERT INTO news_route(newsid, category)
VALUES (:new.newsid, c1.category);
END LOOP;
END;
RELATED DOCUMENTS
Oracle9i Text Application Developer's Guide ReleaseHi,
please post a Oracle Text question in the Oracle Text forum: Text
That forum is monitored by Oracle Text Experts. This forum not always.
Herald ten Dam
Superconsult.nl -
One select list with multiple LOV's (LOV based on how page was called)
APEX 4.0.2
I've a DML form page from a report on which I need a single select list item to have a differing LOV based on how the form page was called.
The calling page (report), contains an edit link column and a create button. Depending on which is selected, I wish the LOV for my select list item to change. The idea behind this is that if someone creates a new entry, I want to constrain the select list to a subset of rows of a table query populating the LOV. On the other hand, if an existing item is edited, I want the select list LOV containing all rows of a table query populating the LOV.
What I've tried...
- Duplicates of select list item each triggered to render based on an arbitrary value set when either "create" or "edit" are selected. This did not work because the item was part of DML and would not allow replication on the same page.
- Logic in the LOV sql statement controlling which sql was to be run based on an arbitrary value set when either "create" or "edit" are selected. This did not work as logic is not allowed in LOV sql statements.
Any thoughts? Many Thanks!
PaulHello Patrick!
Thanks for responding - Love your captcha plugin!
Anyway, these are the two dynamic LOV's. The first I have in play right now (when creating new records). I need to have the other for existing record modifications.
LOV #1
select stock_no d, stock_no r
from [email protected]
where status like '%Awaiting Transfer%'
or status like '%On Hold%'
order by 1LOV #2
select stock_no d, stock_no r
from [email protected]
order by 1As I mentioned, I attempted to use plsql logic in the query to trigger one or the other based on a value set when the user either clicked an edit link or a create button but couldn't get the dynamic LOV to commit with that extra code in it.
Thanks!
Paul
Maybe you are looking for
-
Sonic's Video 55 with iPod nano
I've been trying to use the Sonic Video 55 with my iPod nano (3G) and can only get music videos to play. When trying to play movies that I have ripped or purchased, I just get a blue screen even when following Sonic's "Using iPod Classic / Nano 3G wi
-
I have iLife '05 and have installed all of them are working except iDVD 5. It has updated to 5.0.1 though when I click on it to open it I get the message "You cannot use this version of the application iDVD with this version of MAC OS X". I have trie
-
External keyboard only works after reboot with Port Replicator III Plus
The problem is that when I boot the notebook, the external PS/2 keyboard doesn't work. When I reboot the keyboard flips on and then I can use it. This problem occurs on a Toshiba Tecra notebook with a Advanced Port Replicator III Plus. I've used seve
-
No english version of CS6 for China?
I have been contacting Adobe office in China several times and they told me no english version of CS6 for China, only chinese version is available! This is unacceptable and i'm very curios to know WHY! So non-chinese speaking people in China cannot u
-
Cannot launch downloaded CS5.5 for windows
I have a site license for CS5.5. I have DVDs for Mac but have to download the PC version. Once downloaded the file will not launch. My PC doesn not ercognize. I have tried serveral times but no luck. What am I doing wrong?