Create user defined TYPE in sql
Hi allI want to create type as below.
Student TYPE
IS
record
(
TABLE of object VARCHAR2 (100),
TABLE FOR mark1 VARCHAR2 (50).
TABLE OF mark2 VARCHAR2 (50).
Brand TABLE 3 VARCHAR2 (100)
);
I get the error. Like this
Error (28.3): PLS-00103: encountered the symbol "TABLE" during awaits one of the following values: pragma < an ID > < a between double quote delimited identifiers of >
My intention is that,
For each student, I need to HAV an arrary of topics, mark1, mark2, mark 3...
I actually cut my requirement of project very simple requirement.
Here for a reason, I need this structure to be like that. Kindly ignore the idea that the subtype of object, mark1,... etc.
Kindly help me in this regard.
Thank you
Sabarisri. N
something like
create type subject_tt
is table of varchar2(100)
/
create type mark_tt
is table of varchar2(50)
/
create type student
as object
(subjects subject_tt
,marks mark_tt
)
/
What I don't understand is, why don't you make a relational good datamodel? Makes life a lot easier...
Published by: Alex Nuijten on August 19, 2011 11:33
Tags: Database
Similar Questions
-
Hi all
I have a function that returns a type defined by the user in my sql environment. The type consists of 5 different columns. I pass a ref_id to my function, on the basis of which he does some calculations and returns me the type.
create or replace type my_type
(
number of col1,
col2 varchar2 (100),
COL3 varchar2 (10),
number of COL4,
number of col5
)
create or replace function fun (number in_id) return my_type
as
Start
-code1
-code2
Return (my_type)
end;
In my sql environment, I have a table which is the following structure
create table tab1
(
number of emeline
upgvc varchar2 (100),
number of Ref_ID, - this ref_id when it is passed to the function above will return a populated user-defined type values.
number of col1,
col2 varchar2 (100),
COL3 varchar2 (10),
number of COL4,
number of col5
)
I have a table tab2, using which i will be filling of the columns of the table tab1, tab2 table structure is as below
create table tab2
(
number of emeline
upgvc varchar2 (100),
number of Ref_ID)
now I have to fill each column in table tab1, tab2 table and my pleasure to feature.
something like
Insert into tab1
Select emeline,
upgvc,
Ref_ID,
Rest of the values must be completed by calling the function using the ref_id and fill in the values. What would be the best way to do it? I have millions of records with it. I tried to use this with the function of REGAL and tried fill lines, but its slow. All of the suggestions.
Note: apologies for not sticking scripts and the original code since it will take days
Thank you
Rahul
PetervdZwan wrote:
Hello
I agree that you shouldn't calc function for each attribute. But you don't need an extra table for this type.
See below:
Not sure what you mean:
SQL > set serveroutput on
SQL > select a.deptno,.
2 a.f.col1 col1,
a.f.col2 3 col2,
4 a.f.col3 col3,
5 a.f.col4 col4,
6 a.f.col5 col5
7 of)
8. Select wagneur, f1 (deptno) f
scott.dept 9 d
10 ) a
11.DEPTNO COL1 COL2 COL3 COL4 COL5
---------- ---------- ---------- ---------- ---------- ----------
10 10 A B 2 3
20 20 A B 2 3
30 30 A B 2 3
40 40 A B 2 3Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
SQL >As you can see, function runs again 5 times by each line. You need to materialize in line of sight. It can be done using NO_MERGE:
SQL > select a.deptno,.
2 a.f.col1 col1,
a.f.col2 3 col2,
4 a.f.col3 col3,
5 a.f.col4 col4,
6 a.f.col5 col5
7 of)
8 select / * + no_merge * /.
wagneur, f1 (deptno) 9 f
scott.dept 10 d
11 ) a
12.DEPTNO COL1 COL2 COL3 COL4 COL5
---------- ---------- ---------- ---------- ---------- ----------
10 10 A B 2 3
20 20 A B 2 3
30 30 A B 2 3
40 40 A B 2 3Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
Call to F1
SQL >However, I have and I know not why, the function is called not 4 but 6 times, using the type of collection (as in my first response) causes function calls only 4 - one per each line.
SY.
-
List of tables of objects or the user-defined type columns
Hello
SQL > select * from v version $;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE Production 11.2.0.2.0
AMT for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
I have n number of tables in my db, since I have several
tables containing "user defined type columns.
so, how can I get/list db objects that contains the user-defined type columns only.
Please suggest me on this
Kind regards
FaizDear Sir
I have n number of tables in my db,from that i have several tables which contains"user defined type columns" so how could i get/list the db objects which contains user defined type columns only. Kindly suggest me on this
Use this
select tab.table_name , tab.column_name , tab.data_type from user_tab_columns tab , user_types typ where tab.data_type = typ.type_name order by tab.table_name ;
Best regards
Mohamed Houri
-
retrieving data from columns of user defined type
Abstract types, I learned the other day. So I created an abstract type and a table.
Create the student_ty as an object type
(name varchar2 (20), number of roll);
create table result)
Student student_ty,
(total);
I also inserted data. But I'm having some trouble with the rretrieval of data. Suppose I want to choose only the roller and the name of the student as described in the type of studen. So I used the follwing query: -.
Select result student.name;
But it's not working. But when I use something like this: -.
Select r.total, r.student.name in result r;
This works perfectly. My question is that it is a rule that oracle needed to use an alias, whenever retrieve values for a user defined type data?. Help, please.
Thanks in advance.Yes, you can use an alias when the type of object in a table like this.
select r.student.name, r.student.roll, r.total from result r
-
Question of the user defined Type (UDT)
Hello
The attached file is NEITHER sample to call a VB6 vi.
The following is declared in the declaration section:
' Global declarations
Dim lvapp As LabVIEW.Application
Dim vi LabVIEW.VirtualInstrumentWhen I paste these statement in another project (that I'm working on), I get an error 'undefined user-defined type '.
Can someone point out to me were in the sample, these type definitions are declared?
Thank you
Rafi
PS the attachment is indeed xxx.rar and not xxx.zip. I changed the name because .rar has not been accepted. Please rename .rar
Thank you
I forgot to mark references to my project
Project--> references--> LabView. Type library of xxx
Thank you
-
Hello
I want to give as open & export to the level of permissions.
How to create user defined groups and users with custom permissions as only open and export in obiee 11 g?
For example, if the group permissions, inturn should reflect on the users.
Please help me.
Thanks in advance,
A.Kavya.
Your question is quite broad and fuzzy then I suggest the security catalog presentation to read documentation: http://docs.oracle.com/middleware/1221/biee/BIESC/mgrgrpsusers.htm#CIHIBJGD
And I think that you mix you two things which are managed in different places:
) an object as read access permissions, write, delete... which control you through the object "Permissions" dialog box
(b) functional privileges controlled through "Manage privileges" under "Administration".
-
Selection in the SQL user-defined Type
I can't try to fill a SQL can be set from a query type:
I can't use a collection of PL/SQL. It must be a SQL type.SQL> select * from v$version; BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod PL/SQL Release 10.2.0.3.0 - Production CORE 10.2.0.3.0 Production TNS for 32-bit Windows: Version 10.2.0.3.0 - Production NLSRTL Version 10.2.0.3.0 - Production SQL> create type typ_colVarchar30 is table of varchar2(30) 2 / Type created. SQL> declare 2 v_colVarchar30 typ_colVarchar30; 3 begin 4 select table_name into v_colVarchar30 from user_tables; 5 end; 6 / select table_name into v_colVarchar30 from user_tables; * ERROR at line 4: ORA-06550: line 4, column 11: PL/SQL: ORA-00932: inconsistent datatypes: expected UDT got CHAR ORA-06550: line 4, column 4: PL/SQL: SQL Statement ignored SQL> drop type typ_colVarchar30; Type dropped.
Thank you.
BrianUse BULK COLLECT
declare v_colVarchar30 typ_colVarchar30; begin select table_name bulk collect into v_colVarchar30 from user_tables; end;
-
Add the column to an existing table-based user-defined type
Hello guys,.
I am compiling my function that returns a type defined by the user based on an existing table. Throughout the process of initialization so my query returns an additional column - SCORE (1). Here is my package:
create or replace
PACKAGE STAFF_AGENCY_PKG AS
TYPE TYPE_SEEKER_TABLE IS TABLE OF THE DRAW. SEEKER % ROWTYPE;
FUNCTION GET_SEEKERS (IN_KEYWORD IN VARCHAR2)
TYPE_SEEKER_TABLE RETURN PIPELINE;
END STAFF_AGENCY_PKG;
-------
create or replace
STAFF_AGENCY_PKG PACKAGE BODY
AS
FUNCTION GET_SEEKERS (IN_KEYWORD IN VARCHAR2)
TYPE_SEEKER_TABLE RETURN PIPELINE
IS
R_TBL TYPE_SEEKER_TABLE; -to return
BEGIN
FOR R IN)
SELECT Seeker.SEEKER_ID,
Seeker.FIRSTNAME,
Seeker.LASTNAME,
Seeker.NATIONALITY,
Seeker.ISELIGIBLE,
Seeker.BIRTHDATE,
Seeker.ISRECIEVEEMAILS,
Seeker.HIGHESTDEGREE,
Seeker.ETHNICITY,
Seeker.GENDER,
Seeker.ISDISABILITY,
Seeker.DISABILITY,
Seeker.CV,
Seeker.PASSWORD,
Seeker.PREFFERED_CITY,
SEEKER. E-mail
SEEKER. JOB_PREFERENCES_ID,
SCORE (1)
THE APPLICANT Seeker
WHERE CONTAINS (CV, ' < query >)
< textquery lang 'grammar' = 'context' = > ' |
GET_RELATED_CATEGORIES (IN_KEYWORD) |
' < / textquery >
< score datatype = "INTEGER" / >
(< / query > ', 1) > 0
)
LOOP
PIPE ROW (R); -Error (38,10): PLS-00382: expression is of the wrong type
END LOOP;
RETURN;
END GET_SEEKERS;
END STAFF_AGENCY_PKG;
How do I change my user type to be sufficient?
Oracle version 11.2.0.1.0
Thanks in advance!>
How do I change my user type to be sufficient?
>
You will need to create two new TYPEs. The one who has all the columns of the draw. The REQUESTOR table and the new column SCORE, then a TYPE which is an array of the first type.See example 12-22 using a Pipelined Table function for a Transformation in the PL/SQl language reference
http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/tuning.htm#i53120
Here's the first part
-- Define the ref cursor types and function CREATE OR REPLACE PACKAGE refcur_pkg IS TYPE refcur_t IS REF CURSOR RETURN employees%ROWTYPE; TYPE outrec_typ IS RECORD ( var_num NUMBER(6), var_char1 VARCHAR2(30), var_char2 VARCHAR2(30)); TYPE outrecset IS TABLE OF outrec_typ; FUNCTION f_trans(p refcur_t) RETURN outrecset PIPELINED; END refcur_pkg; / CREATE OR REPLACE PACKAGE BODY refcur_pkg IS FUNCTION f_trans(p refcur_t) RETURN outrecset PIPELINED IS out_rec outrec_typ; in_rec p%ROWTYPE; BEGIN
Change
TYPE outrec_typ IS RECORD ( var_num NUMBER(6), var_char1 VARCHAR2(30), var_char2 VARCHAR2(30)); TYPE outrecset IS TABLE OF outrec_typ;
to include all the columns you need. Unfortunately, you have to manually list all the columns in the draw. The REQUESTOR table. If you think you need this same structure in other places you must create them as SQL types instead of PL/SQL types.
This example should be enough to show you how to modify your code to do something similar.
-
Querying the user-defined types
I have a chart in which one of the columns is a user-defined data type:
The type 'MYTYPE' is a simple object that contains a field: a CLOB called MESSAGE:SQL> describe my_table ... USER_DATA MYTYPE
When I do a "select *...» "in this table, the USER_DATA column appears as"MYTYPE (oracle.sql.CLOB@898c2d).SQL> describe mytype Name Null? Type ------ ----- ---- MESSAGE CLOB
I know that for CLOB and BLOB fields, Developer SQL let me double click on the value and display the content. But for type like this defined by the user that contains a field, I can't navigate the data members of type. I find myself wanting to do something like a 'select user_data.message from my_table", but this is not a valid syntax. Is there a way to query a given specific member of this type defined by the user with the rest of the columns in the table, I can display the CLOB member instead of a representation of the object? If not, is it possible to configure SQL Developer to allow me to browse the data members of types defined by the user? TOAD has a feature like that but I would only use SQL Developer and it is a table that I work with on a regular basis.csimons,
Try this:
select t1.user_data.message from eimgr.aq_rtv_docs_out_table t1 where rownum = 1;
See you soon
Edited by: Frenchwood on September 22, 2009 22:38
-
With the help of a user defined type as a return type of function with a type of object
Hi, I created my own data type of table I want to use as data type back to a member function of an object type that I created.
I work in an environment of 10g.
The code I used looks like this:
create or replace
Dim p As Package as
type p_rec is (number of v1);
type p_tab is table of the p_rec;
end p;
/
CREATE or REPLACE TYPE p_ot () AS OBJECT
/ * some statements * /.
NO DEFINITIVE MEMBER FUNCTION p.p_tab RETURN foo
);
/
When I try to compile p_ot I get an error: Error (5.40): PLS-00201: identifier 'P.P_TAB' must be declared.
I don't know the syntax is correct so I must be missing something, amy hepl would be great.
See you soonYou can define types of objects
create type p_rec as object ( v1 number ); create type p_tab as table of p_rec;
They can be used inside the package (p) in your example) as well as defined in the package.
In this case, there will be no problems with create typeCREATE TYPE p_ot AS OBJECT ( /* some declarations*/ NOT FINAL MEMBER FUNCTION foo RETURN p_tab );
-
Inserting data from the user-defined Type
Hi all
I have the following type
I have the procedure (within a package) that pulls in the python papers.create or replace type answer_obj is object (all_employee_seq integer,questionseq varchar2(10),text_answer varchar2(4000),optionseq varchar2(10)); create or replace type answer_tbl is table of answer_obj;
My question is, is it better to insert the data directly from the (record) (records) argument using for LOOP INSERT or the conversion of the argument in an associative array and a FORALL?TYPE answer_tbl_type IS TABLE OF question_answer%ROWTYPE INDEX BY PLS_INTEGER; PROCEDURE submit_survey (p_answers IN OUT answer_tbl) IS l_answers_tbl answer_tbl_type; BEGIN FOR i IN p_answers.FIRST .. p_answers.LAST LOOP l_answers_tbl (i).all_employee_seq := p_answers (i).all_employee_seq; l_answers_tbl (i).questionseq := p_answers (i).questionseq; l_answers_tbl (i).text_answer := p_answers (i).text_answer; l_answers_tbl (i).optionseq := p_answers (i).optionseq; END LOOP; FORALL idx IN l_answers_tbl.FIRST .. l_answers_tbl.LAST INSERT INTO QUESTION_ANSWER VALUES l_answers_tbl (idx); END;
As you can see, it's a FOR LOOP to set the values in the array and then by the FORALL.
I think the above is even faster because of the first LOOP IS done in memory and real integration is carried out with FORALL.
I want to get as many opinions.
See you soon,.
JoelHello
Because you created the SQL Types, what just to do this within your procedure?
INSERT INTO QUESTION_ANSWER (all_employee_seq, questionseq, text_answer, optionseq) SELECT all_employee_seq, questionseq, text_answer, optionseq FROM TABLE(p_answers);
-
call a DLL that has the user-defined types
I am trying to call a function in a DLL that is
int32 system_config(&recCfg, &pulseCfg, errMsg)
recCfg is a structure consisting of 3 double rooms and 2 integers
and pulseCfg is a structure consisting of just Boolean
I don't know how to set the input parameters for this call the library feature.
LabVIEW sees as
void system_config(void)
I see the only choice of Numeric, Array, String, waveform, digital waveforms, digital data, ActiveX, Adapt to Type and pointer to Instance data for arg1. ActiveX seems to be the only one to use?
NYC says:
I am trying to call a function in a DLL that is
int32 system_config(&recCfg, &pulseCfg, errMsg)
recCfg is a structure consisting of 3 double rooms and 2 integers
and pulseCfg is a structure consisting of just Boolean
Actually contrary to what Simon says you can do in this case. But your line you are showing is unfortunately very unclear, because he does not understand the real typedef for your clusters. So I have to go by what you write in prose that is... Well... not very detailed.
The first is simply a cluster in LabVIEW with 3 floats to double precision, followed of 2 integers. You find yourself what bitsize integer, you need, as you do not show the typedef in the cluster. In order to connect to a cluster in a CLN you must configure this setting as to adapt to the Type. But be careful who does not work for clusters containing strings or arrays at all. Tables and chains of LabVIEW are something completely different than what awaits a C DLL. You can configure the parameters of function to be C compatible pointers to arrays and strings and LabVIEW will make sure to do the conversion on every call, but you cannot configure the CLN to convert strings and tables within a cluster.
The second group is really equivalent to a simple Boolean value passed by reference. As you do not show the actual type of the Boolean value, it is difficult to recommend this type of data to use in LabVIEW. Windows BOOL is a 32-bit integer and C++ bool is usually a 8-bit value which would coincide with the Boolean LabVIEW 8-bit use. You cannot configure a Boolean setting directly in the NLCS, so you can either use an integer of size accordingly or create this cluster with a single LabVIEW boolean anyway (if your bool is a bool C++ and not something else) and do the same as for the previous cluster/structure parameter.
-
PROGRAMMER (USER) DEFINED RECORDS
Hi all;
I do self - study of PL/SQL concepts for user-defined folders.
I get the error.
SQL > desc emp;
Name Null? Type
----------------------------------------- -------- ----------------------------
EID NUMBER
ENAME VARCHAR2 (15)
VARCHAR2 (10) EQUAL
ESALARY VARCHAR2 (15)
ECITY VARCHAR2 (15)
SQL > select count (*) from emp;
COUNT (*)
2
PROGRAMMER (USER) DEFINED RECORDS
SQL > DECLARE
2 C_cr CURSOR IS
3. Select ename, equality, esalary, eid, ecity emp;
4 EMP_DETAILS RECORD TYPE IS
5 (e_id emp.eid%TYPE,
6 e_name emp.ename%TYPE,
7 e_qual emp.equal%TYPE,
8 e_salary emp.esalary%TYPE,
e_city 9 emp.ecity%TYPE);
10 emp_detail e1;
BEGIN 11
12 C_cr OPEN;
LOOP 13
14 C_cr FETCH in emp_detail;
15 WHEN OUT C_cr % NOTFOUND;
16 DBMS_OUTPUT. Put_line (emp_detail.e_id | emp_detail.e_name | emp_detail.e_q ual | emp_detail.e_salary | emp_detail.ecity);
17 END OF LOOP;
18 DBMS_OUTPUT. Put_line (C_cr % ROWCAMOUNT);
19 CLOSE C_cr;
20 END;
21.
emp_detail e1;
*
ERROR on line 10:
ORA-06550: line 10, column 12:
PLS-00201: identifier "E1" must be declared.
ORA-06550: line 10, column 12:
PL/SQL: Ignored Element
ORA-06550: line 14, column 17:
PLS-00320: the declaration of the type of the expression is incomplete or
Malformed
ORA-06550: line 14, column 1:
PL/SQL: SQL statement ignored
ORA-06550: line 16, column 22:
PLS-00320: the declaration of the type of the expression is incomplete or
Malformed
ORA-06550: line 16, column 1:
PL/SQL: Statement ignored
SQL > select * from v version $;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
AMT for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Thank you all;
MY QUESTION IS: type_name, record_type must be the same?
It is not necessary to be the same. Once you create a record type, then it might be assigned to different variables, such as:
SQL > DECLARE
2 C_cr CURSOR IS
3. Select ename, equality, esalary, eid, ecity emp;
4 TYPE EMP_DETAILS IS RECORD
5 (e_id emp.eid%TYPE,
6 e_name emp.ename%TYPE,
7 e_qual emp.equal%TYPE,
8 e_salary emp.esalary%TYPE,
e_city 9 emp.ecity%TYPE);
10 emp_detail EMP_DETAILS;
11 emp_detail_2 EMP_DETAILS;
12 emp_detail_3 EMP_DETAILS;
13 l_id NUMBER;
Now, he becomes similar to a variable_type of variable_name in the declaration section. Emp_detail or emp_detail_2 is a variable of type EMP_DETAILS, like the variable l_id that can hold values of type numbers.
-
Hello Experts!
I have a simple question.
Is there a way, of creating user defined KING?
For example, I want to create a return on investment, such as:
Hello
Yes and no. You can combine this KING of three kings of base: two lines and a circle (or ring). Movement will be a little tricky (because all three kings should be moved together with the movement of the mouse) - you need to do programmatically. ("Point of departure") example as an attachment. Think otherwise maybe twice - it will be easier to use single point KING with overlay instead of several Kings.
Andrey.
-
vSphere 5.5 user defined storage capacity
Is it possible to create user-defined in vSphere 5.5 storage capacity?
I am trying to create a storage policy, and when I get to the section "value 1", the only option for capacity rule is 'None'. I remember in 5.0 in the VI Client, there is an option to 'Manage storage capacities' and create a user-defined function. Is it an option to 5.5 in the web client?
Thank you
Scott
This should help you with that
http://everythingshouldbevirtual.com/vSphere-5-5-storage-profiles-now-storage-policies
Maybe you are looking for
-
Help with WIFI hp Pavilion 15-p048no
Hello, I need help with my wifi. I have hp pavilion 15-p048no that I just installed Windows 7 64 bit, but now the problem is I cannot find drivers for lan/wlan for windows 7 because this laptop came with windows 8.1 and hp do not support this model w
-
What is the best way to create a backup external to the files from my laptop?
What is the best way to create a backup external for my laptop files which may be about 40 GB +.
-
As the title, yesterday, I presented a new file of cod in the world of the app as a free update for my software. Today, when I connect to the world of the seller on the releases tab app the Release status: project - you can modify this version. What
-
App won't start with the Simulator
Hello I met a lot of mistakes trying to get that deployed on the Simulator, most of them addressed by other posters. I use the 0.9.3 beta version of the Simulator. However, now I have this problem that I can not find the answer. Flash Builder will n
-
Helloin the grid with ASM architecture 11.2 or 12 c, it is always recommended to use fdisk to create a partition on a shared LUN or I can used is that raw?I do not use asmlib