Showing posts with label enum. Show all posts
Showing posts with label enum. Show all posts

Thursday, March 29, 2012

Enumeration variables??

Is it possible to create variables of type enum in PL/SQL?
In VB.NET it would be something like e.g.: enum seasons {Spring, Summer, Autumn, Winter}
Thx.Originally posted by OracleDev
Is it possible to create variables of type enum in PL/SQL?
In VB.NET it would be something like e.g.: enum seasons {Spring, Summer, Autumn, Winter}

Thx.
No, PL/SQL does not have such a type.|||I feared this, because I couldn't find info about it.

Thx anyway.

Tuesday, March 27, 2012

enum for a column

Is there a way to do something like an enum for a column?
I have a column that should contain one of a fixed set of values. The set of
values won't change and there is only one column in one table that uses this
set of values.
So I was thinking that there wasn't much point in creating a new table just
for this set of values. I could set the data type of the column to a fixed
size char and create a check constraint that tests for each possible value.
There are 20 values in the set so the constraint will be tedious to write.
But there is a notion of order to the set. i.e. value 1 < value 2 < value
N.
So what I really want is an enum like in C++ or C#.
What's the closest approximate in T-SQL?the closest thing to an enum in TSQL is a check constraint.
if you use IN the definition isn't that much more tedious than an enum
definition in C#--you still have to list all of the possible values. For
example,
create table t1
(
f1 int identity(1,1) not null
constraint pk_t1 primary key clustered,
f2 char(5) not null
constraint ck_f2 check (f2 in ('NORTH', 'SOUTH', 'EAST', 'WEST'))
)
"Jonathan Dodds" wrote:

> Is there a way to do something like an enum for a column?
> I have a column that should contain one of a fixed set of values. The set
of
> values won't change and there is only one column in one table that uses th
is
> set of values.
> So I was thinking that there wasn't much point in creating a new table jus
t
> for this set of values. I could set the data type of the column to a fixed
> size char and create a check constraint that tests for each possible value
.
> There are 20 values in the set so the constraint will be tedious to write.
> But there is a notion of order to the set. i.e. value 1 < value 2 < value
> N.
> So what I really want is an enum like in C++ or C#.
> What's the closest approximate in T-SQL?
>
>

Enum datatype in SQL Server?

hi guys,

is it possible to do a enum datatype in SQL Server? if so can anyone point me to an example please?

thanks,

benny

No - there is no Enum Type is sql server.

Generally an Enum may be expressed in code as an Enum of Integers. Then in Sql Server, you would store the specific Integer that was selected. If you wish to insure that a value cannot be stored in your database unless it has been defined as allowable in sql server, then you could add a Constraint to your sql table for that particular Integer column to require specific values.

|||

thanks for your help :)

|||

I've found that it's effective enough to store the values of .NET Enums as int datatypes in SQL Server. Given that you have properties on your classes that are of type MyEnum, those int values will natively convert to their corresponding enum values (which are Integer values anyway).

Alternatively, if you store those values as varchar you can do an [Enum].Parse(GetType(MyEnum), VarcharValue) to convert it from its corresponding string.

Hope that helps.