Deterministic function
A function is deterministic if the returned value is completely determined by its entries (arguments).
CN, I get an example for the function deteministic. When exactly can we declare a deterministic function?
Rahul_India wrote:
A function is deterministic if the returned value is completely determined by its entries (arguments).
CN, I get an example for the function deteministic. When exactly can we declare a deterministic function?
A deterministic function basically means that whenever you provide values settings you will always get the same return results (the results are "determined" by the entry and will not change over time)
Might be easier to look at examples of deterministic functions and not deterministic, to better understand...
Non Deterministic - a function that takes an ID of service as a parameter and returns the number of employees in this Department
Non Deterministic - a function that takes no parameters and returns the current date
Deterministic - a function that takes two strings and returns the first characters of the two concatenated
Deterministic - a function that takes two values and applies a non-random mathematical computation before returning the result. adding for example numbers, MOD etc.
Tags: Database
Similar Questions
-
How does a deterministic function caching mechanism works?
Hi all
I read an article on caching by Tom Kyte. http://www.Oracle.com/technetwork/issue-archive/2011/11-Sep/o51asktom-453438.html
In accordance with article the two mechanisms are based on the hash functions. The scalar subquery caching is explained in details. However, there are some questions about the deterministic functions.
Can someone please explain, if there are 32 different values for the column 'owner' in the table of the scene. So, how is it deterministic function cannot be executed 32 times as well as the function result cache?
SQL > create or replace function f (x in varchar2)
Return number
2 DETERMINISTIC
3 as
4 start
5 dbms_application_info.set_client_info
(userenv ('client_info') + 1);
6 return length (x);
7 end;
8.
The function is created.
SQL > start
2: cpu: = dbms_utility.get_cpu_time;
3 dbms_application_info.set_client_info (0);
4 end;
5.
PL/SQL procedure successfully completed.
SQL > select master, f (owner) of scene;
...
72841 selected lines.
SQL > select
2 dbms_utility.get_cpu_time-: cpu cpu_hsecs,.
3 userenv ('client_info')
4 double;
CPU_HSECS USERENV ('CLIENT_INFO')
--------- -----------------------
69 8316
SQL > create or replace function f (x in varchar2)
Return number
2 RESULT_CACHE
3 as
4 start
5 dbms_application_info.set_client_info
(userenv ('client_info') + 1);
6 return length (x);
7 end;
8.
The function is created.
SQL > start
2: cpu: = dbms_utility.get_cpu_time;
3 dbms_application_info.set_client_info (0);
4 end;
5.
PL/SQL procedure successfully completed.
SQL > select master, f (owner) of scene;
...
72841 selected lines.
SQL > select
2 dbms_utility.get_cpu_time-: cpu cpu_hsecs,.
3 userenv ('client_info')
4 double;
CPU_HSECS USERENV ('CLIENT_INFO')
--------- -----------------------
73 32
Thanks in advance!
The deteministic function is deterministic for the duration of a single database call.
SQL * the 'extraction' is such an appeal, and the arraysize failure means issue you a new call every 15 rows.
Tests:
ARRAYSIZE 1 000 1 set) and you should see the County substantially
(2) set arraysize 33, select master, f (owner), count (*) from the group stage by owner, f (owner); and you should see the number drop to 32 (even if perhaps 33 due to a minor detail of how the extractions begin)
Interesting documents here: Oracle SQL | A function deterministic vs scalar subquery caching. Part 1 (and follow the links)
Concerning
Jonathan Lewis
-
details of the virtual columns and deterministic function
Hello
First time that I post a question after the migration of the Forums. So please excuse me if you see errors in format.
Below, I have created a function as deterministic and a table with a virtual column (column refers to the function)
Here are my questions
(1) if I run SELECT * FROM t whenever Oracle will perform the function add_fn?
(2) what is the advantage of DETERMINISTIC? (Documentation says that if we declare a function as deterministic he will attempt to use previously caluculated results for the same set of values. So, when I ever I run SELECT * FROM t oracle executes add_fn only once and it will use the result for the next time. Is my understanding correct.)
Here's the code.
SQL> create or replace function add_fn ( p_n1 in number 2 ,p_n2 in number ) 3 return number deterministic 4 is 5 begin 6 return p_n1+p_n2; 7 end; 8 / Function created SQL> create table t ( n1 number 2 ,n2 number 3 ,n3 number generated always as (add_fn(n1,n2)) virtual 4 ); Table created SQL> insert into t (n1,n2) values (10,20); 1 row inserted SQL> select * from t; N1 N2 N3 ---------- ---------- ---------- 10 20 30 SQL> select * from t; N1 N2 N3 ---------- ---------- ---------- 10 20 30 SQL>
Hello
...
(1) if I run SELECT * FROM t whenever Oracle will perform the function add_fn?(2) what is the advantage of DETERMINISTIC? (Documentation says that if we declare a function as deterministic he will attempt to use previously caluculated results for the same set of values. So, when I ever I run SELECT * FROM t oracle executes add_fn only once and it will use the result for the next time. Is my understanding correct.)
...
(1) oracle will have to evaluate the function. Because only deterministic functions are allowed, this means that it will not necessarily perform the function again; He can get the value cached from a previous call.
I think that the indexed values are actually stored in the index. "SELECT * FROM t;" do not use an index, but if you make another request, then you should be able to get the value of the virtual table of the index, without calling the function or obtaining the value of a cache.
(2) If a function is DETERMINISTIC, the optimizer may decide whether to actually call the function each time, or the cache for better performance results. There is no guarantee that it will always be one or the other. Replace "will be" in your description "may", and then what you say is correct.
-
NVL and deterministic function
Hi all
I recently found a note on deterministic function and its use. As usual check and validate with various relevant articles on the same topic. I decided to check the importance of it with an example below.
The example given, it seems if we happen to use deterministic functions and replace NVL in where clause if appropriate and possible its picking the index created and the query is very effective. We have tested with more records too. This is to say that the index is selected, even when records are questioned are even more than 90% of all of the data in the table for the given condition, is not happens on a normal basis.create table rnd_all_objects as select * from all_objects; create or replace function RND_check_null_var(p_var in varchar) return varchar2 deterministic as begin if p_var is null then return 'X'; else return p_var; end if; end; create index rnd_DET on rnd_all_objects (rnd_check_null_var(status)); select COUNT('X') from rnd_all_objects --where status is null where RND_check_null_var(status) = 'X' /* One can check the plan of the query by commenting the 3rd line of query and uncommenting 2nd line to compare the performance. */
I pray the pros discuss and get rid of my doubts.
Thanks in advance.Here's what I mean:
After doing this:
create index rnd_1 on rnd_all_objects (rnd_check_null_var(status)); create index rnd_2 on rnd_all_objects (nvl(status,'X')); create index rnd_3 on rnd_all_objects (status,'X');
And then what follows, I see no difference between NVL and deterministic function.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> set lines 120 SQL> set pages 999 SQL> SELECT * 2 FROM rnd_all_objects 3 WHERE rnd_check_null_var(status) = 'X'; no rows selected SQL> SQL> select * from table(dbms_xplan.display_cursor); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------- SQL_ID 24rfj6nz0haks, child number 0 ------------------------------------- SELECT * FROM rnd_all_objects WHERE rnd_check_null_var(status) = 'X' Plan hash value: 3930105948 ----------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 117 (100)| | | 1 | TABLE ACCESS BY INDEX ROWID| RND_ALL_OBJECTS | 428 | 902K| 117 (0)| 00:00:02 | |* 2 | INDEX RANGE SCAN | RND_1 | 171 | | 114 (0)| 00:00:02 | ----------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("RND_ALL_OBJECTS"."SYS_NC00016$"='X') Note ----- - dynamic sampling used for this statement (level=2) 23 rows selected. SQL> SQL> SELECT COUNT(*) 2 FROM rnd_all_objects 3 WHERE rnd_check_null_var(status) = 'X'; COUNT(*) ---------- 0 SQL> SQL> select * from table(dbms_xplan.display_cursor); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------- SQL_ID 9pkp2u9xyfd5f, child number 0 ------------------------------------- SELECT COUNT(*) FROM rnd_all_objects WHERE rnd_check_null_var(status) = 'X' Plan hash value: 2866958763 --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 1 (100)| | | 1 | SORT AGGREGATE | | 1 | 6 | | | |* 2 | INDEX RANGE SCAN| RND_1 | 1 | 6 | 1 (0)| 00:00:01 | --------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("RND_ALL_OBJECTS"."SYS_NC00016$"='X') 20 rows selected. SQL> SQL> SELECT * 2 FROM rnd_all_objects 3 WHERE nvl(status,'X') = 'X'; no rows selected SQL> SQL> select * from table(dbms_xplan.display_cursor); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------- SQL_ID 762n8j14mpqk1, child number 1 ------------------------------------- SELECT * FROM rnd_all_objects WHERE nvl(status,'X') = 'X' Plan hash value: 2211738098 ----------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 117 (100)| | | 1 | TABLE ACCESS BY INDEX ROWID| RND_ALL_OBJECTS | 428 | 69764 | 117 (0)| 00:00:02 | |* 2 | INDEX RANGE SCAN | RND_2 | 171 | | 114 (0)| 00:00:02 | ----------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("RND_ALL_OBJECTS"."SYS_NC00017$"='X') Note ----- - dynamic sampling used for this statement (level=2) 23 rows selected. SQL> SQL> SELECT COUNT(*) 2 FROM rnd_all_objects 3 WHERE nvl(status,'X') = 'X'; COUNT(*) ---------- 0 SQL> SQL> select * from table(dbms_xplan.display_cursor); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------- SQL_ID 0bhwd0rc3g7pp, child number 0 ------------------------------------- SELECT COUNT(*) FROM rnd_all_objects WHERE nvl(status,'X') = 'X' Plan hash value: 1668065865 --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 1 (100)| | | 1 | SORT AGGREGATE | | 1 | 6 | | | |* 2 | INDEX RANGE SCAN| RND_2 | 1 | 6 | 1 (0)| 00:00:01 | --------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("RND_ALL_OBJECTS"."SYS_NC00017$"='X') 19 rows selected. SQL> SQL> SELECT * 2 FROM rnd_all_objects 3 WHERE status is null; no rows selected SQL> SQL> select * from table(dbms_xplan.display_cursor); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------- SQL_ID b2zw36qjc8nxq, child number 0 ------------------------------------- SELECT * FROM rnd_all_objects WHERE status is null Plan hash value: 2472515261 ----------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 43 (100)| | | 1 | TABLE ACCESS BY INDEX ROWID| RND_ALL_OBJECTS | 2399 | 264K| 43 (0)| 00:00:01 | |* 2 | INDEX RANGE SCAN | RND_3 | 2399 | | 8 (0)| 00:00:01 | ----------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("STATUS" IS NULL) 19 rows selected. SQL> SQL> SELECT COUNT('X') 2 FROM rnd_all_objects 3 WHERE status is null; COUNT('X') ---------- 0 SQL> SQL> select * from table(dbms_xplan.display_cursor); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------- SQL_ID 03gbx96m8a4hp, child number 0 ------------------------------------- SELECT COUNT('X') FROM rnd_all_objects WHERE status is null Plan hash value: 1659481815 --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 9 (100)| | | 1 | SORT AGGREGATE | | 1 | 5 | | | |* 2 | INDEX RANGE SCAN| RND_3 | 8 | 40 | 9 (0)| 00:00:01 | --------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("STATUS" IS NULL) Note ----- - dynamic sampling used for this statement (level=2) 23 rows selected.
Published by: DomBrooks on November 24, 2010 11:46
-
create indexes on the upper part of the column - reminders function is not deterministic
Hi all
I'm having a problem on a database. When you create an index on an existing table on the upper part of a column, Oracle triggers an ORA-30553. I've done this 40 index other databases, with the same and different versions, without problem. When you create the index on a copy of the table, it is created with success...
Here is the code:
SQL > select * from v version $;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11 g Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE Production 11.2.0.3.0
AMT for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
SQL > CREATE INDEX IDX_SRE_E_MAIL_UPPER on fsynrelatie (upper (sre_e_mail)) tablespace idx;
CREATE the INDEX IDX_SRE_E_MAIL_UPPER on idx tablespace fsynrelatie (upper (sre_e_mail))
*
ERROR on line 1:
ORA-30553: the function is not deterministic
SQL > create table fsynrelatie2 in select * from fsynrelatie;
Table created.
SQL > CREATE INDEX IDX_SRE_E_MAIL_UPPER on fsynrelatie2 (upper (sre_e_mail)) tablespace idx;
The index is created.
SQL > drop table fsynrelatie2;
Deleted table.
SQL > show parameter query_rewrite_enabled
VALUE OF TYPE NAME
------------------------------------ ----------- ------------------------------
query_rewrite_enabled string TRUE
Hi all
Thank you for the answers. I found the problem:
On the table, there are 54 index:
Select index_type, uniqueness, count (*) from user_indexes where table_name = 'FSYNRELATIE '.
Index_type group, uniqueness
INDEX_TYPE SINGLE CHARACTER COUNT (*) FIELD ARE NOT UNIQUE 1 BASED ON A NORMAL FUNCTION ARE NOT UNIQUE 4 NORMAL UNIQUE 3 NORMAL ARE NOT UNIQUE 46 3 unique indexes are the primary key and 2 another witch number field contains unique identifiers for rows in other systems. The domain index is an index of Oracle text on a couple of fields. There are 3 indices of function based on a high on a field and 1 on an individual function. This last clue has caused the problem. Apparently, on the creation, this function is deterministic, but when rolling a new version of the software. It became a non-deterministic function. When I delete the index, my original index on upper (sre_e_mail) has been created successfully! Now, I did the deterministic function again and could recreate the function without problem.
Thanks for your comments!
-
Functions and deterministic performance of gain. What is the reality behind?
Hello Pros,
What is that we really can win using the deterministic function. I've seen some good examples of askthom and discussions. After reading these examples, I feel deterministic functions are rarely used and the benefits are neglected. Is my thoughts right? Requst the pro s to discuss on how used this deterministic function or how better can be used in the right places to take advantage of the performance.
[url http://asktom.oracle.com/pls/apex/f?p=100:11:0:P11_QUESTION_ID:1547006324238 #12928321943595] Example site asktom
Here is the link I had called and taken a few examples out of it.
Thanks in advanceYou can also see the CBO in action (optimize SQL code and do not stuff that is not necessary to determine the final result).
Think the feature is actually executed when you use a SQL as follows? :-)
SQL> exec global.counter := 0; PL/SQL procedure successfully completed. SQL> select count(*) from (select SpecialFoo(level/level) as X from dual connect by level <= 10000); COUNT(*) ---------- 10000 SQL> exec dbms_output.put_line( 'execution='||global.counter ); execution=0 PL/SQL procedure successfully completed. SQL>
-
Function Index problem.
Hello
I have a problem regarding a function function index.
example:
TableName: Test
Column: A, B, C, D
I create the index on the table, column, a test using a user-defined function.
If I do a select on the column, he'll be fine. In other words, I'll get the results you want.
However, if I insert in the table and validation, and I do a query using the 'A' column in the where clause. I don't have any query hits. Its really weird.
Have you ever experienced this problem? and is there an index of function according to back and donts w.r.t.?
Thank you.
MichaelR
If you use a deterministic function really, it works:
create or replace function test_fn (p_number number) return number deterministic is vreturn number := 0; begin if p_number = 1 then vreturn := 55; end if; if p_number = 2 then vreturn := 89; end if; return vreturn; end;
Or, if you reverse the order of your second inserts (insert the folder before the recording of test1 test2) - it works fine.
The reason why you get no results is when you insert the file test1 with a = 2, Oracle executes the function and gets no data, so it assumes that the result is NULL and puts in the index. You said Oracle function is deterministic, so he starts from the principle that any time test_fn (2) is called, it retrieves a null response.
-
Hi gurus,
Just trying to get some info in the function-based index.
Can we have index created in the user-defined function?
Lets say we have a table and I need a counter of a column. Could we have indexes on County?
Select count (name) of employee
WHERE name = "Hary";
Thank you
Tina
The functions used in the function-based index must be DETERMINISTIC.
Example you is not deterministic, that is given the input, the output can vary, because there might be 10 Harys today and 5 tomorrow.
Deterministic functions always return the same value for the same entry.
See: http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/function.htm#LNPLS1580
-
How to make a generic function?
Hi all
I am using oracle 11g.
My question is how can I do a generic function to escape some special charecters.
Currently, I use this way.
Select Replace (replace (replace (FACILITY_ADDRESS,'-','-'), "','------" '),'"','------"') installation;
above, I give for a column, in the same way, I do for some more columns
so I need a generic function, and I'll use this function in each columns that depends on the State.
Thank you
Dale
search for deterministic function?
create or replace function repl (p varchar2) return varchar2 deterministic as
Start
return replace (replace (replace (p, '-','-'), "',' \" ') ', ' "' ','------" ');
end;
----
Ramin Hashimzade
-
Hi friends,
I have a requirement where in I need decode my source table values while inserting in my target table. I usually do my task by performing functions (don't use case and decode). My first question is
(1) is using the function to accomplish these tasks is good. I have several of these conversion requirements.
(2) Clubbing subprogrammes togther in packages is a good habit. But what should be the number of these subprogrammes. I can club togther 100 of this togther functions (a function of the average is 50 lines)? If this is not the case, what should be the thoughts of segregation?
(3) are the oracle integrated like sqrt, length etc. deterministic functions?
This code represents a typical requirement of the mine where in I map my name of source country in the target
ID of country when migrating my data from the source to the target.
I generally functions for this kind of mappings. I have several of these requirements as indicated above and thecreate table source ( emp_id number, empname varchar2(100), sal number, country varchar2(100) ); insert into source values (1,'ALEX',1000,'US'); Insert into source values (2,'RAHUL',2000,'IND'); Insert into source values (3,'KARTIK',3000,'IND'); Insert into source values (4,'SHADOW',5000,'US'); insert into source values(5,'LOUI',1500,'JAP'); Create table source_country_code ( country varchar2(100), abbrv varchar2(100), area number, climate varchar2(100) ); insert into source_country_code values ('UNITED STATES','US',10000,'COLD'); insert into source_country_code values ('INDIA','IND',100000,'HOT'); insert into source_country_code values ('JAPAN','JAP',1000000,'MODERATE'); Create table target_country_code ( country_id number, descr varchar2(100), density number, weather varchar2(100) ); insert into target_country_code values (101,'this is descrition txt 1',1001,'COLD'); insert into target_country_code values (102,'this is descrition txt 2',1001,'HOT'); insert into target_country_code values (103,'this is descrition txt 3',1001,'MODERATE'); create table target ( emp_id number, empname varchar2(100), sal number, country_id number );
cardinality of data is high.
last step,create or replace function transform (in_src_country varchar2) return number deterministic as l_country_id number; l_climate varchar2(1000); begin select climate into l_climate from source_country_code where upper(abbrv)=upper(in_src_country); select country_id into l_country_id from target_country_code where upper(weather)=upper(l_climate); return(l_country_id); exception when no_data_found then return null; end;
so, what I usually do is
insert into target
Select emp_id, empname, sal, transform (country) in the source;
As always, thank you
Rahul
Published by: Rahul K on 5 June 2013 10:51No technique is universally good or bad universally. You must understand your needs, the compromise and what you're trying to optimize for.
If you don't care anything else you are looking for the absolute fastest performance, reduce what you have to do in PL/SQL is a good idea. Most of the people and most of the systems, however, prefer to have code that is a bit slower if it makes the code easier to maintain and easier to write or minimizes the number of places that the code is duplicated. If you attempt to load a data warehouse of company with billions of new lines every night, you're as almost exclusively worry about raw performance. And, if you design correctly, there is that one way to load any particular item of data, you don't have to worry about code duplication because there will always be an INSERT statement that inserts data in a particular table. If you build an OLTP application, on the other hand, it is very likely that there will be many places where you want to do something like search for a value and you are much less concerned about raw performance you're on maintainability and ensure that you do not duplicate the code. In these cases, well-designed functions and procedures are well worth the return miners (so if you do a query of single line as most OLTP systems are generally easier to treat if you write DSS queries that return millions of processing lines billionr lines.
Justin
-
Hello
In our database, we have the following settings for caching the result:
result_cache_max_result integer 5
result_cache_max_size great whole 256256 K
result_cache_mode chain MANUAL
result_cache_remote_expiration integer 0
But we use indicators no results hidden in questions, or tables that are enabled for result caching.
So from my understanding, caching the result should not happen.
But we met a performance problem, and when I checked the AWR report I found this:
And also I found this activity latch:
However, just set result_cache_max_size = 0 fixed to all our questions. Wait no more. Performance as expected.
But how is that possible? I thought with result_cache_mode = manual and not using indicators of result cache or table modes,.
There should be no result at all caching? Any max_size choose?
Can someone help me understand what is happening here?
Thank you and greet.
Daniel
tylerv wrote:
The original poster was not to the point and they actually understand the docs.
Sorry - I'm not okay. As I went to the docs are very EXPLICIT about how to disable the cache of result. If you turn it off, then it is enabled.
The fact that they have tried to do is that when result_cache_mode is set to the default value of the MANUAL, because they showed, it is, while according to the docs 12 c only the results of queries that use the RESULT_CACHE indicator must be stored in the cache of result
Maybe that's where you and OP have misunderstanding. on the RESULT_CACHE_MODE parameter and the parameter values. This seems to be a common misunderstanding.perhaps, because people are not read ALL the relevant articles of the RFSO and only looking at the section for this parameter.
There is NOTHING in the doc of 12 c for this parameter that shows ANY correlation to determine whether the cache is enabled or not.
Refer to the section "Setting the Mode of the result Cache"
https://docs.Oracle.com/database/121/TGDBA/tune_result_cache.htm#CDEJCGJD
As shown in table 15-3 there are ONLY two settings: MANUAL and FORCE. No adjustment said ANYTHING on toggle or if the cache is ENABLED or DISABLED.
... and they were not aware of all the queries that they had used this trick on. When you're ready to values by default and don't use don't not result_cache indicator (as much), it's odd to find the cache of your result are so full.
OK - the USER does not use the indicator result-cache to cache the results of the queries USERS. But if the cache is enabled (size not equal to zero) that according to the quote from the doc above has NO effect on the use of Oracle to cache for queries or non-deterministic function calls.
I think a lot of people may be jumping on the server I mentioned first that article explicitly states that you must set the size to zero to disable hide and seek only to the section on setting the parameters.
And that the "setting mode" section is confusing as it includes a paragraph that uses the expression "If you choose to activate the result cache.
That subsection and the r-phrase likely cause people to think that the setting and the off/on State of the cache are one and the same.
When the result cache is enabled, the database also highlights cache queries that call non-deterministic functions of PL/SQL. When caching
SELECT
statements that call functions, result cache dependencies of data for PL/SQL functions and titles of database objects. However, if the function uses the data that are not followed (such as sequences,SYSDATE
,SYS_CONTEXT
and package variables), uses the cache of result on queries that call this function can produce stale results. In this regard, the behavior of the cache of result is identical to the caching of PL/SQL functions. So always consider the accuracy of the data, as well as performance, if you choose to activate the result cache.But if all associated sections are interpreted in their context, it should clear up the misunderstanding.
If you have a support contract, you can submit a request to have the documentation changed to update mode setting (table 15-3) article to explicitly declare the parameter mode does NOT determine if the cache is enabled or not.
.
-
Parent index for the data in a table?
Is there a way to index a child table with a function to include a column from a parent table?
Example:
I want to see how many children live in a zip code (and their address is listed with their parents)
Select count (*)
class c of child, parent p
where c.parent_id = p.parent_id
and p.zipcode = "12345"
Is there a way to make an index of children with a function that gets parents zip code?
Thanks for the help?
An index on the child table can reference only the columns of the child table. You can't have an index on the child table that is based on information from the parent table.
There are the function-based index, but they may involve only constants and deterministic functions (and, of course, the columns of the table). For example, the child table could have a clue on UPPER (name), where last_name is a column of the table, but he could not have a clue about get_zip (parent_id), where get_zip is a function defined by the user who queries the parent table.
Well - you "might" have a functional indication if you did to be deterministic, but it is not recommended because if the changed zip_code parent would really not deterministic and the change would not be included in the index.
This apart from this code will work properly if the zip_code data does not change:
CREATE TABLE parent (COL1 number primary key, zip VARCHAR2 (5))
create the child table (col1 number, parent_key number);create or replace function get_zip (number p_key) return deterministic varchar2 as
v_zip varchar2 (5);
Start
Select zip from v_zip of the parent where col1 = p_key;
Return v_zip;
end;/
create indexes on children (get_zip (parent_key)) child_zip;
-
Problem with the part decryption dbms_crypto
Hi all
I have a requirement for encryption, decryption of password... with a special key.
So first of all a key is passed to a function MAIN_KEY that is encrypted and the encrypted key will be passed to the function of encryption where the password will be encrypted with the special key.
next part of decryption, decryption function has to decrypt the supplied password, using the special key given earlier, but the code does not work as expected.
Special key encryption and normal encryption works well.
But the decryption function does not work.
Can someone help me solve the problem?
Code below:
<code> create or replace PACKAGE passwd_enc_dec as FUNCTION main_key(p_key in varchar2) RETURN RAW DETERMINISTIC; encryption_type pls_integer; ENCRYPTION_KEY RAW (32); FUNCTION encrypt (p_plainText VARCHAR2) RETURN RAW DETERMINISTIC; FUNCTION decrypt (p_encryptedText RAW) RETURN VARCHAR2 DETERMINISTIC; END; / create or replace package body test as encryption_key raw (32); FUNCTION MAIN_KEY(P_KEY IN VARCHAR2) RETURN RAW DETERMINISTIC IS encryption_key raw(2000); encryption_type pls_integer; begin encryption_type := dbms_crypto.encrypt_des + dbms_crypto.chain_cbc + dbms_crypto.pad_pkcs5; ENCRYPTION_KEY := UTL_RAW.CAST_TO_RAW(P_KEY); return ENCRYPTION_KEY; EXCEPTION WHEN OTHERS THEN NULL; END MAIN_KEY; FUNCTION ENCRYPT (P_PLAINTEXT VARCHAR2) RETURN RAW DETERMINISTIC IS encrypted_raw raw (2000); crypto_key raw(2000); begin crypto_key := main_key(p_plaintext); encrypted_raw := dbms_crypto.encrypt ( src => utl_raw.cast_to_raw (p_plaintext), TYP => ENCRYPTION_TYPE, KEY =>crypto_key); RETURN ENCRYPTED_RAW; EXCEPTION when others then return encrypted_raw; end encrypt; function decrypt (p_encryptedtext raw) return varchar2 deterministic is decrypted_raw raw (2000); dummy varchar2(1000); decrypto_key raw(2000); begin decrypto_key := main_key(p_encryptedtext); decrypted_raw := dbms_crypto.decrypt ( src => p_encryptedtext, typ => encryption_type, key => decrypto_key ); return (utl_raw.cast_to_varchar2 (decrypted_raw)); exception when others then dummy := sqlerrm; return (utl_raw.cast_to_varchar2 (decrypted_raw)); end decrypt; end;
Your encryption done original key but your decryption is not. So what you have to do is to use a key setting more in both encrypt and decrypt function. Try the below
create or replace
PACKAGE passwd_enc_dec
as
FUNCTION main_key(p_key VARCHAR2) RETURN GROSS precautions DETERMINISTIC;
FUNCTION fn_ENCRYPT (p_plainText VARCHAR2, VARCHAR2 p_key) RETURN RAW DETERMINISTIC;
FUNCTION fn_decrypt (p_encryptedText p_key RAW, VARCHAR2) RETURN VARCHAR2 DETERMINISTIC;
END;
/
create or replace
passwd_enc_dec package body
as
encryption_type PLS_INTEGER: = DBMS_CRYPTO. ENCRYPT_DES
+ DBMS_CRYPTO. CHAIN_CBC
+ DBMS_CRYPTO. PAD_PKCS5;
FUNCTION MAIN_KEY(P_KEY IN VARCHAR2) RETURN GROSS IS DETERMINISTIC
encryption_key RAW (32);
Start
encryption_key: = UTL_RAW. CAST_TO_RAW (P_KEY);
RETURN encryption_key;
END MAIN_KEY;
FUNCTION fn_ENCRYPT (P_PLAINTEXT VARCHAR2,
P_KEY VARCHAR2) RETURN GROSS IS DETERMINISTIC
encrypted_raw RAW (2000);
crypto_key RAW (32);
Start
crypto_key: = main_key (P_KEY);
encrypted_raw: = dbms_crypto.encrypt)
SRC-utl_raw.cast_to_raw (p_plaintext) online,
TYP-online encryption_type,
KEY-online crypto_key);
RETURN ENCRYPTED_RAW;
end;
function fn_decrypt (p_encryptedtext, RAW,
P_KEY VARCHAR2) RETURN VARCHAR2 DETERMINISTIC IS
decrypted_raw RAW (2000);
VARCHAR2 (1000) dummy;
decrypto_key RAW (32);
Start
decrypto_key: = main_key (P_KEY);
decrypted_raw: = dbms_crypto.decrypt)
CBC-online p_encryptedtext,
Typ-online encryption_type,
key-online decrypto_key);
Return (utl_raw.cast_to_varchar2 (decrypted_raw)) End Function
end;
end;
/
-
Hi people,
I have a requirement in which I need to write a sql statement. Something like
Select
col1,
col2,
col3,
COL4,
col5,
(select is_table id),-I have to optimize this call
col6,
col7
Of
table_with_ten_million_rows
I'm skeptical of the term used in my topic. that is, a scalar subquery. that is when I get the id of the id_table. But what would be the best way to run this query. There is no use plsql. Is there a way out by which oracle will optimize the call to is_table table for each row scanned. A deterministic function will work better? or this scalar subquery? Or in any other way.
Thank you
Pacmann wrote:
You really should read until the end of the Article knani referred to.
They usually aren't they?
-
Error DBMS_CRYPTO in encrypt and decrypt
Hello
CREATE or REPLACE PACKAGE enc_dec
AS
FUNCTION encrypt (p_plainText VARCHAR2) RETURN RAW DETERMINISTIC;
FUNCTION decrypt (p_encryptedText RAW) RETURN VARCHAR2 DETERMINISTIC;
END;
/
CREATE or REPLACE PACKAGE enc_dec BODY
AS
encryption_type PLS_INTEGER: = DBMS_CRYPTO. ENCRYPT_DES
+ DBMS_CRYPTO. CHAIN_CBC
+ DBMS_CRYPTO. PAD_PKCS5;
encryption_key RAW (32): = UTL_RAW.cast_to_raw ('MyEncryptionKey');
FUNCTION encrypt (p_plainText VARCHAR2) RETURN RAW DETERMINISTIC
IS
encrypted_raw RAW (2000);
BEGIN
encrypted_raw: = DBMS_CRYPTO. ENCRYPT
(
SRC = > UTL_RAW. CAST_TO_RAW (p_plainText),
Typ = > encryption_type,.
key = > encryption_key
);
RETURN encrypted_raw;
END encrypt;
FUNCTION decrypt (p_encryptedText RAW) RETURN VARCHAR2 DETERMINISTIC
IS
decrypted_raw RAW (2000);
BEGIN
decrypted_raw: = DBMS_CRYPTO. DECRYPT
(
SRC = > p_encryptedText,
Typ = > encryption_type,.
key = > encryption_key
);
RETURN (UTL_RAW. CAST_TO_VARCHAR2 (decrypted_raw));
END decrypt;
END;
/
I used the script above to encrypt a column of data. But I get the error below
ERROR on line 1:
ORA-12899: value too large for column
"TEST1". «TESTS ".» "" SECURE_ID "(real: 32,)
maximum: 12)
The column data type is NOT NULL VARCHAR2 (12 CHAR). Where I have to change my script to encrypt this column.
Kind regards
007>
Where I have to change my script to encrypt this column.
>
Oracle knows nothing about your data is encrypted. So like all other columns, the column must be defined with a length that will contain the largest value that it must take. Redefine the column to make it longer.Have you considered using the Oracle Transparent data encryption?
For examples, see this AskTom blog
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:44742967463133And the Doc for the characteristics
http://docs.Oracle.com/CD/B19306_01/network.102/b14268/asotrans.htm
Maybe you are looking for
-
Tempered glass screens are ruining the look of the iPhone?
Hey guys,. So, recently I bought the iPhone 6 Plus and also bought a screen in tempered glass. At the request of the screen, I noticed immediately that the screen has Lint and dirt adhered. I understand the Plus 6 is bent sideways and therefore produ
-
Need new ports USB for Satellite Pro L450D
Hello I ve tried to keep new ports usb for my Toshiba Satellite Pro L450D I ve called Toshiba and they said I have to put it in for repair, but the thing is - it's not is no longer in warranty so that I can t make and send to Toshiba for repair. for
-
Laptop HP 62 357 ca HDMI connection
I tried to use my HDMI on my HP 62 357 ca laptop connection. Could not get a picture on my TV LCD of Shap Aquis. Not compatible message receipt. Any suggestion on what to do.
-
Cannot read nba2k10 on windows 7
I installed nba2k10 on my windows 7 but can not play. I double clicked it, but nothing comes out. When I clicked on the compatibility of evil grows. He ended by saying problems found "incompatible application" I really want to play this game. Pls hel
-
I bought an upgrade from windows vista to windows 7 two days ago and I can download on my laptop... even if my laptop has passed the test. But I can't get hold of someone at microsoft for a refund. I could take care of her through my credit card comp