SELECT statement to return a type in Oracle objects
Hi all, I have created a small system for Uni using oracle objects and types. I have a table person with type of seller under the person table and the type of claimant to the title of the person table. I need the select statement to return data of the person, table, but only the type of applicant data. for example, SELECT * FROM person_tab, WHERE the type is applicant_t. I know it's probably simple, but just can't get the syntax right. The code all series just may not get the right to choose. Thanks for your time.
create type appointment_t; create type property_t; create type telephone_t as object ( weekdayDaytime varchar2(15), weekdayEveningAndWeekend varchar2(15)); create type person_t as object ( person char(6)) not final; create type appointment_list_t as table of ref appointment_t; create type property_list_t as table of ref property_t; create type salesperson_t under person_t ( sSurname varchar2(20), sForename varchar2(20), dateOfBirth varchar2(12), makes appointment_list_t, member function appointments_made return number ); create type applicant_t under person_t ( aSurname varchar2(20), aForename varchar2(20), dateOfBirth varchar2(12), aAddressLine1 varchar2(25), aAddressLine2 varchar2(25), aTown varchar2(20), telephoneNums telephone_t, maxPrice number(10), desiredArea varchar2(20), attends appointment_list_t, member function appointments_attended return number ); create or replace type body salesperson_t as member function appointments_made return number is total number; begin total := self.makes.count; return total; end; end; create or replace type body applicant_t as member function appointments_attended return number is total number; begin total := self.attends.count; return total; end; end; create or replace type appointment_t as object ( appointment char(10), appdate date, apptime varchar2(15), appointmentType varchar2(15), levelOfInterest integer(3), offerMade number(10), is_made_by ref salesperson_t, is_attended_by ref applicant_t, is_related_to ref property_t); create or replace type property_t as object ( property char(10), dateOfRegistration date, propertyType varchar2(15), bedrooms integer(2), receptionRooms integer(2), bathrooms integer(2), garage varchar2(5), garden varchar2(6), regionArea varchar2(20), pAddressLine1 varchar2(20), pAddressLine2 varchar2(20), pTown varchar2(20), askingPrice varchar2(20), relatesTo appointment_list_t); create table person_tab of person_t ( person primary key ); create table property_tab of property_t ( primary key(property)) nested table relatesTo store as relates_to_table; create table appointment_tab of appointment_t ( primary key (appointment), scope for (is_made_by) is person_tab, scope for (is_attended_by) is person_tab, scope for (is_related_to) is property_tab); insert into person_tab values (salesperson_t('s001', 'Fontigue', 'Farquar', '22-feb-1980', appointment_list_t())); insert into person_tab values (salesperson_t('s002', 'Richmond', 'Neil', '30-feb-1983', appointment_list_t())); insert into person_tab values (salesperson_t('s003', 'Devere', 'Jeremy', '03-mar-1977', appointment_list_t())); insert into person_tab values (salesperson_t('s004', 'Schofield', 'Paul', '07-dec-1969', appointment_list_t())); insert into person_tab values (salesperson_t('s005', 'Johnson', 'Richard', '04-jul-1992', appointment_list_t())); insert into person_tab values (salesperson_t('s006', 'Stevens', 'Rupert', '22-may-1989', appointment_list_t())); insert into person_tab values (applicant_t('ap007', 'Hadfield', 'Linda', '22-nov-1981', '3 Duckdoo Avenue', 'Rosemont', 'Neath Port Talbot', telephone_t('01639877103', '07756338175'), '110000', 'Mumbles', appointment_list_t())); insert into person_tab values (applicant_t('ap008', 'Walsh', 'Riley', '18-sep-1974', '12 George Street', 'Taibach', 'Neath Port Talbot', '01639890337', '075982228741', '125000', 'Ten Acre Wood', appointment_list_t())); insert into person_tab values (applicant_t('ap009', 'Kennedy', 'Shaun', '11-dec-1972', '101 Granada Close', 'Waun Wen', 'Swansea', '01792558447', '07894558123', '150000', 'Central Swansea', appointment_list_t())); insert into person_tab values (applicant_t('ap010', 'Redgrave', 'Steven', '30-jun-1988', '47 Victoria Gardens', 'City Apartments', 'Neath', '01639770183', '07774273391', '95000', 'Neath', appointment_list_t())); insert into person_tab values (applicant_t('ap011', 'Hopkins', 'John', '07-feb-1979', '130 Flanders Court', 'Richfield', 'Bridgend', '01656889227', '05589337123', '137500', 'Brechfa', appointment_list_t())); insert into person_tab values (applicant_t('ap012', 'Glover', 'Germaine', '14-aug-1983', '32 Regent Crescent', 'Cranforth', 'Cardiff', '01210887336', '07975625195', '170000', 'Cardiff West', appointment_list_t()));
The one I am running made the telephone_t in all households.
Happy that you have your code working but that was not my point
It comes to you providing us with the correct instructions to actually run the test case and help you efficiently.
Regarding your last question, use the function of REGAL to caster level being superior in one of its subtype.
for example
SQL> select person 2 , treat(object_value as applicant_t).aSurname as surname 3 , treat(object_value as applicant_t).aForename as forename 4 from person_tab 5 where object_value is of (applicant_t) ; PERSON SURNAME FORENAME ------ -------------------- -------------------- ap007 Hadfield Linda ap008 Walsh Riley ap009 Kennedy Shaun ap010 Redgrave Steven ap011 Hopkins John ap012 Glover Germaine 6 rows selected.
Tags: Database
Similar Questions
-
How to get a select statement to pass a variable as the OUT parameter in PROC
I have the underside of the nested select statement that returns the name of the missing table (data_table_name).
How to be an effective way to modify the select statement, so that the returned 'data_table_name' is passed as OUTPUT in a procedure parameter
Any help is greatly appreciated.select 'Missing Table Name : ' || data_table_name from ( select upper(data_table_name) data_table_name from TABLE1 where data_table_name in ('ABC',EFG','XYZ') MINUS ( select upper(fus_data_table_name) from TABLE2 where fus_data_table_name in ('EFG',') group by upper(fus_data_table_name) union select upper(fus_data_table_name) from TABLE2 where fus_data_table_name = 'LMN' group by upper(fus_data_table_name) ));
SCREATE OR REPLACE PROCEDURE myproc (tname OUT NOCOPY VARCHAR2) AUTHID CURRENT_USER IS BEGIN SELECT something INTO tname FROM whatever; EXCEPTION WHEN OTHERS THEN tname :=
; END myproc; / -
How to use the Type of Oracle Table values in the Select statement.
Hello
I get the initial set of values in the Table of Type Records of the Oracle and want to use the list of values in the Select statement.
For example, try something like the following:
TYPE t_record () IS RENDERING
ID TABLEA.ID%type,
NO TABLEA.NO%type
);
v_record t_record;
T_table TYPE IS the v_record TABLE % TYPE;
v_table t_table;
-Code to fill the values of v_table here.
SELECT ID, NO, COLLECT in BULK IN < some other table variabes here > FROM TABLEA
WHERE ID IN (i) v_table USER.USER;
I want to know how to use the Type of Oracle Table values in the Select statement.Something like this:
create or replace type t_record as object ( id number, no number ) / CREATE or replace type t_table AS TABLE OF t_record; / set serveroutput on declare v_table t_table := t_table(); v_t1 t_table := t_table(); begin v_table.extend(1); v_table(1).ID := 1; v_table(1).No := 10; v_table.extend(1); v_table(2).ID := 2; v_table(2).ID := 20; SELEC t_record (ID,NO) BULK COLLECT INTO v_t1 from TableA FROM TABLEA WHERE ID IN (select t.ID from table(v_Table) t); for i in 1..v_t1.count loop dbms_output.put_line(v_t1(i).ID); dbms_output.put_line(v_t1(i).No); end loop; end; /
No test!
P;
Published by: bluefrog on March 5, 2010 17:08
-
mixture of column type in the select statement
Oracle 11g r2.
tab_test (name varchar2, blob... photo)
(1) select general use *.
Stored procedure: open ref_cursor to some * of table_test...
Coast of java: call.registerOutParameter (1, OracleTypes.CURSOR); Call.Execute ();
It works very well.
(2) enter the name of the column in the select such as
Stored procedure: open ref_cursor to select name, photo table_test...
Coast of java: call.registerOutParameter (1, OracleTypes.CURSOR); Call.Execute ();
ERROR: java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent data types: expected - got BLOB
My question, if I specify the column names in the select statement, including the varchar2 and blob, how can I registerOutParameter (1, OracleTypes.CURSOR);?
Thank you
Scott
PS The number of returned columns, in real case schenario, is a little, so I prefer to specify column names.
Wrong forum. This forum is for questions of sql and pl/sql.
Enter the question ANSWER and the repost in the JDBC forum
When repost you provide the necessary information to help you:
1. information on the full version for Oracle DB
2 version of the JDK
3. the name and version of the JDBC jar file
4. real code that demonstrates the problem
You should also review the info re REF CURSOR in the JDBC Developer's Guide
http://docs.Oracle.com/CD/E16655_01/Java.121/e17657/oraint.htm#i1058743
-
Skip and capture the Oracle SQL record dirty in a select statement
Hello
I have the Oracle Oracle 11.2.0.4 database when I run a select query.
Question:
10 columns have given Date format. When I try to execute this query into a FROG he says, a month not valid. Since the records are billion in nature, I am not able to know which line has this problem.
Is there a way I can capture the failed row and add it to other tables and continues with the select statement regardless of this error
OK, you have several TO_DATE functions fed a string that is built on the fly. At least part of the time, the chain that is built does not match the date format mask used.
For example:
TO_DATE (SUBSTR (TO_CHAR (SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID), 0, 8). » -'|| SUBSTR (TO_CHAR (SQ_W_PURCH_CYCLNS_ORA. (LAST_SUBMITTED_ON_DTTM_WID), 9, 6), "YYYYMMDD-HH24MISS")
"SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID' does not have a string where characters 5-6 are in the range 01-12. You'll have to do an analysis on this column. From its data and how that is managed by to_char. What ARE the data type of ' SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID' and what is a typical value?
As others have said, this is simply an impossibility for a column of a table to actually have invalid month (or day, or year, or hour or minute or second). ONLY, you get this error during the conversion of a string to a date with the TO_DATE function.
-
Is it possible to use the record type or a PL/SQL table in the Select statement
Hi all
My requirement is that.
I want to write a query and write a function, function, I want to return multiple columns at the same time in a Select statement.
I select the return values in the Select no statement in a PL/SQL block.
Is it possible to use the PL/SQL Table or Variable of Type record, or any other method in the statement Select?
Please help me understand the solution.
Kind regards830960 wrote:
do we like it?In general, Yes, if the function is a function table, you can do something like:
select t.col1, t.col2, f.col1, f.col2, f.col3 from table_name t, table(some_table_function(param1,...paramN)) f /
SY.
-
Create the view and by using the function that returns a type oracle
Following is possible?
A function returns an ORACLE object Type, and I want to use this feature, in my opinion, it is possible to access each field of the type once the function is executed and make a column in the view?
Now, I want to use the function according to me - if the underlying query of the view follows-create or replace TYPE SOME_INFO AS OBJECT ( CHARGE FLOAT, SOME_DATE DATE, SOME_VAL VARCHAR(50) ); CREATE OR REPLACE FUNCTION CALCULATE_INFO ( p_chargeId NUMBER) RETURN SOME_INFO AS v_some_info SOME_INFO := new SOME_INFO(0, null, null); BEGIN -- function body populates the v_some_info return v_some_info; END calculate_info;
How to recover someInfo.CHARGE, someInfo.some_date, someInfo.some_val? I can put them as columns in the view?select c.*, calculate_info(c.charge_id) as someInfo from some_charge;
If you use only functions that return a single value in a view?
Thank you
Mustapha
Published by: Tina Giri on April 16, 2009 05:47How to recover someInfo.CHARGE, someInfo.some_date, someInfo.some_val?
SQL> create or replace type some_info as object (charge float, some_date date, some_val varchar (50)); / Type created. SQL> create or replace function calculate_info (p_chargeid number) return some_info as v_some_info some_info := new some_info (0, null, null); begin -- function body populates the v_some_info return v_some_info; end calculate_info; / Function created. SQL> select your_view.someinfo.charge, your_view.someinfo.some_date, your_view.someinfo.some_val from (select c.*, calculate_info (c.empno) as someinfo from emp c) your_view where rownum <= 3 SOMEINFO.CHARGE SOMEINFO SOMEINFO.SOME_VAL --------------- -------- -------------------------------------------------- 0 0 0 3 rows selected.
-
Get the types of columns in a select statement
Hello
Is there a way to get the types of columns that results in a select statement?
For example to force an analysis on this topic and then look for the types of columns resulting in the view v$?
Best regards
Klaus Mogensen
declare c number; d number; col_cnt integer; rec_tab dbms_sql.desc_tab; col_num number; begin c := dbms_sql.open_cursor; dbms_sql.parse(c, 'select dummy, 33 x, sysdate now from dual', dbms_sql.native); dbms_sql.describe_columns(c, col_cnt, rec_tab); col_num := rec_tab.first; while col_num is not null loop dbms_output.put_line( rec_tab(col_num).col_name || ' ' || case rec_tab(col_num).col_type when 1 then 'varchar2' when 2 then 'number' when 12 then 'date' else '???? ' || rec_tab(col_num).col_type end ); col_num := rec_tab.next(col_num); end loop; dbms_sql.close_cursor(c); end; / DUMMY varchar2 X number NOW date
-
Find data of select statement - Oracle 11 g after having changed the connection?
IAM very very new to Oracle. Only yesterday I installed Oracle 11 G and created database - JafferDB
Oracle SQL Developer, I created a named connection - JafferCon and also given SID... and the role is - SYSDBA
And I excute the Sub statement
insert into MyTable1 Values ('AAA1', 'BBB1', "CCC1")
insert into MyTable1 Values ("AAA2", 'BBB2', "CCC2")
Then I checked by a Select statement, it showed the values... No problem...
But, as a test, I removed the connection and created a new tio of connection to the same database with a different name
and when I checked by the Select statement..., it has not shown the values...?
Made mistakes...?
Thanks for the directions...After insert, update, or delete data in the database you must use the statement "commit" or "dismantling". If you want to 'save' the changes or cancellation, if you do not have to commit.
Other users cannot see what new changes until you do the "commit". -
on integer column SELECT statement returns no data
After the export and import of database of 32-bit database 10 g 2 64 bits, 10gR 1, I get strange results
Select * from test
returns 5 rows
but
Select * from test
where col3 = 1
returns no rows
where col3 is an integer column and has a value of 1 for all lines.
K1 is varchar2, col2 is varchar2 and col3 and col4 are columns of integers
/ RajkumYou could start a ticket with the Support of Oracle for confirmation bug and see if there is a patch attached to your release.
Alternatively, if you have access to Metalink, search for 'erroneous results check constraint' and you will see a number of bugs confirmed around this area.
The solution recommended - other than to install a patch available - tends to set 10195 event to disable the use of predicates as check constraints.
For examplealter session/system set events '10195 trace name context forever, level 1';
If you go to the bottom of the event route, you may need to empty the pool shared before the definition of this event and execute the sql, otherwise you might find yourself just reuse the existing plan.
-
How to display the data type long using the select statement
Hai All
I have to select the text of a view. But the text is declared as long and I need to see full view
When I use this
Select the text in all_views where view_name = "DAILY_ATTEND_VIEW";
I have got only half of a select statement
Concerning
Srikkanth.MHello
SQL> SET LONG 100000 SQL> select text from user_views 2 where view_name='MVIEW'; TEXT ------------------------------------------ select e.empno,e.deptno,d.dname from emp@sdblink e,dept@sdblink d where e.deptno=d.deptno
But it is limited to sql alone. If you use the double click TOAD on the text column in the grid will show you the entire SQL views.
Unfortunately, there is limitation to consider,
The largest value that you return from the function would be 32 k (RETURN VARCHAR2), both.Twinkle
-
Return multiple values from a function in a SELECT statement
I hope I've provided enough information here. If not, let me know what I'm missing.
I create a view that will combine the information from several tables. Most are pretty simple, but there are a couple of columns in the view that I need to get by running a function within a package. Even if this is quite simple (I have a function named action_date in a package called rp, for example, that I can use to return the date that I need through SOME rp.action_date (sequence_number).
Here is the question: I really need to return several bits of information of the same record (not only action_date, but also action_office, action_value, etc.)-a join of the tables will work not here, as I will explain below. I can, of course, perform a function separate for each statement, but this is obviously inefficient. Within the select statement of the view, however, I don't know how each of the values that I need to get back.
For example, right now, I have:
Table 1:
sequence_number NUMBER (10),
name varchar (30),
...
Table2:
Table1_seq NUMBER (10),
action_seq NUMBER (10),
action_date DATE,
action_office VARCHAR (3),
action_value VARCHAR (60),
...
I can't just simply join Table1 and Table2 because I have to perform processing in order to determine the rows returned matching, I really need to select. If the package opens a cursor and treats each line until it finds the one I need.
The following works but is ineffective since all calls to the package returns the columns of the same record. I don't know how to put all the values that I need in the SELECT statement.
CREATE VIEW all_this_stuff AS
SELECT sequence_number, name,
RP.action_date (sequence_number) action_date,
RP.action_office (sequence_number) action_office,
RP.action_value (sequence_number) action_value
FROM table1
Is there a way to return multiple values in my SELECT statement or I'm going about this all wrong?
Any suggestions?
Thank you very much!Hello
What you want is a Query of Top - N , what you can do using the ROW_NUMBER analytic function in a subquery, like this:
WITH got_rnum AS ( SELECT action_seq, action_dt, action_office, action_type, action_value , ROW_NUMBER () OVER ( ORDER BY action_date , action_seq , action_serial ) AS rnum FROM table2 WHERE action_code = 'AB' AND action_office LIKE 'E' -- Is this right? ) SELECT action_seq, action_dt, action_office, action_type, action_value FROM got_rnum WHERE rnum = 1 ;
As written, this returns a single line (at most).
I suspect you'll actually get a rank for each group , where a group is defined by a value in a table in which you join.
In this case, add a PARTITION BY clause to the ROW_NUMBER function.
If post you a small example of data (CREATE TABLE and INSERT statements), I could show you exactly how.
As I don't have your tables, I'll show you the use of the tables in the scott schema.
This is a view containing data in the scott.dept table and also to scott.emp, but only for the highest employee in each Department (in other words, the employee whose oldest hire date). If there be a tie for the first hire date, while the candidate with the lowest empno is selected.CREATE OR REPLACE VIEW senior_emp AS WITH got_rnum AS ( SELECT d.deptno , d.dname , e.empno , e.ename , e.hiredate , ROW_NUMBER () OVER ( PARTITION BY d.deptno ORDER BY e.hiredate , e.empno ) AS rnum FROM scott.dept d JOIN scott.emp e ON d.deptno = e.deptno ) SELECT deptno , dname , empno , ename , hiredate FROM got_rnum WHERE rnum = 1 ; SELECT * FROM senior_emp ;
Output:
. DEPTNO DNAME EMPNO ENAME HIREDATE ---------- -------------- ---------- ---------- --------- 10 ACCOUNTING 7782 CLARK 09-JUN-81 20 RESEARCH 7369 SMITH 17-DEC-80 30 SALES 7499 ALLEN 20-FEB-81
Moreover, one of the conditions to the query you posted has been
action_office LIKE 'E'
which equals
action_office = 'E'
(AS is always equivalent to = if the string that follows AS does not contain the winning cards.)
Did you mean say that or did you mean something like this:action_office LIKE 'E%'
Instead?
-
How to ask the user to type in the select statement
Hello
Can anyone tell me the syntax of the select statement where I can ask the user to enter the value.
for example, I try to use belowthing, but it displays error
Select * from emp where empname =: empname
SP2-0552: Bind "empname' undeclared variable.
2. is there a dictionary of data table to see all pl/sql procedures and corresponding code?
Thank you
SriTry:
select * from emp where empname='&empname';
L.
-
How to insert the value of the variable using select statement - function Oracle
Hello
I have a function that inserts the record based on a condition
INSERT IN the case
(
Case_ID,
Case_Status,
Closure_Code,
Closure_Date
)(
SELECT newCaseID,
caseStatus,
Closure_Code,
Closure_Date,
CASE
WHERE Case_ID = caseID
);
Now, I want the new value casestatus instead of value caseStatus select statement. I have a m_caseStatus variable and I want to use the value of this variable in the select statement above.
How can I use this.
Thank youINSERT INTO Case ( Case_ID, Case_Status, Closure_Code, Closure_Date )( SELECT newCaseID, m_caseStatus, <-- here place your variable Closure_Code, Closure_Date, FROM Case WHERE Case_ID = caseID );
Nicolas.
-
Details by e-mail to the people found in the select statement
Hello
I managed to send me an e-mail to test base for the first time.
However, I now require a method to be found via a SQL select with their information only email people.
for example, select statement returns the details below: -.
NAME OF APPLICATION DETAILS
Fred.Bloggs request2 details
Fred.Bloggs request4 details
Jim.Blair request3 details
I should concatenate the field IE @company.com
so
[email protected] receiving an email
"request2 details" completed
"request4 details" completed
and
[email protected] receiving an email
"Details of the request3" completed
I need help for the loop enter the full e-mail address of each person, and then send them only their data.
Thanks in advance for your help.
Wire UPDATE with news (previously the report erroneously) select sql statement
your Reported
Published by: user11962502 on December 1st, 2009 01:56
Published by: user11962502 on December 1st, 2009 02:02Hello
I don't have easy access to an Oracle instance to check it works and get the syntax right right right now but my first reaction would be to use a combination of rpad() and width as the column to be constant. This can be a you hard-code (IE, if you know what type of query will always say less than 8 characters) or ideally, first select the maximum length of the table:SELECT MAX(LENGTH(request)) + 3 INTO l_max_length FROM my_table WHERE clauses; /*Added the three to give a bit of extra space - modify to suit your needs*/
Then when you are out of the field, do something like:
message:=message || rpad(i.request,l_max_length - LENGTH(i.request));
This will ensure that everything is aligned. Of course, it only works if the email is sent in plain text and that the user is using a font to width fixed to read emails in plain text. Most people do, but do not count on it.
As before, the other option is to use an HTML table, however HTML emails are not very nice - try to stick with the plaintext if possible! :)
Maybe you are looking for
-
Blue screen on Inroom X 200-219 during execution of Adobe Lightroom-slide show
I am running Vista Business SP1 32-bit and I upgraded my RAM to 4 GB. I have 50 GB free on my C: drive. Whenever I run the slideshow in Lightroom 1.3.1 and 1.4.1 I get the blue screen of death. I swapped the original back in memory but get the same r
-
Encryption of files on iomega ix4 - 200 d
Hi all I would like to know if there is a way to put an encryption of files within the NAS, not only the SSL protocol in the communication. Thank you all
-
How can I set an alarm to tell me that I put the caps lock on?
On my old laptopwindows vista, I got an alarm beep to let me know when I had inadvertently put caps lock. I can't find it on windows 7 can someone help me please?
-
BlackBerry smartphones no sound from the speakers during playback of media
The title speaks for itself. When I try to play music or videos and listen to them through the loudspeaker of the storm, I have no sound. I get sound even if I use headphones. I already have a clear memory, nothing has changed.
-
Photoshop 64-bit CS5.1 is compatible with Windows 10?
Please could you tell me if Photoshop 64-bit CS5.1 is compatible with Windows 10?