How to read type of element for Oracle collection type? - sql

I have Oracle collection type defined as:
type tab_foo as table of obj_foo
Where obj_foo is defined as:
type obj_foo as object
By calling:
select * from sys.all_types where typecode = 'COLLECTION';
I can get metadata for all the collection types, however there is no information what is the type of element contained in the collection.
How to retrieve collection element type metadata from oracle?

Look at ALL_COLL_TYPES, which lists all collection types. The column you are interested in is ELEM_TYPE_NAME.

Related

Structure where the data type of a member differs

Maybe superfluous, but some intro...
I am rewriting an add-in for my CAD-application (using VB.NET).
This add-in reads, via an API, a bunch of metadata from a file, presents it in a Form. This data can then be (partially) changed and written back to the file.
This metadata is accessible in a consistent way, however the data type is not the same everywhere (String, Currency, Date, Boolean, Long and IPictureDisp).
Currently I have a much too complex class with several arrays. I thought it might be smarter to create a structure. The problem is the varying data type.
Is it possible to define a structure with a member with varying datat type, or am I forced to define a different structure for each data type?
You have a few options...
1: Use Object
Nice and simple, every data type inherits from Object - so if your struct contains a property of type Object, you can put pretty much any data type in there
From the docs:
The Object data type can point to data of any data type, including any object instance your application recognizes. Use Object when you do not know at compile time what data type the variable might point to.
However, this does mean that you will get next to no help from the compiler when you are trying to write code using this property. You will also probably have to cast any time you need to do anything type-specific
2: Generic Types
This will not fit situations where you are not sure of the type. You can create a generic struct using the Of syntax.
You'd create it as so:
Structure MyStructure(Of T)
'our changing type
Dim MyCustomData As T
'...alongside regular types
Dim Name As String
Dim OtherThing As Integer
End Structure
and then when you need to create the structure, you'd simply pass the type in and assign the value
Dim struct As New MyStructure(Of Integer)
struct.MyCustomData = 123
Dim struct2 As New MyStructure(Of String)
struct2.MyCustomData = "a"

Does C# have an enum that would match SQL object type?

In the sys.objects table documentation, there's a list of types with their corresponding codes:
SO = Sequence object
U = Table (user-defined)
V = View
...
Is there a native enum or const in C# that would match these Sql object type?
The closest enum I've found is the DAC ObjectType Enum but it only matches some of the Sql object type.
Since SQL server is using 2 characters codes for these type, I understand that I would probably have write some mapping logic... but I'd prefer using a native enum instead of writing my own Enum.
Is there a native enum or const in C# that would match these Sql object type?
No. There is not.

HSQLDB 2.3.3: How to create type java list?

Can we create custom type which is of type java.util.List?
CREATE TYPE list
EXTERNAL NAME 'java.util.List'
LANGUAGE JAVA;
Types can be created based on an existing supported type, so this cannot be used for your purpose.
The SQL equivalent of a list is an ARRAY. You should use an array such as INTEGER ARRAY, or VARCHAR(100) ARRAY. The Java form of the array to use in the Java static method is Object[].

Correct way of using TYPE REF TO data?

I've declared a type with the type of ref to data. so it looks like this
my_type type ref to data.
Then I declare an internal table, which I want to assign to my_type.
Data:
ref_data type my_type.
itable type it_table.
ref_data = itable.
Why can't I assign itable to ref_data, isn't a ref to data is a generic data type and can be assigned to anything?
This is very similar to other programming languages, and it's not a problem of typing the variables or references. You're trying to assign a value to a pointer variable - that won't work anywhere. You need to use GET REFERENCE OF itable INTO ref_data.
That's not quite how a data reference works. A data reference has to be typed, but you type it at run time.
data: ref_data type ref to data.
data: itable type it_table.
"you access the data in a data reference via a field symbol
field-symbols: <dref> type any.
create data ref_data type it_table.
assign ref_data->* to <dref>.
<dref> = itable.
I now have a copy of itable in my dynamically typed variable ref_data, accessed by the field symbol .

Concrete form bean for html select

I have used <html:select> in one of my jsp pages with multiple selection. What varibles, for storing the selection, should i have in the form bean associated with this list?
Straight from the documentation:
This tag operates in two modes, depending upon the state of the
multiple attribute, which affects the data type of the associated
property you should use:
multiple="true" IS NOT selected - The corresponding property should be a scalar value of any supported data type.
multiple="true" IS selected - The corresponding property should be an array of any supported data type.
(emphasis mine)