Home » SQL & PL/SQL » SQL & PL/SQL » need help for oracle sql (ORACLE)
icon2.gif  need help for oracle sql [message #635707] Tue, 07 April 2015 04:00 Go to next message
hivwood
Messages: 7
Registered: April 2015
Location: CMB
Junior Member
I am not good at for oracle sql. I need to fix my code. That is the problem. i given my answer. I want to check my code is correct or not. please help me.

Consider a type named student_type that has attributes, (sid: char(8), sname: varchar(15), phone: char(10)).
Let ug_type be a subtype of student_type with attributes, (gpa: real, deptid: char(6), course: varchar(10)).

(a) Write Oracle object SQL statements to create these two types.

(b) Assuming that a table named students of student_type has been created, insert ug_type tuple into it with attribute values of sid: 12354326, sname: Janet Paeres, phone: null, gpa: 3.2, deptid: CS01, and course:InfoTech.

(c) Assuming there may be data of ug_type and others in the table students of student_type, write an Oracleobject SQL statement to retrieve the sid and sname of only students with deptid of CS01.


My ANSWERS:
A)
CREATE TYPE student_type AS OBJECT (
sid char(8),
sname varchar(15),
phone char(10)) NOT FINAL;/

CREATE TABLE student_type_table of student_type(
sid PRIMARY KEY);

CREATE TYPE ug_type UNDER student_type
(gpa real,
deptid char(6),
course varchar(10));/

CREATE TABLE ug_type_table of ug_type;

B)
INSERT INTO student_type_table VALUES(
Student_type ('12354326', 'Janet Paeres', 'NULL'));

Insert into ug_type_table values(
Ug_type (3.2, 'CS01', 'InfoTech' ));


C)
How to do "C"?
Re: need help for oracle sql [message #635708 is a reply to message #635707] Tue, 07 April 2015 04:34 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

FIRST, you have to know that you should NEVER use object type in a stored table. Oracle is a relational database with object extension not an object database and so objects are "hiddenly" and with very poor performances converted to relational objects.

A) testing your code:
SQL> CREATE TYPE student_type AS OBJECT (
  2  sid char(8),
  3  sname varchar(15),
  4  phone char(10)) NOT FINAL;
  5  /

Type created.

SQL> CREATE TYPE ug_type UNDER student_type
  2  (gpa real,
  3  deptid char(6),
  4  course varchar(10));
  5  /

Type created.

SQL> desc student_type
 student_type is NOT FINAL
 Name                             Null?    Type
 -------------------------------- -------- ----------------------
 SID                                       CHAR(8 CHAR)
 SNAME                                     VARCHAR2(15 CHAR)
 PHONE                                     CHAR(10 CHAR)

SQL> desc ug_type
 ug_type extends MICHEL.STUDENT_TYPE
 Name                             Null?    Type
 -------------------------------- -------- ----------------------
 SID                                       CHAR(8 CHAR)
 SNAME                                     VARCHAR2(15 CHAR)
 PHONE                                     CHAR(10 CHAR)
 GPA                                       FLOAT(63)
 DEPTID                                    CHAR(6 CHAR)
 COURSE                                    VARCHAR2(10 CHAR)

Is this what you want?

B)
SQL> CREATE TABLE student_type_table of student_type(
  2  sid PRIMARY KEY);

Table created.

SQL> desc student_type_table
 Name                             Null?    Type
 -------------------------------- -------- ----------------------
 SID                              NOT NULL CHAR(8 CHAR)
 SNAME                                     VARCHAR2(15 CHAR)
 PHONE                                     CHAR(10 CHAR)

Your answer is not correct because the input (from the text) is an ug_type not a student_type as your "INSERT INTO student_type_table VALUES(Student_type ('12354326', 'Janet Paeres', 'NULL'));" use it.
So the input is (also note there is no quote around NULL):
Ug_type ('12354326', 'Janet Paeres', NULL, 3.2, 'CS01', 'InfoTech')
So:
SQL> insert into student_type_table
  2  values (Ug_type ('12354326', 'Janet Paeres', NULL, 3.2, 'CS01', 'InfoTech'));

1 row created.

SQL> select * from student_type_table;
SID      SNAME           PHONE
-------- --------------- ----------
12354326 Janet Paeres

1 row selected.

The other attributes of the input data are lost (as far as I know).

C) See my last sentence.

[Updated on: Tue, 07 April 2015 04:52]

Report message to a moderator

