Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Create a view with function

user13117585Nov 11 2020

Hello,

I'm trying to create a view. The following SELECT works and it does what I need. However, when I try to create a view that returns the value, it fails. Any suggestion?
This works:
WITH FUNCTION getNextValue(v IN PLS_INTEGER) RETURN VARCHAR
AS
digits PLS_INTEGER;
remaining PLS_INTEGER;
secondLetterIndex PLS_INTEGER;
firstLetterIndex PLS_INTEGER;
BEGIN
digits := MOD(v, 10000);
remaining := (v - digits) / 10000;
secondLetterIndex := MOD(remaining, 26);
firstLetterIndex := FLOOR(remaining / 26);
RETURN CHR(ASCII('A') + firstLetterIndex) || CHR(ASCII('A') + secondLetterIndex) || LPAD(digits, 4, '0');
END;
SELECT getNextValue(seq.nextval) AS nextvalue
FROM dual
;
When I do CREATE VIEW view (v) with previous select it fails (sequence not allowed there).
Any idea how I can do that? Function is not mandatory as long as I get the same result... And, we never get to ZZ...
Regards

Comments
Post Details
Added on Nov 11 2020
7 comments
5,316 views