Forum Stats

  • 3,874,474 Users
  • 2,266,741 Discussions
  • 7,911,854 Comments

Discussions

Request for enum support in pl/sql

User_LFNWX
User_LFNWX Member Posts: 3 Green Ribbon

Request for ability to define enum like structures in pl/sql. Currently there workarounds to do this like using oracle types and constructor functions. However would like to see a more user-friendly implementation of this.

Perhaps something that would allow for referencing the enum values w/o string/literal matching such as can be done with pl/sql constants and other languages. E.g.

for i in (select * from levels_table) loop
   if i.level_col = level.MEDIUM then ...

Java

public class Main {
  enum Level {
    LOW,
    MEDIUM,
    HIGH
  }

  public static void main(String[] args) {
    Level myVar = Level.MEDIUM; 
    System.out.println(myVar);
  }
}

C#

class Program
{
  enum Level
  {
    Low,
    Medium,
    High
  }
  static void Main(string[] args)
  {
    Level myVar = Level.Medium;
    Console.WriteLine(myVar);
  }
}


Related post:

https://community.oracle.com/tech/developers/discussion/4504763/request-for-enum-support-in-pl-sql

User_LFNWX
1 votes

Active · Last Updated

Comments

  • Mike Kutz
    Mike Kutz Member Posts: 6,253 Gold Crown
    edited Oct 30, 2022 2:30PM

    I can see the Implementation being based on JSON data type.

    with data as (
        select json('{"DifficultyLevel":"MEDIUM"}') lvl from dual
    )
    select t.lvl.DifficultyLevel lvl from data t;
    

    but, this only works in SQL, not PL/SQL

    ( Level is not liked since it is a Keyword)