Skip to main content
Solved

Using DBMS_RANDOM in Quick Reports

  • February 26, 2020
  • 9 replies
  • 333 views

dsj
Superhero (Partner)
Forum|alt.badge.img+22
  • Superhero (Partner)
  • 831 replies

Hi All,

 

Seems quick report SQL does not allow DBMS_RANDOM.VALUE.

Error Message:

Forbidden PLSQL code rejected: "DBMS_RANDOM"

FNDSQLFORBIDDEN: Forbidden PLSQL code rejected: "DBMS_RANDOM"

 

Is there an alternate to get a random value in a quick report?

 

Cheers!

Best answer by eqbstal

DSJ,

Is the following ‘allowed’ in your situation:

select regexp_substr(sys_guid(), '\d') from dual;

It is pseudo random, but it is quite simple to implement, I think.

Regards,
Steve

View original
Did this topic help you find an answer to your question?

9 replies

CallumW
Superhero (Partner)
Forum|alt.badge.img+15
  • Superhero (Partner)
  • 128 replies
  • February 26, 2020

Put it in a package?

 

Header:

 FUNCTION getRandom(val_ IN NUMBER, val2_ IN NUMBER) RETURN NUMBER;

Body: 

FUNCTION getRandom(val_ IN NUMBER, val2_ IN NUMBER) RETURN NUMBER IS
 random_ NUMBER;
 BEGIN
 random_ := DBMS_RANDOM.value(val_, val2_);
 RETURN random_;
END getRandom;

Quick Report: 

Output:

 


dsj
Superhero (Partner)
Forum|alt.badge.img+22
  • Author
  • Superhero (Partner)
  • 831 replies
  • February 26, 2020

Thanks @CallumW!

Creating a new package is something we avoid in a customer environment due to licensing, version handling and permission setup issues. I was wondering if this can be solve using already existing things :sunglasses:

 

/DSJ


CallumW
Superhero (Partner)
Forum|alt.badge.img+15
  • Superhero (Partner)
  • 128 replies
  • February 26, 2020

I can’t see any other way around it, other than by having a customisation to get RnD to take out the code which is blocking it. 
 

 


eqbstal
Superhero (Partner)
Forum|alt.badge.img+21
  • Superhero (Partner)
  • 672 replies
  • Answer
  • February 26, 2020

DSJ,

Is the following ‘allowed’ in your situation:

select regexp_substr(sys_guid(), '\d') from dual;

It is pseudo random, but it is quite simple to implement, I think.

Regards,
Steve


CallumW
Superhero (Partner)
Forum|alt.badge.img+15
  • Superhero (Partner)
  • 128 replies
  • February 27, 2020

This is an alternative, but it’s limited to the set ranges 

 

SELECT substr(to_char(systimestamp, 'FF6'), 6, 6) FROM dual; -- Random from 0 to 9
SELECT substr(to_char(systimestamp, 'FF6'), 5, 6) FROM dual; -- Random from 0 to 99
SELECT substr(to_char(systimestamp, 'FF6'), 4, 6) FROM dual; -- Random from 0 to 999
SELECT substr(to_char(systimestamp, 'FF6'), 3, 6) FROM dual; -- Random from 0 to 9999
SELECT substr(to_char(systimestamp, 'FF6'), 2, 6) FROM dual; -- Random from 0 to 99999
SELECT to_char(systimestamp, 'FF6') FROM dual; -- Random from 0 to 999999


 


dsj
Superhero (Partner)
Forum|alt.badge.img+22
  • Author
  • Superhero (Partner)
  • 831 replies
  • February 28, 2020

Thanks both for the answers.

I put both answers to test and here’s the result

 

Quick report SQL

SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')   FROM dual 
union all 
SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')  FROM dual 
union all 
SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')  FROM dual 
union all 
SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')  FROM dual 
union all 
SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')  FROM dual

 

result

 

I read somewhere that systimestamp    precision varies with DB settings and it could be the reason I’m getting same value with the systimestamp?

 

Therefore I choose answer by @eqbstal 

 

Thanks both!


CallumW
Superhero (Partner)
Forum|alt.badge.img+15
  • Superhero (Partner)
  • 128 replies
  • February 28, 2020
dsj wrote:

Thanks both for the answers.

I put both answers to test and here’s the result

 

Quick report SQL

 SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')   FROM dual 
union all 
SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')  FROM dual 
union all 
SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')  FROM dual 
union all 
SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')  FROM dual 
union all 
SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')  FROM dual

 

result

 

I read somewhere that systimestamp    precision varies with DB settings and it could be the reason I’m getting same value with the systimestamp?

 

Therefore I choose answer by @eqbstal 

 

Thanks both!


Makes sense. When I run regexp_substr(sys_guid(), '\d') I only get 9 returned every time


  • Do Gooder (Customer)
  • 8 replies
  • February 29, 2020

A) You can use a custom logical unit (rnd.zip in rnd.docx).

1. Create a logical unit: MyRnd
2. Create a persistent field (numeric): p
3. Create a read only field (numeric): Rng
      a) argument: t.cf$_p
      b) select statment: select dbms_random.value +:cf$_p -:cf$_p from dual
  4) Then Approve & Publish LU

In report
select ifsapp.my_rnd_clp.Get_Cf$_Rnd(0) from dual

 

B)  You can use a IAL (my_rnd.ial.txt)

SELECT x.rnd FROM ifsinfo.my_rnd x

 


durette
Superhero (Customer)
Forum|alt.badge.img+19
  • Superhero (Customer)
  • 525 replies
  • March 26, 2020

This will return a pseudo-random number between 0 and 1.

 

SELECT TO_NUMBER(sys_guid(), 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') / POWER(2, 128) FROM DUAL


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings