Skip to main content
Solved

Using DBMS_RANDOM in Quick Reports

  • February 26, 2020
  • 9 replies
  • 338 views

dsj
Ultimate Hero (Partner)
Forum|alt.badge.img+22
  • Ultimate Hero (Partner)
  • 896 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+16
  • Superhero (Partner)
  • 129 replies
  • February 26, 2020

Put it in a package?

 

Header:

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

Body: 

1FUNCTION getRandom(val_ IN NUMBER, val2_ IN NUMBER) RETURN NUMBER IS
2 random_ NUMBER;
3 BEGIN
4 random_ := DBMS_RANDOM.value(val_, val2_);
5 RETURN random_;
6END getRandom;

Quick Report: 

Output:

 


dsj
Ultimate Hero (Partner)
Forum|alt.badge.img+22
  • Author
  • Ultimate Hero (Partner)
  • 896 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+16
  • Superhero (Partner)
  • 129 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)
  • 700 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+16
  • Superhero (Partner)
  • 129 replies
  • February 27, 2020

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

 

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

 


dsj
Ultimate Hero (Partner)
Forum|alt.badge.img+22
  • Author
  • Ultimate Hero (Partner)
  • 896 replies
  • February 28, 2020

Thanks both for the answers.

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

 

Quick report SQL

1SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')   FROM dual
2union all
3SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')  FROM dual
4union all
5SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')  FROM dual
6union all
7SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')  FROM dual
8union all
9SELECT 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+16
  • Superhero (Partner)
  • 129 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

 
1SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')   FROM dual
2union all
3SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')  FROM dual
4union all
5SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')  FROM dual
6union all
7SELECT to_char(systimestamp, 'FF6'),regexp_substr(sys_guid(), '\d')  FROM dual
8union all
9SELECT 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


  • Sidekick (Customer)
  • 10 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)
  • 541 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