Package constants in DBMS_CRYPTO
Anyone any idea why I can't reference the constants in the DBMS_CRYPTO package.
I've looked in the package spec and they are there, and if I use the actual value then that works fine, but I can't reference it by name for some reason.
SQL> create view vw_tab1 as select myid, dbms_crypto.hash(myclob, DBMS_CRYPTO.HASH_SH1) as myclob from mytab1;
create view vw_tab1 as select myid, dbms_crypto.hash(myclob, DBMS_CRYPTO.HASH_SH1) as myclob from mytab1
ERROR at line 1:
ORA-06553: PLS-221: 'HASH_SH1' is not a procedure or is undefined
SQL> create view vw_tab1 as select myid, dbms_crypto.hash(myclob, 3) as myclob from mytab1;
View created.
SQL>
Hello
It's not just dbms_crypto, it's package constants in general:
SQL> create or replace package pkg_test
2 as
3 pc_test_const constant number:=1;
4 end;
5 /
Package created.
SQL> select pkg_test.pc_test_const from dual;
select pkg_test.pc_test_const from dual
ERROR at line 1:
ORA-06553: PLS-221: 'PC_TEST_CONST' is not a procedure or is undefined
SQL> select to_char(pkg_test.pc_test_const) from dual;
select to_char(pkg_test.pc_test_const) from dual
ERROR at line 1:
ORA-06553: PLS-221: 'PC_TEST_CONST' is not a procedure or is undefinedI had a look in the docs to try to find the reason but I couldn't.
HTH
David
Similar Messages
-
Accessing package CONSTANT in a SQL query
Hi,
Can anybody explain why I cannot access the package constant in a SQL but can use it in dbms_output.put_line:
SQL> create package scott.xx_test_const_pkg
2 as
3 a constant varchar2(1) :='A';
4 end;
5 /
Package created.
SQL> begin
2 dbms_output.put_line( scott.xx_test_const_pkg.a);
3 end;
4 /
A <------------------THIS WORKS
PL/SQL procedure successfully completed.
SQL> select * from scott.emp where ename=scott.xx_test_const_pkg.a;
select * from scott.emp where ename=scott.xx_test_const_pkg.a <------------------THIS DOES NOT WORK
ERROR at line 1:
ORA-06553: PLS-221: 'A' is not a procedure or is undefined
ThanksYou can't refer to a pl/sql package constant in a sql statement.
Create a function that returns the constant value and then refer to the function in a sql statement. -
I am trying to use a package constant in a query as follows:
SELECT field1 FROM table t WHERE CEIL(sysdate - t.field2) > schema.package.constant
field1 is a name
field2 is a timestamp
constant is an integer indicating the expiration time in days
basically I am trying to find all expired items.
I get the error "ORA-06553: PLS-221: 'constant' is not a procedure or is undefined" on this query.
I use this same query as a cursor in the package itself with no errors.Unfortunately you cannot directly use package global variables in select statements like this.
One workaround is to use bind variables for that:
<p>
SQL> CREATE OR REPLACE PACKAGE pkg
AS
myconstant VARCHAR (20) := 'This is my constant';
END pkg;
Package created.
SQL> VAR myconstant VARCHAR2 (20)
SQL> EXEC :myconstant := pkg.myconstant
PL/SQL procedure successfully completed.
SQL> SELECT :myconstant
FROM DUAL
:MYCONSTANT
This is my constant -
Using package constants in package SQL - acts as bind variable or literal?
I'm looking for confirmation on the performance impact of using package constants in package SQL.
Let's say I have a number of queries in package code that refer to various literals that are prone to typos e.g. "CANCELLED" instead of "CANCELED". To reduce the chances of this happening, I have an APP_GLOBALS package where I declare constants for each literal:
C_CANCELED CONSTANT VARCHAR2(12) := 'CANCELED';And in queries that refer to literal 'CANCELED' I use APP_GLOBALS.C_CANCELED instead. This way the typo is caught during compilation. For example:
BEGIN
--Do something with all 'Canceled' orders
FOR r IN (SELECT order_id
FROM orders
WHERE status = APP_GLOBALS.C_CANCELED)
LOOP
END LOOP;
END;Assume that:
- the STATUS column is indexed
- the possible values are PENDING, APPROVED, CANCELED
- a small percentage of orders are CANCELED
From the optimizer's perspective is the query equivalent to
SELECT order_id
FROM orders
WHERE status = :varor
SELECT order_id
FROM orders
WHERE status = 'CANCELED'?
According to what I see in v$sqltext_with_newlines, it's the first one. Can anyone suggest an alternative way of replacing literals in package SQL to prevent typos? Worst case, I suppose I can start with constants so that it compiles successfully then do a global replace of the constants with the literals.Can anyone suggest an alternative way of replacing literals in package SQL to prevent typos?I cannot think of any. But, here is the thing. If the typos are there, then, it technically is a bug even though both the codes would compile. The bug will be hunted down when the program doesn't work as intended. Wouldn't most typos be caught in unit testing of the code?
Also, if you replace a string literal with a variable, then, maybe (just maybe, depending on your version of the dbms), it may end up picking a different execution plan. That might be an unintended consequence. -
Package constant in select statement
In my Package has several consatnt values...
CREATE OR REPLACE PACKAGE xoec IS
EXPIRED_DESC CONSTANT VARCHAR2(20) := 'Expired';
LIVE CONSTANT VARCHAR2(1) := 'L';
LIVE_DESC CONSTANT VARCHAR2(20) := 'Live';
CANCELLED CONSTANT VARCHAR2(1) := 'X';
CANCELLED_DESC CONSTANT VARCHAR2(20) := 'Cancelled';
END ;
I want to display the constant in Select statement.
select xoec.live from dual;
The above statement through error.
Please help to fix it.
Regards
ManiThis is one of examples.
CREATE OR REPLACE PACKAGE xoec IS
EXPIRED_DESC CONSTANT VARCHAR2(20) := 'Expired';
LIVE CONSTANT VARCHAR2(1) := 'L';
LIVE_DESC CONSTANT VARCHAR2(20) := 'Live';
CANCELLED CONSTANT VARCHAR2(1) := 'X';
CANCELLED_DESC CONSTANT VARCHAR2(20) := 'Cancelled';
function get(in_vc varchar2) return varchar2;
END ;
CREATE OR REPLACE
PACKAGE BODY xoec IS
function get(in_vc varchar2) return varchar2
is
begin
if upper(in_vc) = 'EXPIRED_DESC' then
return EXPIRED_DESC;
elsif upper(in_vc) = 'LIVE' then
return LIVE;
elsif upper(in_vc) = 'LIVE_DESC' then
return LIVE_DESC;
elsif upper(in_vc) = 'CANCELLED' then
return CANCELLED;
elsif upper(in_vc) = 'CANCELLED_DESC' then
return CANCELLED_DESC;
else
null; -- somthing error raising
end if;
end;
END;
SQL> select xoec.get('live') from dual;
XOEC.GET('LIVE')
L -
Grant execute on DBMS_CRYPTO package (11R1)
I figured out I needed to grant my user access to this SYS package using:
SQL> grant execute on DBMS_CRYPTO to lob_demo;
Grant succeeded.
yet after doing this, I still get this error:
SQL> select DBMS_CRYPTO.HASH(bytes, DBMS_CRYPTO.HASH_SH1) from blobslicer where id=1;
select DBMS_CRYPTO.HASH(bytes, DBMS_CRYPTO.HASH_SH1) from blobslicer where id=1
ERROR at line 1:
ORA-06553: PLS-221: 'HASH_SH1' is not a procedure or is undefined
Yet if I use the numeric constant for DBMS_CRYPTO.HASH_SH1 (3), it works:
SQL> select DBMS_CRYPTO.HASH(bytes, 3) from blobslicer where id=1;
F5A7338EFFEB15A49AFC9545393EF685BB51F931
So what am I missing that prevents me from having access to a constant in the package when I can successfully use one of the function of that same package?
Thanks, --DDMaybe, that makes a little bit clearer the difference
between usage of package constants in sql and pl sql...That's what I suspected, thank you for hammering the point home Maxim.
The taken away for me is that package constants are not available to SQL code, only to PL/SQL code. (irrelevant of their type most likely).
I actually tried to grant my user SELECT privileges on the package, because accessing a constant from a package is more akin to SELECT than EXECUTE, but of course one cannot do that.
Thank you both again for the help. --DD -
Error when useing DBMS_CRYPTO package in reports 10g
hi all,
i wrote a package which use dbms_crypto, there are functions to crypto userid and decrypo userid.
in report 6i it work fine it cryptos and decrpts. when i use in reports 10g it gives this error.
-28817 ORA-28817: PL/SQL function returned an error.
ora-06512: at "SYS.DBMS_CRYPTO_FFI", line 67
ORA-06512: at "SYS.DBMS_CRYPTO", line 41
ora-06512: at "YBS.SIFRELE", line 26
the packege like this;
PACKAGE BODY SIFRELE
IS
function sicil_sifrele (p_sicil_no IN varchar2) RETURN varchar2
IS
p_key RAW(128);
p_sicil_raw RAW(128);
p_encrypted_raw RAW(128);
BEGIN
p_key := utl_raw.cast_to_raw(to_char(sysdate,'mmyyyydd'));
p_sicil_raw := utl_raw.cast_to_raw(p_sicil_no);
p_encrypted_raw := dbms_crypto.encrypt(src => p_sicil_raw,
typ => dbms_crypto.des_cbc_pkcs5, key => p_key);
return (utl_raw.cast_to_varchar2(p_encrypted_raw));
END;
FUNCTION sicil_coz ( p_encrypted_raw IN RAW) RETURN varchar2
IS
p_key RAW(128);
p_decrypted_raw RAW(128);
sicil_donen VARCHAR2(250);
BEGIN
p_key := utl_raw.cast_to_raw(to_char(sysdate,'mmyyyydd'));
p_decrypted_raw := dbms_crypto.decrypt(src => p_encrypted_raw,
typ => dbms_crypto.des_cbc_pkcs5, key => p_key);
sicil_donen := utl_raw.cast_to_varchar2(p_decrypted_raw);
return (sicil_donen);
END;
END;
thanks.
eserHello,
You should create a "wrapper function"
Create a function in the database that will call dbms_crypto.encrypt / dbms_crypto.decrypt and call this function in Reports.
(The problem here seems to be the reference to dbms_crypto.des_cbc_pkcs5)
Regards -
Error when using DBMS_CRYPTO package in reports 10g
hi all,
i wrote a package which use dbms_crypto, there are functions to crypto userid and decrypo userid.
the packege like this;
PACKAGE BODY SIFRELE
IS
function sicil_sifrele (p_sicil_no IN varchar2) RETURN varchar2
IS
p_key RAW(128);
p_sicil_raw RAW(128);
p_encrypted_raw RAW(128);
BEGIN
p_key := utl_raw.cast_to_raw(to_char(sysdate,'mmyyyydd'));
p_sicil_raw := utl_raw.cast_to_raw(p_sicil_no);
p_encrypted_raw := dbms_crypto.encrypt(src => p_sicil_raw,
typ => dbms_crypto.des_cbc_pkcs5, key => p_key);
return (utl_raw.cast_to_varchar2(p_encrypted_raw));
END;
FUNCTION sicil_coz ( p_encrypted_raw IN RAW) RETURN varchar2
IS
p_key RAW(128);
p_decrypted_raw RAW(128);
sicil_donen VARCHAR2(250);
BEGIN
p_key := utl_raw.cast_to_raw(to_char(sysdate,'mmyyyydd'));
p_decrypted_raw := dbms_crypto.decrypt(src => p_encrypted_raw,
typ => dbms_crypto.des_cbc_pkcs5, key => p_key);
sicil_donen := utl_raw.cast_to_varchar2(p_decrypted_raw);
return (sicil_donen);
END;
END;
in report 6i it work fine cryptos and decrpts. when i use in reports 10g it gives this error.
-28817 ORA-28817: PL/SQL function returned an error.
ora-06512: at "SYS.DBMS_CRYPTO_FFI", line 67
ORA-06512: at "SYS.DBMS_CRYPTO", line 41
ora-06512: at "YBS.SIFRELE", line 26
thanks...Hello,
You should create a "wrapper function"
Create a function in the database that will call dbms_crypto.encrypt / dbms_crypto.decrypt and call this function in Reports.
(The problem here seems to be the reference to dbms_crypto.des_cbc_pkcs5)
Regards -
Constant declaration of VARRAY index by varchar2 within package header
Hi there
I'm looking for the correct syntax to declare a constant
of a varray type which is indexed by varchar2. I've tried
the following:
create or replace package nl_types
is
TYPE nt_assoc_small IS TABLE OF INTEGER INDEX BY VARCHAR2(32);
nl_bindcnt constant nt_assoc_small ('xml_gkregnl') := 3;
end;
I know this array hat just one element, but there will
be even more when I got this example case to work. As
I tried to compile this package, the compiler said:
13/16 PL/SQL: Declaration ignored
13/25 PLS-00566: type name "NT_ASSOC_SMALL" cannot be constrained
13/70 PLS-00320: the declaration of the type of this expression is
incomplete or malformed
O.K. then: Does anybody know the "wellformed" declaration
for this kind of varray?
Thanx in advance,
Martin.That's not a VARRAY declaration, it's a PL/SQL table / associative array.
There is no syntax to declare the contents of an associative array in-line.
They can either be assigned to directly or populated by BULK COLLECT (except for associative arrays indexed by VARCHAR2). Perhaps you could assign the return value of a function?
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> CREATE OR REPLACE PACKAGE types AS
2
3 TYPE associative_array_type IS TABLE OF INTEGER
4 INDEX BY VARCHAR2 (32);
5
6 FUNCTION default_associative_array_type
7 RETURN associative_array_type;
8
9 END;
10 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY types AS
2
3 FUNCTION default_associative_array_type
4 RETURN associative_array_type
5 IS
6 associative_array associative_array_type;
7 BEGIN
8 associative_array ('xml_gkregnl') := 3;
9 RETURN associative_array;
10 END;
11
12 END;
13 /
Package body created.
SQL> CREATE OR REPLACE PACKAGE constants AS
2
3 associative_array CONSTANT types.associative_array_type :=
4 types.default_associative_array_type;
5
6 END;
7 /
Package created.
SQL> SET SERVEROUTPUT ON;
SQL> BEGIN
2 DBMS_OUTPUT.PUT_LINE (
3 'constants.associative_array (''xml_gkregnl'') => ' ||
4 constants.associative_array ('xml_gkregnl'));
5 END;
6 /
constants.associative_array ('xml_gkregnl') => 3
PL/SQL procedure successfully completed.
SQL> -
I am trying to figure out the best way to implement a CONSTANTS class for my project. I have all of my files defined in a package. And I have included the class where I defined my package constants in that package. I have defined them like:
static final int a = 1;
So they have package level access (not public/private). And I can access them when a direct call:
int b = consts.a;
But, I am a little confused on the use of defining this way, using import, package scope, interfaces. Looking at the tutorial:
http://java.sun.com/docs/books/tutorial/together/index.html
I see that they have a constants class that is an interface which they also import into other classes when they want to use it AND they call it explicitly with the class name prefix. Running a little test, I see that without any of this, a class can access a variable defined without public/private definition and/or package and/or interface and/or imports. So, it doesn't seem like any of these are really necessary.
Simple question: What is the best way to define and access constants in one place for a project?A question many of us ask but never really come up with a satisfactory answer.
Firstly are they real constants? I.e. will they never change in the life of the program (if they might change then they should be in a config file).
Next thing to bare in mind is how the java compiler works. Say I have class A
class A
public static final int A_NUMBER = 0;
}which is use somewhere else
class B
void aMethod() {
int something = A.A_NUMBER;
}Now if I compile it all, it works fine. If I know go and change A_NUMBER to be another value and recompile class A only, then the reference to A.A_NUMBER will still be 0!! The compiler is actually copying the value accross.
So, next question to ask. what is you build policy? Do you always recompile everything? If so then you should be alright with a load of static final values in an interface somewhere.
Other things to bare in mind is were are constants used. If the constants are used in one class only then they should be defined in this class with a private modifier.
I would normally suggest still using get methods to get hold of constants, just to make sure the senario with the compiler never happens.
If you tell me what your constants are I can probably give you a better ideas as to what to do with them.
One the whole, the only time you would want to put them all in one place was if you wanted to find them quickly for changing them. In which case you should have a config file instead. -
Is there a way to invoke DBMS_CRYPTO directly from SQL?
When I try to do this:-
INSERT INTO MyTable ( MyName ) VALUES
DBMS_CRYPTO.ENCRYPT(UTL_I18N.STRING_TO_RAW ('Graeme', 'AL32UTF8'),
DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5,
UTL_I18N.STRING_TO_RAW('0123456789ABCDEF', 'AL32UTF8')
I get
ORA-06553: PLS-221: 'ENCRYPT_AES128' is not a procedure or is undefined.
However if I create a PL/SQL function MyEncrypt to do the same thing
INSERT INTO MyTable Name VALUES ( MyEncrypt('Graeme') );
it works fine. Hmm.
Is there a way to invoke the DBMS_CRYPTO package's functions directly from SQL?
Edited by: sparky62 on Nov 23, 2008 7:46 PMYou cannot reference packaged constants from pure SQL. You could replace the argument
DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5,with the equivalent constants, i.e.
6 + 256 + 4096Of course, that isn't likely to be nearly as readable and/or maintainable as the first approach.
Justin -
Can DBMS_CRYTO Package encrypt using a HMAC-SHA-1 Signature?
Hello there,
I'm trying to integrate Google Checkout (GC) into a friend's APEX-created website, running on a 10g Release 2 database (Express Edition).
Google request that XML representing an order be encrypted using a HMAC-SHA-1 signature, which will consist of the GC Merchant ID.
I'm very new to crptography in the Oracle Database, but had heard of the DBMS_CRYPTO Package. However, I could not identify a package constant representing the HMAC-SHA-1 signature. The closest I could come was HMAC-SH1. I don't think that's quite the same thing.
Can anybody offer any assistance?
Kind Regards.
JamesWhat was wrong here was that the key was not a) converted from modified base64 and then b) not converted back to binary.
This now generates the correct signing value
set define off
DECLARE
l_key_src VARCHAR2(100) := 'vNIXE0xscrmjlyV-12Nj_BvUPaw=';
l_key_b64 varchar2(100) := translate(l_key_src,'-_','+/');
l_key_bin raw(2000);
l_string VARCHAR2(100) := utl_url.escape('/maps/api/geocode/json?address=New+York&sensor=false&client=clientID');
l_sig_mac RAW(2000);
l_base64_sig_mac VARCHAR2(2000);
l_base64_sig_mac_alter VARCHAR2(2000);
BEGIN
l_key_bin := utl_encode.base64_decode(UTL_I18N.string_to_raw(l_key_b64, 'AL32UTF8'));
l_sig_mac :=DBMS_CRYPTO.mac(UTL_I18N.string_to_raw(l_string, 'AL32UTF8'), DBMS_CRYPTO.hmac_sh1,l_key_bin);
l_base64_sig_mac := UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(l_sig_mac));
l_base64_sig_mac_alter := translate(l_base64_sig_mac,'+/','-_');
DBMS_OUTPUT.put_line('MAC Signature (Base64-encoded): ' || l_base64_sig_mac);
END; -
Using named constants in SQL rather than magic numbers
We are running Oracle 7.3.4. In our system we have a number of
tables that just store static data. For example, we have a table
that stores the different types of statuses that a docket can
have:
Docket_Status: docket_status_id NUMBER(8), description VARCHAR
(100)
It has a small number of records as follows:
docket_status_id description
1 New
2 Issued
3 Completed
4 Finalised
and so on.
When we want to select all of the dockets with a status of
"New", we could do something like:
select d.*
from docket d
where d.docket_status_id = 1
However, this SQL statement is not particularly readable or
maintainable since the "1" is meaningless unless you have
memorised the id fields for the docket.
So we defined constants for each of the static data tables, in a
package of their own:
PACKAGE DOCKET_STATUS_PL IS
New_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 1;
Issued_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 2;
Completed_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 3;
and so on.
Ideally you could directly reference these values in SQL as
follows:
select d.*
from docket d
where d.docket_status_id = Docket_Status_Pl.New_Id
But SQL does not let allow this - an invalid column error is
raised when this is parsed.
So the package must then be changed to have functions pass back
each of the constants.
PACKAGE DOCKET_STATUS_PL IS
FUNCTION New_Id RETURN NUMBER;
PRAGMA RESTRICT_REFERENCES(New_Id, WNDS, WNPS);
FUNCTION Issued_Id RETURN NUMBER;
PRAGMA RESTRICT_REFERENCES(Issued_Id, WNDS, WNPS);
FUNCTION Completed_Id RETURN NUMBER;
PRAGMA RESTRICT_REFERENCES(Completed_Id, WNDS, WNPS);
and so on.
PACKAGE BODY DOCKET_STATUS_PL IS
N_New_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 1;
N_Issued_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 2;
N_Completed_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 3;
FUNCTION New_Id RETURN NUMBER IS
BEGIN
RETURN N_New_Id;
END;
FUNCTION Issued_Id RETURN NUMBER IS
BEGIN
RETURN N_Issued_Id;
END;
and so on.
Once these functions have been defined in the packages, they can
be called in a SQL statement as follows:
select d.*
from docket d
where d.docket_status_id = Docket_Status_Pl.New_Id
This makes the SQL statement a lot more readable, but has the
unfortunate by-product of having the Docket_Status_Pl.New_Id
function called for every row in the docket table. Although it
is very quick to call, once there are thousands of records in
the docket table this can add up to a lot of extra
time/processing.
An alternative is to select the constant from the dual table as
follows:
select d.*
from docket d
where d.docket_status_id = (select Docket_Status_Pl.New_Id from
dual)
This works but is not really an ideal solution, since it
decreases the readability of the SQL statement.
Does anyone know of alternatives to this approach? Ideally
package constants could be referenced from SQL, but this does
not work under our version of Oracle. Do any later versions
support this ability?
Any suggestions would be much appreciated.
nullI don't understand why you cannot just select on the description
column if you don't no the id. If speed is a problem create a
unique not null index on the column description. Technically
this should have been done since your id column is a is not
the "REAL" primary key.
Having said that you could also create a view on top of this
table which mimics your package.
CREATE OR REPLACE VIEW name_of_view AS
SELECT DECODE(docket_status_id, 1, 'New_id',
2, 'Issued_Id',
3, 'Completed_Id',
'OTHER') alt_description,
docket_status_id description
FROM name_of_table
then select * from name_of_view
where alt_description = 'New_id'
Geoff Hardy (guest) wrote:
: We are running Oracle 7.3.4. In our system we have a number of
: tables that just store static data. For example, we have a
table
: that stores the different types of statuses that a docket can
: have:
: Docket_Status: docket_status_id NUMBER(8), description VARCHAR
: (100)
: It has a small number of records as follows:
: docket_status_id description
: 1 New
: 2 Issued
: 3 Completed
: 4 Finalised
: and so on.
: When we want to select all of the dockets with a status of
: "New", we could do something like:
: select d.*
: from docket d
: where d.docket_status_id = 1
: However, this SQL statement is not particularly readable or
: maintainable since the "1" is meaningless unless you have
: memorised the id fields for the docket.
: So we defined constants for each of the static data tables, in
a
: package of their own:
: PACKAGE DOCKET_STATUS_PL IS
: New_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 1;
: Issued_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 2;
: Completed_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 3;
: and so on.
: Ideally you could directly reference these values in SQL as
: follows:
: select d.*
: from docket d
: where d.docket_status_id = Docket_Status_Pl.New_Id
: But SQL does not let allow this - an invalid column error is
: raised when this is parsed.
: So the package must then be changed to have functions pass back
: each of the constants.
: PACKAGE DOCKET_STATUS_PL IS
: FUNCTION New_Id RETURN NUMBER;
: PRAGMA RESTRICT_REFERENCES(New_Id, WNDS, WNPS);
: FUNCTION Issued_Id RETURN NUMBER;
: PRAGMA RESTRICT_REFERENCES(Issued_Id, WNDS, WNPS);
: FUNCTION Completed_Id RETURN NUMBER;
: PRAGMA RESTRICT_REFERENCES(Completed_Id, WNDS, WNPS);
: and so on.
: PACKAGE BODY DOCKET_STATUS_PL IS
: N_New_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE :=
1;
: N_Issued_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE :=
2;
: N_Completed_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE :=
3;
: FUNCTION New_Id RETURN NUMBER IS
: BEGIN
: RETURN N_New_Id;
: END;
: FUNCTION Issued_Id RETURN NUMBER IS
: BEGIN
: RETURN N_Issued_Id;
: END;
: and so on.
: Once these functions have been defined in the packages, they
can
: be called in a SQL statement as follows:
: select d.*
: from docket d
: where d.docket_status_id = Docket_Status_Pl.New_Id
: This makes the SQL statement a lot more readable, but has the
: unfortunate by-product of having the Docket_Status_Pl.New_Id
: function called for every row in the docket table. Although it
: is very quick to call, once there are thousands of records in
: the docket table this can add up to a lot of extra
: time/processing.
: An alternative is to select the constant from the dual table as
: follows:
: select d.*
: from docket d
: where d.docket_status_id = (select Docket_Status_Pl.New_Id
from
: dual)
: This works but is not really an ideal solution, since it
: decreases the readability of the SQL statement.
: Does anyone know of alternatives to this approach? Ideally
: package constants could be referenced from SQL, but this does
: not work under our version of Oracle. Do any later versions
: support this ability?
: Any suggestions would be much appreciated.
null -
Weired behaviour while we compile PL/SQL package
Hi All,
We have one package where we have declared few constants those we are using all over our application code. By mistake, one of the developer declared one constant twice, we didn't notice it until today while chasing down a bug...
I was under impression that we can not declare same variable or constants twice in the same package/procedure/block. But surprisingly, if we are not using the same variable in that block, (We defined it global packaged constant) we are not getting compilation error or warning. Does anyone know anything about this.
Oracle Configuration:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - ProductionThanks in advance.
Thanks,
Dharmesh PatelI would again point out that I do not see the results as you describe. see the output from 9.2.0.3 below. Both times it gives me the same result.
As shown above by James, it throws out the correct error under 10G. But as far as I see, it seems to be consistent under Oracle9i release 9.2.0.3 and 9.2.0.5.
I think it might be the time for your database to be upgraded to at least 9.2.0.3 release.
SQL> CREATE OR REPLACE PACKAGE P00_Constants AS
2 SubType201 CONSTANT VARCHAR2(3) := '201';
3 SubType202 CONSTANT VARCHAR2(3) := '202';
4 SubType202A CONSTANT VARCHAR2(4) := '202A';
5 SubType202P CONSTANT VARCHAR2(4) := '202P';
6 SubType202I CONSTANT VARCHAR2(4) := '202I';
7 SubType203 CONSTANT VARCHAR2(3) := '203';
8 SubType201 CONSTANT VARCHAR2(3) := '204';
9
10 Yesflag CONSTANT VARCHAR2(3) := 'YES';
11 ------------------------------------------------------
12
13 --- <summary>This function returns value of YES</summary>
14 --- <param name="none"></param>
15 --- <exception cref="none"> </exception>
16 FUNCTION GetyesFlag RETURN VARCHAR2;
17 PRAGMA RESTRICT_REFERENCES(GetYesFlag,
18 WNDS,
19 WNPS);
20 END P00_Constants;
21 /
Package created.
SQL> SHOW ERRORS
No errors.
SQL>
SQL> CREATE OR REPLACE PACKAGE BODY P00_Constants AS
2 ---function getYesFlag
3 FUNCTION GetYesFlag RETURN VARCHAR2 IS
4 BEGIN
5 RETURN YesFlag;
6 END;
7 END P00_Constants;
8 /
Package body created.
SQL> SHOW ERRORS
No errors.
SQL>
SQL> CREATE OR REPLACE PACKAGE Test_Constant IS
2 -- Author : DPATEL
3 -- Created : 10/12/2004 8:20:12 AM
4 -- Purpose : To test the duplicate constants defined in P00_Constants package
5 -- Public type declarations
6 FUNCTION getSubType RETURN VARCHAR2;
7 END Test_Constant;
8 /
Package created.
SQL> SHOW ERRORS
No errors.
SQL>
SQL> CREATE OR REPLACE PACKAGE BODY Test_Constant IS
2 FUNCTION getSubType RETURN VARCHAR2 IS
3 mySubType VARCHAR2(10);
4 BEGIN
5 mySubType := P00_Constants.SubType201;
6 RETURN(mySubType);
7 END;
8 END Test_Constant;
9 /
Package body created.
SQL> SHOW ERRORS
No errors.
SQL>
SQL> -- Test Script
SQL> SET SERVEROUTPUT ON
SQL> BEGIN
2 Dbms_OutPut.Put_Line('Result is: ' || test_constant.getsubtype);
3 END;
4 /
Result is: 204
PL/SQL procedure successfully completed.
SQL> ALTER PACKAGE P00_Constants COMPILE
2 /
Package altered.
SQL> SET SERVEROUTPUT ON
SQL> BEGIN
2 Dbms_OutPut.Put_Line('Result is: ' || test_constant.getsubtype);
3 END;
4 /
Result is: 204
PL/SQL procedure successfully completed.
SQL>
SQL> disconnect
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production
SQL> -
Optimization of using text constants
Does Forms compiler optimize using text constants when it make *.fmx
file, if yes then how?
What I mean. In many cases Forms programmers use text constants to do
any actions, for sample:
- do_key('EXECUTE_QUERY');
- if (:system.mode = 'ENTER-QUERY') then /* ... */ end if;
- execute_trigger('ON-POPULATE-DETAILS');
- show_alert('ASK_SAVE');
- go_block('ORDERS') or go_item('ORDERS.NAME');
- set_block_property(bid,DEFAULT_WHERE,':orders.pay > '||:r.pay_rate);
As I have undestood myself, Forms divide such constant on types:
- standart text constants('EXECUTE_QUERY','ENTER-QUERY' ...);
- user's text constants ('ASK_SAVE','ORDERS.NAME');
And Forms do any optimization with standart text constants: in *.fmx file
I found only one enter for every from such constants.
But for user's text constants Forms does not optimization: in *.fmx file
I found more then one enter for such constants.
If above is right then is there benefit from creating a package in form
module and creating constants in the package, that contain frequently used
user's text constants(block and items names, e.t.c.) and then writing down
in program these package constants instead of user's text constants?I get to answer my own question. I found a workaround should you ever what to be sure a certain font is used and not replaced. Granted, this will add my download time but you at least can preserve the look.
Simply make any text with a shadow. But make the offset 0 and the transparency to 1 (you can't make it 0). You won't even notice the "shafow" and the text will be made into a graphic every time.
Stephen
Maybe you are looking for
-
My Queries are not caching even i enabled chaching in NQScinfig.ini file. How to verify and resolve the problem. Please suggest the answer.
-
Huge question PLEASE HELP ME!!!!!
Okay, so I'm returning my iPod to get it fixed. But I dont have the receipt anymore because it was on my hard drive and it broke. So I dont have that any more. Will I still be able to return it? I mean, they can look at the serial number and stuff an
-
Dear all I am getting the below error while changing the vendor master. "Tax code 1 must be numerical Message no.AR144 "
-
Problem in Opening Workflow Applet
Hi, I have installed Stellent 7.5.1 All the components are working fine, if i'm trying to open Workflow i'm getting pop saying this message "unable to start the application workflow. Failed to response from host Server returned HTTP response code:502
-
Simple question - set in & out points
I have a LONG MP3 file that I need to pull specific parts out & save them as separate MP3s. How do I set the in & out points and export using Garageband? I'm assuming I would just position the in & out points at the beginning/end of the audio I want