create array object in table? [message #9376] |
Thu, 06 November 2003 10:58 |
Priyanka Shah
Messages: 19 Registered: January 2003
|
Junior Member |
|
|
I want to store 'overtime' as a single field in a row among other fields
This field 'overtime' should have 'type' and 'hours'
So how should I create it , retrieve it , select etc ?
|
|
|
|
Re: create array object in table? [message #9378 is a reply to message #9376] |
Thu, 06 November 2003 11:15 |
Art Metzer
Messages: 2480 Registered: December 2002
|
Senior Member |
|
|
SQL> CREATE OR REPLACE TYPE overtime_type
2 AS OBJECT (
3 ot_type VARCHAR2(10)
4 , ot_hours NUMBER
5 )
6 /
Type created.
SQL> CREATE TABLE timesheet (
2 empno NUMBER
3 , d DATE
4 , overtime overtime_type
5 )
6 /
Table created.
SQL> DECLARE
2 l_overtime overtime_type;
3 BEGIN
4 l_overtime := overtime_type('A',2.5);
5 INSERT INTO timesheet (
6 empno
7 , d
8 , overtime
9 ) VALUES (
10 1234
11 , TO_DATE('20031103','YYYYMMDD')
12 , l_overtime
13 );
14 l_overtime := overtime_type('B',1);
15 INSERT INTO timesheet (
16 empno
17 , d
18 , overtime
19 ) VALUES (
20 5678
21 , TO_DATE('20031103','YYYYMMDD')
22 , l_overtime
23 );
24 COMMIT;
25 END;
26 /
PL/SQL procedure successfully completed.
SQL> SELECT t.empno
2 , TO_CHAR(t.d
3 , 'fmMM/DD/YYYY') work_date
4 , t.overtime.ot_type
5 , t.overtime.ot_hours
6 FROM timesheet t
7 WHERE t.overtime.ot_hours > 2
8 /
EMPNO WORK_DATE OVERTIME.O OVERTIME.OT_HOURS
---------- ---------- ---------- -----------------
1234 11/3/2003 A 2.5
SQL> HTH,
A.
|
|
|
Re: create array object in table? [message #9380 is a reply to message #9378] |
Thu, 06 November 2003 19:17 |
Priyanka Shah
Messages: 19 Registered: January 2003
|
Junior Member |
|
|
Thanks!
I was wondering if since i am using jsp with jdbc, can I use a vector or array in java and add that to the database in that field or do I have to create a type for this?
If I am not using PLSQL how do I insert records?
|
|
|
Re: create array object in table? [message #9384 is a reply to message #9380] |
Fri, 07 November 2003 07:02 |
Art Metzer
Messages: 2480 Registered: December 2002
|
Senior Member |
|
|
You have to create a type at the SQL level to make this approach work.
If I were you, I would create a stored procedure in PL/SQL using the INSERT method I showed you, and just invoke that stored procedure from JDBC using the CallableStatement object.
HTH,
A.
|
|
|