Re: need help for oracle sql [message #635709 is a reply to message #635708] Tue, 07 April 2015 04:38 Go to previous messageGo to next message
hivwood
Messages: 7
Registered: April 2015
Location: CMB
Junior Member
Thank you your quick reply. That is really help full. I will check again and contact you.
Thank you again.
Re: need help for oracle sql [message #635710 is a reply to message #635708] Tue, 07 April 2015 04:56 Go to previous messageGo to next message
hivwood
Messages: 7
Registered: April 2015
Location: CMB
Junior Member
About "C

(c) Assuming there may be data of ug_type and others in the table students of student_type, write an Oracleobject SQL statement to retrieve the sid and sname of only students with deptid of CS01.

Yes data are missed. But i need to get some idea about that. I can drive with sql. But oracle sql is difficult to me. Can help me to write this code. In this situation we need to remember we have lot of data. But only need to catch "only students with deptid of CS01"
Thank you.

[Updated on: Tue, 07 April 2015 05:00]

Report message to a moderator

Re: need help for oracle sql [message #635711 is a reply to message #635710] Tue, 07 April 2015 05:02 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You cannot get student with this deptid because this information is not in the table, this information has been lost during the insertion.

Re: need help for oracle sql [message #635714 is a reply to message #635711] Tue, 07 April 2015 05:41 Go to previous messageGo to next message
hivwood
Messages: 7
Registered: April 2015
Location: CMB
Junior Member
yes i know sir. But i want that query...I do not want exact result. only query.....
thank you.
Re: need help for oracle sql [message #635717 is a reply to message #635714] Tue, 07 April 2015 06:04 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You can't have a query that does not exist.
Do you understand this?
Let me show you the example, you have this in the table:
SQL> select * from student_type_table;
SID      SNAME           PHONE
-------- --------------- ----------
12354326 Janet Paeres

1 row selected.

Is Janet in deptid CS01?
If you can't answer this question seeing the content of the table then Oracle can't either.
Re: need help for oracle sql [message #635750 is a reply to message #635717] Wed, 08 April 2015 02:33 Go to previous messageGo to next message
hivwood
Messages: 7
Registered: April 2015
Location: CMB
Junior Member
hello sir,
I successfully created object(student_type).
And object table(student_type_table).
As well as i created subtype of "student_type" (ug_type).
But i have no idea about create table for that subtype. I mean "ug_type_table". Is this correct or not?

And how to insert data to this tables? I mean that.
(b) Assuming that a table named students of student_type has been created, insert ug_type tuple into it with attribute values of sid: 12354326, sname: Janet Paeres, phone: null, gpa: 3.2, deptid: CS01, and course:InfoTech.

I waste 2 days with that. But i can not able to correct way.....i got more errors. please help me to insert that data and view that data with one query.

Thank you.
Re: need help for oracle sql [message #635768 is a reply to message #635750] Wed, 08 April 2015 04:42 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

I give you all the examples to do these things.

Quote:
.i got more errors.


We can't help on something we can't see.
Use SQL*Plus and copy and paste your session, the WHOLE session.

Re: need help for oracle sql [message #635770 is a reply to message #635768] Wed, 08 April 2015 04:47 Go to previous messageGo to next message
hivwood
Messages: 7
Registered: April 2015
Location: CMB
Junior Member
Ok tell me,

may i need to create table for subtype?

I successfully created object(student_type).
And object table(student_type_table).
As well as i created subtype of "student_type" (ug_type).
But i have no idea about create table for that subtype. I mean "ug_type_table". Is this way correct or not?
Re: need help for oracle sql [message #635771 is a reply to message #635770] Wed, 08 April 2015 04:51 Go to previous messageGo to next message
hivwood
Messages: 7
Registered: April 2015
Location: CMB
Junior Member
That is the link to download my questions http://tempsend.com/28E86413D7 please kindly help me.
Thank you.
Re: need help for oracle sql [message #635772 is a reply to message #635770] Wed, 08 April 2015 04:52 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
may i need to create table for subtype?


How can I know? Is this asked in your homework?

Quote:
Is this way correct or not?


To achieve what?

Re: need help for oracle sql [message #635773 is a reply to message #635771] Wed, 08 April 2015 04:54 Go to previous message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

hivwood wrote on Wed, 08 April 2015 11:51
That is the link to download my questions http://tempsend.com/28E86413D7 please kindly help me.
Thank you.


I already did.
I won't do your homework for you.
If something is not clear in the questions, ask your teacher not me.

Previous Topic: %rowtype error 06512
Next Topic: Oracle Number length to SQL Numeric length
Goto Forum:
  


Current Time: Fri Apr 19 16:33:22 CDT 2024