DBMS_ALERT
Hi,
In this forum i got suggestion to monitor a table ,i can use dbms_alert,the main of purpose of using this was to seperate the data load process from processing logic.
So how i am planning to do things ,that whenever any record is inserted in table ,the trigger i will use dbms_alert.signal to signal the insert.
But the problem here is someone must be waiting for the signal...
so how to do that ..i cannnot use jobs for waiting process ,
any suggestions on that.
Regards,
Sandeep
Jobs only break if wecode them badly; in particular if we don't handle exceptions properly.
Also i have sometimes seen next date of job not being updated properly. As I suggested in that other, the correct approach would be to have one job which runs permanently rather than one which executes on a per file basis. If you take that approach the interval will be largely irrelevant.
You will find you have a similar problem with DBMS_ALERT. You need a client listening for the signal. This could be an extproc for instance. This is a lotek solution but not infallible. Extproc sessions can get killed off like anything else.
Cheers, APC
Similar Messages
-
Using DBMS_ALERT package
Hello,
I would like to use DBMS_ALERT package. I have read documentation about this package. It works correctly but I have noticed that sometime the pl/sql block (with dbms_alert) performed quick but sometimes it lasted too long. There is no traffic od the server. So my questions are followed:
a) what could be the reason that calling dbms_alert sometimes last too long?
b) how performance is affected
c) waiting session has active status. It is good idea to use shared server for this purpose?
ThanksI have just now solved my problem with DBMS_ALERT :-). I described my problem badly.
My application using dbms_alert started wait when I issue statement dbms_alert.waitone (in another thread). The problem was that my database was misconfigured :-(. I have only one shared_server process and session with dbms_alert.waitone blocked this shared server and any other session cann't work for a while.
SASA
PS: The way of understanding is very twisting :-) -
Using dbms_alert in Jdeveloper
Hello!
I need check signal from OracleDatabase in my application on the JSP Page.
How I can using dbms_alert package for my JSP page?
Thanks.Not specific for DBMS_ALERT but here are the basics from the JDBC developer guide:
http://download.oracle.com/docs/cd/B10501_01/java.920/a96654/basic.htm#1002489 -
Newbie trying to understand usage of DBMS_ALERT in application
Regarding DBMS_ALERT, under "Operational Notes" here
http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_alert.htm
I see the following text:
Alerts can be signalled more often than the corresponding application wait calls. In such cases, the
older alerts are discarded. The application always gets the latest alert (based on transaction commit times).
It is possible to receive an alert, read the data, and find that no data has changed. This is because
the data changed after the prior alert, but before the data was read for that prior alert.Scenario A: The waiting application receives a first alert, then processes this alert, and during this processing, a second alert might have been sent, but the application (while processing the previous alert), is not currently waiting, and so misses this second alert. After processing completes, the application goes back to waiting, when a possible third alert comes along. In this way, the application may not "see" all possible alerts.
Scenario B: The waiting application receives a first alert, then process this alert. Between the time the application received the alert and processes it, a second alert may have taken place, in which case the application only "reads" the second alert. In this way the application may not "see" all possible alerts.
Are those both possible scenarios with DBMS_ALERT? Did I miss any other cases where the application would miss an alert?
If so, then DBMS_ALERT seems suited for applications that only need current data. For example, it wouldn't be suited to distributing 911 calls to emergency personnel because, while the latest call will always get through, there's the potential that one may not get seen by the application. Pardon the bad example, but is that essentially the usage model for DBMS_ALERT?
Edited by: tem on Apr 18, 2012 5:42 PM>
If the alert indicates some event took place, and the application receives this alert, the application must leave the waiting mode to process this alert. If that is correct, then the application carries out any needed processing, then returns to waiting.
During processing, between the time the application retrieves the last bit of data from the database, and the time the application returns to waiting
Also, the event that triggered this second alert would not be represented during the time the application processed the last alert (since it hadn't occurred yet). It would seem the application would need to receive another (third) alert after it begins waiting again before becoming aware of this second event. Hopefully I'm not repeating myself, and thanks for your patience.
>
Well, yes, you are repeating yourself and that means I must repeat myself.
Reread my last response - it all depends on the way you architect the system.
Your approach seems to be have one procedure, 'WAIT_ON_AND_PROCESS_ALERT', that waits for an alert and then processes that alert no matter how longer it takes (seconds, hours, weeks) and then waits on the next alert. You could certainly implement it synchronously that way but that isn't the way you would implement it.
Again - back to the 911 call example. An alert trigger is created on the CALL_TABLE that sends an alert every time an INSERT on the table is committed. The details of the 911 call are in the table record.
You create a stored procedure, PROCESS_UNASSIGNED_CALLS, that processes new records (status = UNASSIGNED) in the CALL_TABLE. It processes all records with an UNASSIGNED status. It doesn't care or even know if there are alerts going on. When the procedure executes it processes the records and dispatches them to be acted on.
Now you create an ON DEMAND job using DBMS_JOB or SCHEDULER that executes the PROCESS_UNASSIGNED_CALLS procedure.
Now you create a 'WAIT_ON_AND_PROCESS_ALERT' procedure that loops and uses the DBMS_ALERT.WAITONE Procedure to wait for the proper alert. When an alert occurs it executes the DBMS_JOB and then goes back to waiting for the next alert. There is no delay except for the fraction of a second it takes to launch the job.
The DBMS_JOB then calls the PROCESS_UNASSIGNED_CALLS procedure which processes ALL new records. The records could have triggered one or 100 alerts; the procedure doesn't care.
Nothing is missed because the PROCESS_UNASSIGNED_CALLS procedure doesn't exit until there are no more records to process. -
Is it possible to use the dbms_alert package from within jdbc to react on events?
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by GSoergel ():
Is it possible to use the dbms_alert package from within jdbc to react on events? <HR></BLOCKQUOTE>
I have got the same problem. Did you managed to solve it?
null -
Dbms_alert package under C++ Daemon
Hi,
I have created a C++ Daemon whihc is using dbms_alert package.
When Daemon runs it makes a call
dbms_alert.waitone("ALERTNAME","MESSAGE", STATUS);
well this is a blocking call as i don;t want to use timeout as 0.
Now when i want to stop my Daemon how can overcome this blocking call?
Many ThanksThanks
But i have alreay mentioned that dbms_alert.remove doesn't work.
Here is a code snippet -
As one can see below that i m looking for code snippet under '_Stop' function as i want to stop the thread workign which is blocked inside 'Action' function.
ie when i sent SIGNAL
kill -SIGTERM <PID>
OTLThread.h
===========
#ifndef OTLThreadh_
#define OTLThreadh_
#include <iostream>
#define OTL_ORA8 // Compile OTL 4.0/OCI8
#define OTL_STL // Turn on STL features
#define OTL_ANSI_CPP // Turn on ANSI C++ typecasts
#include <otlv4.h> // include the OTL 4.0 header file
#include <boost/thread/thread.hpp>
#include <boost/thread/condition.hpp>
using namespace std;
class OTLThread
boost::mutex m_mtxEvent;
boost::mutex m_mtxExclusive;
boost::condition m_cndEvent;
bool m_bWantPause;
bool m_bWantStop;
bool m_bFirstRun;
protected:
static OTLThread * M_pOTLThread;
otl_connect db; // connect object
otl_stream oRslts;
std::string strSQL;
public:
OTLThread();
bool WantStop();
bool WantPause();
void _Resume();
static void Resume(){ if (M_pOTLThread) M_pOTLThread->_Resume(); }
void _Pause();
static void Pause(){ if (M_pOTLThread) M_pOTLThread->_Pause(); }
void _Stop();
static void Stop(){ if (M_pOTLThread) M_pOTLThread->_Stop(); }
void Run();
bool DBConnect();
bool DBDisConnect();
void Action();
void operator()();
};//class OTLThread
#endif/*OTLThreadh_*/
OTLThread.cpp
=============
#include "OTLThread.h"
OTLThread * OTLThread::M_pOTLThread = NULL;
OTLThread::OTLThread():
m_bWantStop(false),
//Set this to true for a 'start-paused' thread model
//and set this to false for a 'start-running' model.
m_bWantPause(false),
m_bFirstRun(true)
if (!M_pOTLThread)
M_pOTLThread = this;
void OTLThread::_Resume()
boost::mutex::scoped_lock lk (m_mtxExclusive);
if(m_bWantPause)
m_bWantPause = false;
m_cndEvent.notify_all();
else
cout
<< "[OTLThread]: Already Resumed, please Pause first"
<< endl;
void OTLThread::_Pause()
boost::mutex::scoped_lock lk (m_mtxExclusive);
if (!m_bWantPause)
m_bWantPause = true;
m_cndEvent.notify_all();
else
cout
<< "[OTLThread]: Already Paused, please Resume first"
<< endl;
void OTLThread::_Stop()
boost::mutex::scoped_lock lk (m_mtxExclusive);
// oRslts.close();
std::string sql;
sql = "call dbms_alert.REMOVE('INSERTALERT')";
otl_cursor::direct_exec
db,
sql.c_str()
); // Registering the Alert
m_bWantStop = true;
m_cndEvent.notify_all();
void OTLThread::Run()
boost::mutex::scoped_lock lk (m_mtxEvent);
DBConnect();
while (true)
if (m_bWantStop) break;
if (m_bWantPause)
cout
<< "\n\t\t"
<< "[" << getpid() << "] "
<< "[OTLThread]: Pausing..."
<< endl;
m_cndEvent.wait(lk);
if (m_bWantStop) break;
Action();
cout
<< "\n\t\t"
<< "[" << getpid() << "] "
<< "Activity: [" << "OLT" << "]: Stopping...\n"
<< endl;
DBDisConnect();
bool OTLThread::DBConnect()
otl_connect::otl_initialize(); // initialize OCI environment
try{
db.rlogon("sam/sam"); // connect to Oracle
std::string sql;
sql = "call dbms_alert.register('INSERTALERT')";
otl_cursor::direct_exec
db,
sql.c_str()
); // Registering the Alert
catch(otl_exception& p){ // intercept OTL exceptions
cerr<<p.msg<<endl; // print out error message
cerr<<p.stm_text<<endl; // print out SQL that caused the error
cerr<<p.var_info<<endl; // print out the variable that caused the error
return false;
return true;
bool OTLThread::DBDisConnect()
try{
db.logoff(); // disconnect from Oracle
catch(otl_exception& p){ // intercept OTL exceptions
cerr<<p.msg<<endl; // print out error message
cerr<<p.stm_text<<endl; // print out SQL that caused the error
cerr<<p.var_info<<endl; // print out the variable that caused the error
return false;
return true;
void OTLThread::Action()
strSQL = "call dbms_alert.waitone('INSERTALERT', :f1<char,out>, :f2<int,out>)";
char Result;
char f1;
int f2;
try{
db.set_max_long_size(7000);
oRslts.open(1,strSQL.c_str(),db); //Waiting for Insert to happen Blocking Call
oRslts>>f1>>f2>>Result;
if(f2 == 0)
std::cout<<"Hey! there is some record in ap3_soln_trigger"<<std::endl;
oRslts.close();
catch(otl_exception& p){ // intercept OTL exceptions
// cerr<<p.msg<<endl; // print out error message
// cerr<<p.stm_text<<endl; // print out SQL that caused the error
// cerr<<p.var_info<<endl; // print out the variable that caused the error
oRslts.close();
void OTLThread::operator()()
Run();
OTLThreadMain.cpp
=================
#include <csignal>
#include <iostream>
#include "OTLThread.h"
void Handler(int iSigno)
if (iSigno == SIGTERM)
OTLThread::Stop();
else if (iSigno == SIGUSR1)
OTLThread::Pause();
else if (iSigno == SIGUSR2)
OTLThread::Resume();
int main(int argc, char *argv[])
OTLThread* pT;
boost::thread_group* ptg;
signal(SIGTERM, Handler);
signal(SIGUSR1, Handler);
signal(SIGUSR2, Handler);
ptg = new boost::thread_group();
pT = new OTLThread();
ptg->create_thread(boost::ref(*pT));
ptg->join_all();
return EXIT_SUCCESS;
Makefile
========
# To use this Makefile on WIN32 (if at all there are Makefiles in WIN32): #
# - Set BUILDER_ROOT to the directory which contains the directory in which #
# you unzipped this zip archive #
# - Set BOOST_ROOT to the boost source tree #
# - Set BOOST_INC_ROOT to the boost include files' root directory #
# - Set BOOST_LIB_ROOT to the boost libs root directory #
# - Set BOOST_THREAD_INCDIR to the boost.threads include directory #
# - Set BOOST_THREAD_LIBS to the boost.threads libs directory #
# - Set BOOST_THREAD_LIBS as required by the WIN32 linkage rules #
# - Run make (and don't fume if it doesn't work ... I am just a novice #
# when it comes to WIN32) #
CC = c++
COMPILE = -c
DEBUG = -g
BOOST_ROOT = /home/lalit/Development/Libs/boost_1_30_0
BOOST_INC_ROOT = $(BOOST_ROOT)/boost
BOOST_LIB_ROOT = $(BOOST_ROOT)/libs
BOOST_THREAD_INCDIR = $(BOOST_INC_ROOT)/thread
BOOST_THREAD_LIBDIR = $(BOOST_LIB_ROOT)/thread/build/bin-stage
BOOST_THREAD_LIBS = -lboost_threadd -lboost_thread
OTL_INCLUDE = /home/lalit/Development/Libs/OTL_4_1_18/include
CFLAGS = -I$(BOOST_ROOT)
CFLAGS += -I$(OTL_INCLUDE)
CFLAGS += -I$(ORACLE_HOME)/rdbms/demo
CFLAGS += -I$(ORACLE_HOME)/rdbms/public
CFLAGS += $(DEBUG)
LDFLAGS = -L$(BOOST_THREAD_LIBDIR) $(BOOST_THREAD_LIBS)
LDFLAGS += -L$(ORACLE_HOME)/lib -lclntsh
OBJS = OTLThread.o
FINAL = OTLThreadMain
All : $(FINAL)
$(FINAL) : OTLThreadMain.o OTLThread.o
$(CC) $(LDFLAGS) -o $@ $< $(OBJS)
OTLThreadMain.o : OTLThreadMain.cpp
$(CC) $(COMPILE) $(CFLAGS) $<
OTLThread.o : OTLThread.cpp OTLThread.h
$(CC) $(COMPILE) $(CFLAGS) $<
clean:
rm -f *.o $(FINAL) -
Problems with the dbms_alert Package
Hello everybody,
I am having some problems while using the ORACLE dbms_alert
package, problems which are not documented, at least anywhere
that I can tell.
Namely the table dbms_alert_info, which holds the registered
alerts of the coresponding sessions doesn't seem to behave the
way it is expected. To be more specific: I start one session and
I begin to register alerts. Everything is fine with the table.
But when a new session starts and tries to register an alert
(doesn't matter if it is identical with the previous session's
alerts or different) the first session's registered alerts are
deleted and are replaced with the latest registered alert of the
second session. The strange thing is that after the first time,
everything works just fine (that is alerts are registered as
expected from both sessions). The problem is that there is no
source code from the package body (as you may have noticed the
package body is 'wraped').
So, please, if someone has encountered the same problems (and
solved it) let me know.
Thanks a lot
Nikos Papakyriakou, Athens-Greece.
nullYou will need to grant execute of DBMS_PIPE to the owner login
Or any login that would use the DBMS_PIPE
Login as SYS and execute the following:
GRANT EXECUTE ON DBMS_PIPE TO <owner login>;Hope this helps
Edited by: jl1997 on Mar 14, 2011 7:26 AM -
Hi,
I have a forms module, when I click on an "Apply" button, the following occur :
1) Calls a Function in a DB Package that triggers a DB signal(dbms_alert.signal) to a waiting(dbms_alert.waitany) daemon registered on that signal.
I am able to get this working using PL/SQL alone.
Since Forms itself is not directly initiating the Signal, shouldn't this work from forms as well?
Can this be made to work using forms ?
Thanks
SharathHello Sharath,
though I don't know exactly what you're trying to achive, I think you should read 47678.1 on metalink first.
With this in mind, it is possible to trigger a Form on the client with DBMS_ALERT from the database. I've used this for a Form with no user interaction.
Bernd -
DBMS_ALERT supports asynchronous notification
Hi,
Im working over dbms_alert package, and I would like to know whats the meaning about:
"*DBMS_ALERT supports asynchronous notification of database events (alerts)*".
Could anybody explain it to me?
Thanks a lot in advanced....EZGms wrote:
Hi,
Im working over dbms_alert package, and I would like to know whats the meaning about:
"*DBMS_ALERT supports asynchronous notification of database events (alerts)*".
Could anybody explain it to me?
Thanks a lot in advanced....http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16760/d_alert.htm#ARPLS351
"Suppose a graphics tool is displaying a graph of some data from a database table. The graphics tool can, after reading and graphing the data, wait on a database alert (WAITONE) covering the data just read. The tool automatically wakes up when the data is changed by any other user. All that is required is that a trigger be placed on the database table, which performs a signal (SIGNAL) whenever the trigger is fired."
provides "real time" notification -
DBMS_ALERT Unknown Within User-Defined PL/SQL Package
Greetings,
I am using Oracle 9i (9.2.0.4.0) database on SUN [sparc] Solaris 9.
From an anonymous PL/SQL block, I can invoke procedures in the DBMS_ALERT package, for example:
begin
DBMS_ALERT.SIGNAL('Avi','was here');
end;But if I put the above call to DBMS_ALERT.SIGNAL() in a stored procedure, or in a PL/SQL package, I get the following error:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
PL/SQL procedure successfully completed.
SQL> create procedure P_AVI
2 is
3 begin
4 DBMS_ALERT.SIGNAL('Avi','was here, again');
5 end;
6 /
Warning: Procedure created with compilation errors.
SQL> show errors
Errors for PROCEDURE P_AVI:
Hit <ENTER> to continue...
LINE/COL ERROR
4/3 PLS-00201: identifier 'DBMS_ALERT' must be declared
4/3 PL/SQL: Statement ignoredI have searched the OTN forum archives, and the MetaLink Web site, and the Oracle documentation, but I couldn't find anything of help.
I would like someone to explain what I need to do in order to be able to invoke DBMS_ALERT.SIGNAL() from within a user-defined (PL/SQL) package, or an alternative to DBMS_ALERT.SIGNAL().
Basically, I have a procedure that receives a list of parameters, and updates several database tables, based on the supplied parameters. If one (or more) of the parameters is invalid, the procedure does not raise an error, it merely sends an "alert" that notifies any interested parties, that a database table was updated with possibly invalid data.
Thanks (in advance),
Avi.I'm terribly sorry. I just realized that I had to grant EXECUTE permission specifically to the database user that was trying to call the DBMS_ALERT package procedure.
The following GRANT did the trick (as the SYS user):
grant execute on DBMS_ALERT to SCOTTNow the SCOTT user can invoke DBMS_ALERT procedures from within SCOTT's stored procedures and packages.
Please forgive me for this waste of bandwidth.
Cheers,
Avi. -
Can't create procedure with dbms_alert
dbms_alert could be run at sqlqlus.
but i can't create any trigger or procedure with dbms_alert as same user.
what do i should do?
see belows;
---SUCCESS---
SQL> EXEC DBMS_ALERT.REGISTER('AAAA');
PL/SQL procedure successfully completed.
---FAIL---
SQL> CREATE OR REPLACE PROCEDURE SP_COGETALERT(P_ALERT IN VARCHAR2, P_MSG OUT VARCHAR2) IS
2 V_MSG VARCHAR2(1800);
3 V_STAT NUMBER(5);
4 BEGIN
5 DBMS_ALERT.REGISTER(P_ALERT);
6 DBMS_ALERT.WAITONE(P_ALERT, V_MSG, V_STAT);
7
8 P_MSG := V_MSG;
9 DBMS_ALERT.REMOVE(P_ALERT);
10 END SP_COGETALERT;
11 /
Warning: Procedure created with compilation errors.
SQL> SHOW ERR
Errors for PROCEDURE SP_COGETALERT:
LINE/COL ERROR
5/5 PLS-00201: identifier 'DBMS_ALERT' must be declared
5/5 PL/SQL: Statement ignored
6/5 PLS-00201: identifier 'DBMS_ALERT' must be declared
6/5 PL/SQL: Statement ignored
9/5 PLS-00201: identifier 'DBMS_ALERT' must be declared
9/5 PL/SQL: Statement ignoredMost likely this account is getting privileges on DBMS_ALERT through a role. You must have privileges granted directly to you to compile an object with a call to another users object.
Richard -
Segmentation fault when calling dbms_alert.register() procedure from OCCI
I am trying to call the dbms_alert.register() from the OCCI but I get segmentation fault when I run the program, here is the code snippet. I am gettin segmentation fault immediately after calling setSQL() method.
Environment *occiEnvironment_;
Connection *occiConnection_ ;
string userName("SCOTT");
string userPasswd("tiger");
string url("");
occiEnvironment_ = Environment::createEnvironment();
try{
occiConnection_ = occiEnvironment_->createConnection(userName,userPasswd,url);
Statement *occiStatement1;
cout << "Before setSQL" << endl;
occiStatement1->setSQL("BEGIN dbms_alert.register(:1); END;");
cout << "After setSQL" << endl;
string alert1("MY_ALERT");
occiStatement1->setString(1,alert1);
occiStatement1->execute();
catch (SQLException ea)
cout << ea.what();
}Thanks for the reply, now I dont see segmentation fault.
I tried to exted the code further to wait for the registered events, I added the following code, I do get and event but then get the exception:
Statement *occiStatement1 = occiConnection_->createStatement();
Statement *occiStatement2 = occiConnection_->createStatement();
string alert, msg;
int status;
occiStatement1->setSQL("BEGIN dbms_alert.register(:1); END;");
string alert1("MY_ALERT");
occiStatement1->setString(1,alert1);
occiStatement1->execute();
occiStatement2->setSQL("BEGIN dbms_alert.waitany(:alert,:msg,:status); END;");
occiStatement2->registerOutParam(1, OCCICHAR, sizeof(alert));
occiStatement2->registerOutParam(2, OCCICHAR, sizeof(msg));
occiStatement2->registerOutParam(3, OCCIINT, sizeof(int));
occiStatement2->execute();
===========================================================
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "SYS.DBMS_ALERT", line 252
ORA-06512: at line 1
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "SYS.DBMS_ALERT", line 252
ORA-06512: at line 1
*** glibc detected *** free(): invalid pointer: 0x08619c48 ***
Aborted -
Call PL/SQL Procedure (not stored) from SQLPLUS
Hello,
the following code creates a stored procedure and allows to call the procedure from SQLPLUS using EXEC.
CREATE or REPLACE PROCEDURE welcome IS
BEGIN
dbms_output.put_line('Welcome user ' || user);
END;
exec welcome;I would like to do the same without storing the procedure. The procedure should be defined in an PL/SQL-Script and called in a SQLPLUS loop. On the one hand I do not have the privileges to create stored procdures. On the other hand I want to use put_line in the loop. Without passing control to SQLPLUS (e.g. the loop-master) all output is kept in the buffer and no information are shown during processing the data.
Regards, Rainernetaktiv wrote:
There should be a repair job updating many hundredthousends records. A script should be created and called only once and the calling user should be informed about the processing status. There is no need for heavy output, but after 5000 or 10000 records I would like to display a message saying nnnnn records processed.Then you need another mechanism to report the current status to the user.
You cannot use the current session to do that. Sessions are serialised. That means they can do only service a single request at a time. So if the session executes procedure foo that updates 100's of 1000's of rows - then that is what the process will be doing. The procedure can only report back to the client after it has completed. It cannot interact directly with the client during the executing of that procedure.
This means that if you want to actually send a notification to the client, you need to do that via a separate session. E.g. the 1st session executes procedure foo that performs the update. That procedure sends a notification (using DBMS_ALERT or DBMS_PIPE for example) to the 2nd session - where the 2nd session receives the asynchronous notification and reports that to the user.
Another method would be for the update procedure to register a long operation using DBMS_APPLICATION_INFO. This enables another session to view the status and progress of the update procedure via virtual (v$) performance views.
Another method would be for the client session not to start the update procedure itself. Instead it can schedule a background job (using DBMS_JPB or DBMS_SCHEDULER interfaces) - and then monitor the status of the job.
Also suggest that you spend some time familiarising yourself with application developer fundamentals and concepts for Oracle. There are guides for both at http://tahiti.orcacle.com for the Oracle version you use. You cannot correctly use Oracle if you do not understand how Oracle works and what the application development features are. And your current approach using DBMS_OUTPUT is pretty much flawed and not how Oracle sessions should report their processing status to a client. -
Trying to get a Trigger and Alert to work
So im trying to get a trigger to work with an alert and the Alert seems to be right and the trigger complies which seems right to me, however the instruction that I have in my book does not produce the same output that I get from my Update.
Here is the deal. I am to log into sql * with a default account as well as login as "SYSTEM"
the trigger should invoke the Alert and output a message to re-order some more product and the status should = 0 since there is no wait time. However I don't get a "Message" from the Alert and the status = 1 which indicates timeout. So if you can take a look at my code and let me know what I did wrong or how to "Connect" the two that would be great.
Trigger I created.
CREATE OR REPLACE TRIGGER order_replace_trg
AFtER UPDATE OF stock on bb_product
FOR EACH ROW
WHEN (OLD.stock = 24 AND NEW.stock = -2)
DECLARE
stock NUMBER(5,1);
idproduct NUMBER(2);
lv_msg_txt VARCHAR2(25);
lv_status_num NUMBER(1);
reorder NUMBER(3);
BEGIN
IF stock <> 24 AND reorder = 25 THEN
lv_msg_txt := 'Product 4 Reorder Time!';
DBMS_OUTPUT.PUT_LINE(lv_msg_txt);
ELSE
lv_status_num := 0;
DBMS_OUTPUT.PUT_LINE(lv_status_num);
END IF;
END;
The Alert:
BEGIN
DBMS_ALERT.REGISTER('reorder');
END;
DECLARE
lv_msg_txt VARCHAR2(25);
lv_status_num NUMBER(1);
BEGIN
DBMS_ALERT.WAITONE('reorder', lv_msg_txt, lv_status_num, 120);
DBMS_OUTPUT.PUT_LINE('Alert: ' ||lv_msg_txt);
DBMS_OUTPUT.PUT_LINE('Status: ' ||lv_status_num);
END;
Here is the block I need to run to test the trigger and alert.
UPDATE bb_product
SET stock = stock -2
WHERE idproduct = 4;
COMMIT;
The message I should get is:
Alert: Product 4 Reorder Time!
Status: 0
PL/SQL procedure successfully completed.
This is what I get.
SQL> /
Alert:
Status: 1
PL/SQL procedure successfully completed.
Thanks for your help!
MacRight. Register says "I'm interested in getting alerted to some particular event", Waitone says "I'm waiting until some event happens". Signal is the key thing that indicates that a particular event happened.
As for your trigger, a couple of issues
- I don't know why you're calling DBMS_OUTPUT. I'm guessing that you probably want to send a message along with your alert that the receiver gets and displays, not that you want to print a message to the window from inside the trigger.
- You're using the local variables stock and reorder in your IF statement but you never initialize them. I'm guessing that you would want to eliminate those local variables and just use :new.stock and :new.reorder (assuming that REORDER is a column in the table).
- Your WHEN clause doesn't seem to make sense. It's telling the trigger to fire only if you update stock from 24 to -2, which doesn't make sense. I'm not sure you would even need a WHEN clause here.
Justin -
Problems in the creation of a MOLAP Cube with DBMS_AWM.
I want to create a MOLAP Cube with the package DBMS_AWM. So I create the ROLAP Cube and the Dimensions with the Enterprise Manager Website, and all works perfectly. Then I executed the code to create the multidimensional dimensions and the multidimensional cube (awm dimensions/cubes), but I had some problems in the first dimension.
This dimension has the name D_DESTIN, and has the following hierarchy:
+DESTIN_DESC_H3
|
+---DESTIN_DESC_H2
|
+------DESTIN_DESC_H1
|
+---------DESTIN_DESC_H0
The name of the hierarchy is H_D_DESTIN.
The following code is the code that I used to create the first multidimensional dimension:
set serveroutput on
execute cwm2_olap_manager.set_echo_on;
execute dbms_aw.execute ('aw create ''WTESTE''');
execute dbms_awm.create_awdimension('EXEMPLO_OLAP', 'D_DESTIN', 'EXEMPLO_OLAP','WTESTE', 'WD_DESTIN');
execute dbms_awm.create_awdimload_spec('D_DESTIN_LOAD', 'EXEMPLO_OLAP', 'D_DESTIN', 'FULL_LOAD');
execute DBMS_AWM.SET_AWDIMLOAD_SPEC_PARAMETER ('D_DESTIN_LOAD','EXEMPLO_OLAP','D_DESTIN','UNIQUE_RDBMS_KEY','NO');
execute dbms_awm.refresh_awdimension('EXEMPLO_OLAP', 'WTESTE', 'WD_DESTIN', 'D_DESTIN_LOAD');
commit;
execute cwm2_olap_manager.set_echo_off;
execute cwm2_olap_manager.end_log
When I executed the code above, I got the following error:
PL/SQL procedure successfully completed.
SP2-0103: Nothing in SQL buffer to run.
PL/SQL procedure successfully completed.
AMD-00001 created AWDimension "EXEMPLO_OLAP.WTESTE.WD_DESTIN"
PL/SQL procedure successfully completed.
AMD-00001 created AWDimLoad_Spec "D_DESTIN_LOAD.EXEMPLO_OLAP.D_DESTIN"
PL/SQL procedure successfully completed.
AMD-00002 set AWDimLoad_Spec_Parameter "D_DESTIN_LOAD.EXEMPLO_OLAP.D_DESTIN"
UNIQUE_RDBMS_KEY to "NO"
PL/SQL procedure successfully completed.
ERROR Create_AWDimension. Problem refreshing dimension:
WD_DESTIN
Error
Validating Dimension Mappings WD_DESTIN.DIMENSION. Key Expression
DWH.D_DESTIN.DESTIN_KEY for Mapping Group
WD_DESTIN.H_D_DESTIN.DESTIN_DESC_H0.DWH_D_DESTIN_WD_DESTIN_H_D_DESTIN
DESTINDESC_H0.DIMENSIONMAPGROUP, Level WD_DESTIN.DESTIN_DESC_H0.LEVEL,
Hierarchy WD_DESTIN.H_D_DESTIN.HIERARCHY is Incorrectly Mapped to
RDBMS.
(AW$XML) AW$XML
In SYS.AWXML!__XML_HANDLE_ERROR PROGRAM:
BEGIN dbms_awm.refresh_awdimension('EXEMPLO_OLAP', 'WTESTE',
'WD_DESTIN', 'D_DESTIN_LOAD'); END;
ERROR at line 1:
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "OLAPSYS.DBMS_AWM", line 1012
ORA-06512: at line 1
Commit complete.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
I donât know what is wrong. The ROLAP Cube is valid according to Oracle Enterprise Manager Website, and it is possible to consult its data with "OracleBI Spreadsheet Add-In"
What is wrong?
Regards,
Rui TorresI executed the same code in a different user and the MOLAP Cube was created successfully.
But, I donât know what is the privilege/role, that permits this second user to create a MOLAP cube with the package DBMS_AWM.
The privileges/roles of the first user are:
ROLES
======
CONNECT
OLAP_DBA
OLAP_USER
OWBR_EXEMPLO_OLAP
OWB_EXEMPLO_OLAP
SYSTEM PRIVILEGES
=================
ALTER SESSION
CREATE ANY PROCEDURE
CREATE DATABASE LINK
CREATE DIMENSION
CREATE INDEXTYPE
CREATE MATERIALIZED VIEW
CREATE PROCEDURE
CREATE PUBLIC DATABASE LINK
CREATE PUBLIC SYNONYM
CREATE ROLE
CREATE SEQUENCE
CREATE SESSION
CREATE SYNONYM
CREATE TABLE
CREATE TRIGGER
CREATE TYPE
CREATE VIEW
DROP ANY PROCEDURE
DROP PUBLIC SYNONYM
EXECUTE ANY PROCEDURE
GLOBAL QUERY REWRITE
SELECT ANY TABLE
SYSDBA
UNLIMITED TABLESPACE
OBJECTS PRIVILEGES
==================
Object Privilege |Schema |Object
=======================================================
SELECT |SYS |DBA_ROLE_PRIVS
EXECUTE |SYS |DBMS_LOCK
SELECT |SYS |DBMS_LOCK_ALLOCATED
EXECUTE |SYS |DBMS_OBFUSCATION_TOOLKIT
EXECUTE |SYS |DBMS_SNAPSHOT
SELECT |SYS |V_$LOCK
SELECT |SYS |V_$MYSTAT
SELECT |SYS |V_$SESSION
SELECT |SYS |V_$SYSTEM_PARAMETER
The privileges/roles of the second user are:
ROLES
======
AQ_ADMINISTRATOR_ROLE
DBA
MGMT_USER
SYSTEM PRIVILEGES
=================
CREATE MATERIALIZED VIEW
CREATE TABLE
GLOBAL QUERY REWRITE
SELECT ANY TABLE
UNLIMITED TABLESPACE
OBJECTS PRIVILEGES
==================
Object Privilege |Schema |Object
=============================================
EXECUTE |SYS |DBMS_ALERT
EXECUTE |SYS |DBMS_AQ
EXECUTE |SYS |DBMS_AQADM
EXECUTE |SYS |DBMS_AQELM
EXECUTE |SYS |DBMS_AQ_IMPORT_INTERNAL
EXECUTE |SYS |DBMS_DEFER_IMPORT_INTERNAL
EXECUTE |SYS |DBMS_REPCAT
EXECUTE |SYS |DBMS_RULE_EXIMP
EXECUTE |SYS |DBMS_SYS_ERROR
EXECUTE |SYS |DBMS_TRANSFORM_EXIMP
ALTER |SYS |INCEXP
DEBUG |SYS |INCEXP
DELETE |SYS |INCEXP
FLASHBACK |SYS |INCEXP
INDEX |SYS |INCEXP
INSERT |SYS |INCEXP
ON COMMIT REFRESH |SYS |INCEXP
QUERY REWRITE |SYS |INCEXP
REFERENCES |SYS |INCEXP
SELECT |SYS |INCEXP
UPDATE |SYS |INCEXP
ALTER |SYS |INCFIL
DEBUG |SYS |INCFIL
DELETE |SYS |INCFIL
FLASHBACK |SYS |INCFIL
Which privilege/role permits the second user to create a MOLAP cube?
Regards,
Rui Torres
Maybe you are looking for
-
TS3274 While playing a game iPad goes to home page why?
While playing temple run 2 sometimes the iPad just goes to home page
-
Number of Records in Masterdata
Hallo Experts, Do anbody know why i have two diffenrent number of records. the first one is when i right-click the Infoobject and manage-Masterdata here is 737. the second number is when i make a report of the records in ABAP "select *" 713 records f
-
HELP!!!! iPod wont stop resetting!!!
So today I went somewhere with my family and my iPod died out on me. When I resetted it while in the car, it showed a picture of a little sad iPod with "x's" for the eyes and an exclamation mark next to it. I thought by simply recharging it, the prob
-
Difference Between Inventory Audit Report & Inventory Positing List Report
Dear all, Please tell me the difference between these twoInventory Audit Report & Inventory Positing List Report, Because I find difference , when observe Closing and Opening Stock Quantity on 1.4.10 audit report showing 610 units but on 1.4.10 post
-
"Local" failover for NTP Server on Solaris 10
I have four Solaris 10 Servers, all syncing their time from an external NTP server ntp.example.com. Is it possible to configure one of the four servers as a local "pseudo" Failover NTP, i.e. acting as a client to ntp.example.com, as long as it is ava