Packaged variables and triggers
I am creating a trigger taht will update the values of packaged variables.
I need some help getting the variables to work correctly...here's the code and issues:
-------------PACKAGE SPECIFICATION------
CREATE OR REPLACE PACKAGE discount_pkg
IS
pv_disc_num NUMBER;
pv_disc_txt VARCHAR2(50);
END;
------------DECLARE VARIABLES-----------
BEGIN
discount_pkg.pv_disc_num:=5;
discount_pkg.pv_disc_txt:='N';
end;
--------------TRIGGER 9:5----------------
CREATE OR REPLACE TRIGGER bb_discount_trg
AFTER UPDATE OF orderplaced ON bb_basket
FOR EACH ROW
BEGIN
IF :NEW.orderplaced=1 THEN
IF discount_pkg.pv_disc_num=5 THEN
discount_pkg.pv_disc_txt:='y';
END IF;
END IF;
END;
/And the resulting test reveals the following errors:
SQL> update bb_basket
2 set orderplaced=1
3 where idbasket=13;
1 row updated.
SQL> print pv_disc_num;
SP2-0552: Bind variable "PV_DISC_NUM" not declared.
SQL> print discount_pkg.pv_disc_num;
SP2-0552: Bind variable "DISCOUNT_PKG" not declared.Any idea why this is happening?
SQL> print pv_disc_num;
Print statement can only be used to display the value of environment variable. In your case, you are trying to display the value of a variable in a package. To display a value of a variable in a package, you need to retrieve it using pl/sql block. Try this:
begin
dbms_output.put_line(discount_pkg.pv_disc_num);
end;
if you want to use the PRINT syntax, you need to declare an environment variable to store the value:
SQL>variable pv_disc_num NUMBER
SQL>begin
:pv_disc_num := discount_pkg.pv_disc_num;
end;
SQL> print pv_disc_num
Similar Messages
-
Calling public package functions and variables through dblink
Is it possible to call a global public variable in a package in one database from another package procedure in another database using a database link? If so, could you let me know the syntax? Same question for package functions.
Hi,
check this documentation link especially the stmt...
http://www.mcs.csueastbay.edu/support/oracle/doc/10.2/appdev.102/b14251/adfns_packages.htm#i1007858
You cannot access remote package variables and constants.May be you can write a function in the remote db which when called will return the variable value.
for calling remote package functions...
syntax from documentation is [[schema.]package.]function_name[@dblink][(param_1...param_n)]
an example given in the above link for this...
EXECUTE fire_emp1@boston_server(1043);
Ravi Kumar
Edited by: ravikumar.sv on Aug 31, 2009 11:29 AM -
We want to get rid of the Globals we currently use in forms. Thought of creating a package with package variables and setting these from the form. We do not really want to have to create a set and get function for each variable we create.
I wanted to be able to pass the variable name to a function to set it or get it. This would be ok using a library in forms and using the COPY and NAME_IN built ins but we want to use a pl/sql package and these are not supported there .
Any suggestions please.If you want an abstractable variable mechanism then you can do something like:
1) Create a Record type which has two columns - key and value
2) Create a PL/SQL Table of records of this type
3) Write routines to get and put into this table based on the Key value.
So you have a single array of global values which can be referenced using string keys (which of course can themselves be variables or constructed at runtime) -
Help with Package variables/constants
Hi All,
I have a function which uses package variables and constants.
I am seeing the following strange behavior when I execute the
function. Here is what I did.
1) I opened a SQL* plus session and executed my function couple
of times. It worked very well and gave me the correct return
value.
2) I left the session idle for about 3 hours. ( did not
disconnect.)
3) I came back after 3 hours and ran the same query, it gives
me null value. (error message says PL/SQL numeric or value
error).
4) I disconnected the session and executed the function on the
new session. I got my result back.
Does this scenario looks something familiar to you? If so, could
you pl. advise where it could go wrong? (is it a bug with oracle
8?) P.S. I used dbms pipe package calls also in my package.
Thanx
rkstrange.. test it one more time in same way..if it happens again
submit TAR. -
Info Package Group Management? and Triggering of Event Chains ?
Hi GURU's
Info Package Group Management? and Triggering of Event Chains ?
Thanks
Bhima Chandra Sekhar GHi Bhima!
IP GROUP:
http://help.sap.com/saphelp_nw04/helpdata/en/80/1a65b5e07211d2acb80000e829fbfe/content.htm
About chains and triggering events:
http://help.sap.com/saphelp_nw04/helpdata/en/41/243d3828135856e10000009b38f842/content.htm
Hope it helps!
Bye,
Roberto -
BC4J ApplicationModule Pooling and persitent package variables
Scenario:
HttpRequest
starts=> - use SessionCookie API to get an Application Module
- call pck.set_id (packaged procedure which sets i++ )
- call pck.get_id (packaged function returning value of i)
finish=> release application Module (***)
What I've seen:
(***) When release statelessly
Two browser sessions (could) get the same Application Module, in which case the 'i' value is incremented 'by' both browser sessions.
(***) When release statefully
Two browser sessions get their 'own' Application Module and manipulate their own 'i' value (even) between consequitive HTTP Requests.
If both situations are explained and viewed correctly, does BC4J application module pooling guarantee that whenever I want to use an AM statefully I get persistent package variable state reproduced in that AM???
If I understand correctly this doesn't mean I get the 'same' AM instance each time, but the BC4J Application Module pooling makes sure that whichever AM I get has state reproduced?
Thx for explaining/affirming?
-J.Scenario:
HttpRequest
starts=> - use SessionCookie API to get an Application Module
- call pck.set_id (packaged procedure which sets i++ )
- call pck.get_id (packaged function returning value of i)
finish=> release application Module (***)
What I've seen:
(***) When release statelessly
Two browser sessions (could) get the same Application Module, in which case the 'i' value is incremented 'by' both
browser sessions.
(***) When release statefully
Two browser sessions get their 'own' Application Module and manipulate their own 'i' value (even) between
consequitive HTTP Requests.
If both situations are explained and viewed correctly, does BC4J application module pooling guarantee that whenever
I want to use an AM statefully I get persistent package variable state reproduced in that AM???In scenario2 above the reason that two different ApplicationModule instances are returned for each
respective session is that the pool has not yet hit its recycle threshold. Once this threshold is hit then the pool will
begin "recycling" the state managed instances and you will observe the same behaviour as in scenario 1.
If I understand correctly this doesn't mean I get the 'same' AM instance each time, but the BC4J Application Module
pooling makes sure that whichever AM I get has state reproduced?This is true for the state that BC4J is aware of (i.e. iterator state, pending transactional changes, etc).
However, BC4J cannot reproduce user state, like the PL/SQL session state that you have defined above. In order
to maintain "user" state it is necessary to:
1. passivate/activate the user state when BC4J passivates/activates its own state. BC4J currently provides a hook for
this via ApplicationModuleImpl.passivateState(Document, Element) and ApplicationModuleImpl.activateState(Element).
2. reset user state when BC4J recycles an ApplicationModule. 9.0.2 does not define a great mechanism for
resetting user state. However, the upcoming maintenance release will provide an ApplicationModuleImpl.reset
hook to clean up session state properly when an ApplicationModule is recycled.
Hope this helps. -
Read access to procedures,function,packages and triggers
Hi,
I created a user with CREATE SESSION,SELECT ANY TABLE privilege. My objective is to create a user with read only access to other schemas. But the newly created user is not able to read procedures,function,packages and triggers. The new user need read access to procedures,function,packages and triggers. What is the priviege required for this access? Please help me to resolve this issue.
Regards,
Mat.Hi,
Grant select all will give select privileges to all schema level objects except procedures,function,packages and triggers. But I need to grant read privileges on these objects to newly created user.
Regards,
Mat. -
Forms 10 and PL/SQL: Using a server package variable
Hi,
I have a variable created at package level in the server,
When I try to assign its value to a Forms item, I get an error.
"Unable to access distant package variable".
What should I do to access this variable?
Many thanksHello,
Add to the package a procedure to set this variable, and also a function that returns the variable content.
Francois -
Package variable g_security_group_id must be set and Collections
we have an app that works fine under an individual user schema/workspace. I exported/imported the app into a new workspace/schema and all is well except for the page that is using a collection. when I call this page, it is throwing a 404 error. when I look in the apache error log I see:
mod_plsql: ORA-20001 Execute ORA-20001: Package variable g_security_group_id must be set.\nORA-06512: at "APEX_030200.F", line 279\nORA-06512: at line 33
Is there some security setting that needs to be set for the schema/workspace where the app was imported into? This appears to be only a collection issue as the new pages in the imported app work fine except for this one. Any ideas about fixing this g_security_group_id or is there a workaround?
Thanks.Another follow up from me. Mine started with a HTTP 404, so in SQL*Plus:
exec dbms_epg.set_dad_attribute('APEX','error-style','DebugStyle');I refreshed the page and "ORA-20001: Package variable g_security_group_id must be set" appeared with all the debug info.
It turned out to be a varchar definition in a package function that was too small for the text I was assigning to it.
Fixed that, then
exec dbms_epg.delete_dad_attribute('APEX','error-style');to turn debug off. -
Calculate the total value of payments with the procedures and triggers?
Hello!
I work for a college project and I have a big problem because professor requires to do it by the examples he gives during the lecture. Here's an example that should be applied to its base, so please help!
I have three table with that should work:
Invoice (#number_of_invoices, date, comm, total_payment, number_of_customer, number_of_dispatch)
where:
number_of_invoices primary key (number),
date (date),
comm (var2),
total_payment is UDT (din - currency in my country) - in this field should be entered value is calculated
number_of_customer and number_of_dispatch (number) are foreign keys and they are not relevant for this example
Invoice_items (#serial_number, #number_of_invoices, quantity, pin)
serial_number primary key (number),
number_of_invoices primary key (number),
quantity (number),
pin foreign keys (number)
Item (#pin, name, price, tax, price_plus_tax)
pin primary key (number),
name (var2),
price, tax, UDT (din) not relevant for this example
price_plus_tax UDT (din)
These are the triggers and procedures with my calculation should be done:
trigger1:
CREATE OR REPLACE TRIGGER "trg1"
BEFORE INSERT OR UPDATE OR DELETE ON Invoice_items
FOR EACH ROW
BEGIN
IF (INSERTING OR UPDATING)
THEN
BEGIN Invoice_items.number_of_invoices := :NEW.number_of_invoices; END;
ELSE
BEGIN Invoice_items.number_of_invoices :=: OLD.number_of_invoices; END;
END IF;
END;trigger2:
CREATE OR REPLACE TRIGGER "trg2"
AFTER INSERT OR UPDATE OR DELETE ON Invoice_items
DECLARE
doc NUMBER := Invoice_items.number_of_invoices;
BEGIN
entire_payment (doc);
END;procedure
CREATE OR REPLACE PROCEDURE "entire_payment" (code_of_doc IN NUMBER) AS
entire NUMBER := 0;
BEGIN
SELECT SUM (a.price_plus_tax * i.quantity) INTO entire
FROM Item a join Invoice_items i on (a.pin = i.pin)
WHERE number_of_invoices = code_of_doc;
UPDATE Invoice
SET total_payment = entire
WHERE number_of_invoices = code_of_doc;
END;As you can see the procedure is called from the triggers, I have a problem at the first trigger, and I think it will be even higher in procedure because UDT, field "total_payment".I was not here a few days because I was trying to get additional information related to this problem. Professor gave me the information that I need to introduce a package and variable to get this thing work. But including that I still have problem. I hope that this time is less of a problem and that someone will be able to help me.
I also noticed that it was not a smart idea to try to translate the names of tables and attributes. That make trouble for me, especially you who are trying to understand and to help me, and absolutely nothing that will change the attribute and the table name will be. So this time I will set out the problem with the original name again to avoid confusion.
So, I try to base Implement optimization technique called: Repeating Single Detail with Master (so writes the slides that I received from professor, I hope that will mean something to you)
These are the lines of code that we get on the slides and should implement in the base, again I remind you that at this time in its original form, without translation.
- First create the package variable:
create or replace
package paket
AS
sifra number(10):=0;
end;This part is ok and it works.
- Secondly, it is necessary to create the first trigger:
create or replace
TRIGGER aktuelna_cena1
BEFORE INSERT OR UPDATE OR DELETE ON cena_artikla
FOR EACH ROW
BEGIN
IF (INSERTING OR UPDATING)
THEN
BEGIN paket.sifra := :NEW.sifra_artikla; END;
ELSE
BEGIN paket.sifra := :OLD.sifra_artikla; END;
END IF;
END;This part is ok and working.
Now the problems begin.
- It is necessary to create another trigger that will call the procedure:
create or replace
TRIGGER aktuelna_cena2
AFTER INSERT OR UPDATE OR DELETE ON cena_artikla
DECLARE
s NUMBER := paket.sifra;
BEGIN
aktuelnacena (s);
END;I suppose the trigger have problem because procedure is not ok.
I will copy error that I get from the compiler:
Error(7,2): PL/SQL: Statement ignored
Error(7,2): PLS-00905: object NUMBER6.AKTUELNACENA is invalid
And finally, it is necessary to create the procedure:
create or replace
PROCEDURE aktuelnacena (SifraPro IN NUMBER) AS
aktCena artikal.aktuelna_cena%type;
BEGIN aktCena:=0;
SELECT cena INTO aktCena
FROM cena_artikla
WHERE sifra_artikla=SifraPro and datum_od=
(select max(datum_od)
from cena_artikla
where sifra_artikla = SifraPro and datum_od<=sysdate);
UPDATE artikal
SET aktuelna_cena = aktCena
WHERE sifra_artikla = SifraPro;
END;I will copy error that I get from the compiler:
Error(10,57): 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 << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge The symbol " " was ignored.
Tables I work with are:
Artikal (sifra_artikla, naziv, aktuelna_cena),
Cena_artikla (sifra_artikla, datum_od, cena)
You will notice that this differs from the first problem, but my task is to implement the two optimization techniques and my base. Both techniques are quite similar and I hope that I now have enough information to help me. I suppose that when this problem is solved the othet one will too!
Thank in advance! -
How to get values from a stored package variable of type record ?
Sir,
In my JClient form, I need to get values from a database stored package variable of type record. And the values are retained in the JClient form for the whole session. The values are copied only once when the form is started.
What is the best way to do that ?
Thanks
StephenStephen,
not sure what your model is, but if it is Business Components, I think I would expose the properties as a client method on the application module. This way all JClient panels and frames will have access to it. You could use a HashMap to store the data in teh app module.
If JDBC supports the record type, then you should be able to call it via a prepared SQL statement. If not, you may consider writing a PLSQL accessor to your stored procedure that returns something that can be handled.
Steve Muench provides the following examples on his blog page
http://otn.oracle.com/products/jdev/tips/muench/stprocnondbblock/PassUserEnteredValuesToStoredProc.zip
http://otn.oracle.com/products/jdev/tips/muench/multilevelstproc/MultilevelStoredProcExample.zip
Frank -
Situation:
SSIS Package designed in SQL Server 2012 - SQL Server Data Tools
Windows 7 - 64 bit.
The package (32 bit) extracts data from a SQL Server db to an Excel Output file, via an OLE DB connection.
It uses 3 package variables:
*) SQLCommand (String) to specify the SQL Statement to be executed by the package
Property path: \Package.Variables[User::ExcelOutputFile].Properties[Value]
Value: f:\Output Data.xls
*) EXCELOutputFIle (String) to specify path and filename of the Excel output file
Property path: \Package.Variables[User::SQLCommand].Properties[Value]
Value: select * from CartOrder
*) VarObjectDataSet (Object) to hold the data returned by SQL Server)
Property path: \Package.Variables[User::VarObjectDataSet].Properties[Value]
Value: System.Object
It consists out of 2 components:
*) Execute SQL Task: executes the SQL Statement passed on via a package variable. The resultng rows are stored in the package variable VarObjectDataSet
*) Script Task: creates the physical output file and iterates VarObjectDataSet to populate the Excel file.
Outcome and issue:The package runs perfectly fine both in SQL Server Data Tools itself and in DTEXECUI.
However, whenever I run it via SQL Server Agent (with 32 bit runtime option set), it returns the errror message below.
This package contains 3 package variables but the error stating that a package variable can not be set, pops up for the VarObjectDataSet only. This makes me wonder if it is uberhaupt possible to set the value of a package variable
of type Object.
Can anybody help me on this please ?
Message
Executed as user: NT Service\SQLSERVERAGENT. Microsoft (R) SQL Server Execute Package Utility Version 11.0.2100.60 for 32-bit Copyright (C) Microsoft Corporation. All rights reserved. Started: 6:40:20 PM DTExec: Could
not set \Package.Variables[User::VarObjectDataSet].Properties[Value] value to System.Object. Started: 6:40:20 PM Finished: 6:40:21 PM Elapsed: 0.281 seconds. The package execution failed. The step failed.
Thank you very much in advance
JurgenHi Visakh,
thank you for your reply.
So, judging by your reply, not all package variables used inside a package need to be set a value for when run in DTEXEC ?
I already tried that but my package ended up in error (something to do with "... invocation ...." and that error is anything but clearly documented. Judging by the error message itself, it looks like it could be just about anything. that is why I asked my
first question about the object type package variable.
Now, I will remove it from the 'set values' list and try another go cracking the unclear error-message " ... invocation ...". Does an error message about " ... invocation ..." ring any bells, now that we are talking about it here ?
Thx in advance
Jurgen
Yes exactly
You need to set values only forthem which needs to be controlled from outside the package
Any variable which gets its value through expression set inside package or through a query inside execute sql task/script task can be ignored from DTExec
Ok I've seen the invocation error mostly inside script task. This may be because some error inside script written in script task. If it appeared after you removed the variable then it may because some reference of variable existing within script task.
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
How to find out Unused Packages/Procedures/Functions/Triggers
Hi,
I have one database. This database is with 7 schemas. Around 1000 triggers are associated with each schema. But the application is using only some triggers.
How to find out the used triggers? Apllications is developed in J2EE.
Same way I want to find out the for Packages/Procedures and Functions.
Any easy way is available?
Please help me.
regards
MathewHi,
>Audit the execution event on the objects by access.
Kindly explain how to enable this auditing.
regards
Mathew -
Package variable g_security_group_id must be set
Hi all,
i have the following problem.
I have a form based on an interactive report.
all standard made out of the apex possibilities.
i have a number of validations, all automatically created by apex, in the form because of the not possible being null of certain columns in my database.
when i press the insert button or save button when i didn't fill in all the necessary fields, i get the following error:
ORA-20001: Package variable g_security_group_id must be set.
Error ERR-1023 Unable perform validations.
OK
i allready checked my validations and i can't find something wrong with it.
they haven't been modified neither after being automatically created by apex
anyone any clue?
thanks in advance,
Mr. TDesmedt,
Can you please demonstrate this on apex.oracle.com?
Scott -
Help needed for loss of package variables!
Seem to have an annoying problem which may just be a misundertanding about libraries.
I have two forms. Initially form 1 created initialised two package variables (of type ora_java.jobject) using the ora_java.new_global_ref function and these persisted across multiple user interactions and existed when form 2 was called (as new form / sharing libraries. Form 2 could call form 1 and the package variables still had values OK.
These package variables were placed in library which only contained this package and was attached to both forms.
I needed more functionality on form 2 so I created a menu module which had to run some code from form 2. I put most of the code (actually imported as it's mostly java classes) into the same library as the package containing the variables and attached the expanded pll to both forms and the menu module. Now when I run form 1 values for the package variables exist for the life of form 1 and form 2, but when I try to reference them after the initial display of form 2 they have disappeared!
Also if form 1 is called again then it behaves differently in that references to the variable are lost after the form is first displayed.
All forms and menus have shared libraries.
I have spent some time playing with different variables and it's the same regardless of the variable type.
Must be something to do with the library I think but don't know what - please help before I tear all my hair out!Ian,
Ensure you have set the SHARE_LIBRARY_DATA parameter in your CALL_FORM statement.
Also deleting the .fmx files, disconnecting from the database and re-building the form usually helps when everything else fails and you have not made any other changes you can think of that may have caused it to break.
Also check that the forms are pointing to the right version of your .pll. Removing the attached library, adding it back and recompiling should do the trick.
Hope this helps, before you lose your hair!
Maybe you are looking for
-
I turn on my mac without hearing the chime boot sound from Apple.. after that im always turning on my Motu (extermal soundcard firewire) i still got that message, by audio midi setup my Motu appears from some minutes and then goes away again.. The sa
-
Can't see photos after iphone is synced
after downloading and installing Itunes 10.5, I did the software upgrade (os5). My phone was backed up and then it asked me if I wanted to restore as a new phone or from backup from the computer. I selected backup from computer (windows XP). Sync
-
Loan table related query wat r the table for loan related
Hi , Can anybody tell me the tablename and field name for 'loan start date" and "monthly payment".It shoulb be connected to VKONT form table fkkvkp.I have tp pass this vkont(contract account number and on the basis of it have to find the loan start d
-
Support question for Oracle Express
Can anyone tell me if Oracle provides security patches for Express? I read an artical from '03 that said they do not. It said Oracle only provides new builds with the patches included. Thanks -Don
-
Hi We're still running Adobe CS3 and whenever we reinstall it for whatever reason we usually download and install the updates again as a single process, via Adobe updater. However right now I've just re-installed CS3 and run Adobe Updater on a laptop