Simple select statement
drop table t10; create table t10 (seq number, code number, value varchar2(10)); insert into t10 values (1, 10, 'first'); insert into t10 values (2, 10, 'second'); insert into t10 values (3, 10, 'third'); insert into t10 values (1, 20, 'first'); insert into t10 values (2, 20, 'second'); commit; select * from t10;
the result obtained
SQL> select * from t10; SEQ CODE VALUE ---------- ---------- ---------- 1 10 first 2 10 second 3 10 third 1 20 first 2 20 second
can we select it write as simply as possible to return onlythe row that contains the highest SEQ for a CODE
so I would like to
SEQ CODE VALUE ---------- ---------- ---------- 3 10 third 2 20 second
This seems like it should be simple, but the brain is just not see the solution and fried. Thank you.
Hello
GregV wrote:
Hello
Another way:
Select max (seq) Dungeon (last dense_rank command by seq) seq, code, max (value) value of Dungeon (last dense_rank command by seq)
T10
Code group;
You can simplify that:
Max (SEQ)
Get exactly the same results as
Max (SEQ) keep (last dense_rank command by seq)
Tags: Database
Similar Questions
-
If then the clause for a simple select statement.
Good afternoon
I'm sure this will be really simple for a person: I have three paintings that I need to access it in a simple select statement. However, I need to make two separate petitions by a field has an entry or not. Here is the code I wrote so far. It is only to retune the ELSE part, which means that I know I'm close, but I know I'm missing something incredibly simple and boring for me right now.
IF common_event.efeanme IS NULL THEN SELECT a.num_1 AS "EVENT NUMBER", CONCAT(CONCAT(CONCAT(CONCAT(SUBSTR(a.cdts,5,2), '/'), SUBSTR(a.cdts,7,2)), '/'), SUBSTR(a.cdts,1,4)) AS "EVENT DATE", CONCAT(CONCAT(c.xstreet1, ' / '), c.xstreet2) AS "EVENT LOCATION" FROM common_event c JOIN agency_event a ON c.eid=a.eid JOIN disposition_type d ON a.ag_id=d.ag_id WHERE a.ag_id='JCSO' AND a.lev3='JC3' AND a.cdts BETWEEN '20140701' AND '20141001' AND d.tycod='CIT' ORDER BY a.num_1; ELSE SELECT a.num_1 AS "EVENT NUMBER", CONCAT(CONCAT(CONCAT(CONCAT(SUBSTR(a.cdts,5,2), '/'), SUBSTR(a.cdts,7,2)), '/'), SUBSTR(a.cdts,1,4)) AS "EVENT DATE", CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(c.estnum, ' '), c.edirpre), ' '), c.efeanme), ' '), c.efeatyp) AS "EVENT LOCATION" FROM common_event c JOIN agency_event a ON c.eid=a.eid JOIN disposition_type d ON a.ag_id=d.ag_id WHERE a.ag_id='JCSO' AND a.lev3='JC3' AND a.cdts BETWEEN '20140701' AND '20141001' AND d.tycod='CIT' ORDER BY a.num_1; END IF;
If I run a query on its own, it works as expected. Which means that I don't get something right (in my opinion) in my CASE SO the ELSE clause. As I said, it's probably something so simple I forget only she, but I better ask for a direction somewhat see where I'm going to do it right.
Thanks in advance for any guidance.
Tony
Cant you just do:
SELECT a.num_1 'EVENT NUMBER. "
Concat (Concat (Concat (Concat (substr (a.CDTS, 5, 2), ' / '), SUBSTR (a.cdts, 7, 2)), ' / '), SUBSTR (a.cdts, 1, 4)) AS 'EVENT DATE ',.
-case when c.efeanme IS NULL
then CONCAT (CONCAT (c.xstreet1, ' /'), c.xstreet2)
of another CONCAT (CONCAT (CONCAT (CONCAT (CONCAT (CONCAT (c.estnum, ' '), c.edirpre), ' '), c.efeanme), ' '), c.efeatyp)
end AS 'EVENT ADDRESS'
OF common_event c
JOIN THE
agency_event one
WE c.eid = a.eid
JOIN the disposition_type d
ON a.ag_id = d.ag_id
WHERE a.ag_id = 'JCSO.
AND a.lev3 = 'JC3.
AND a.cdts BETWEEN '20140701' AND '20141001'
AND d.tycod = 'CIT '.
ORDER BY a.num_1
Concerning
Etbin
Deleted AND c.efeanme IS NULL
-
a simple select statement once again
What is the meaning of the one below select statement, pay attention to (sysdate + 1.1)
Select (sysdate + 1.1) of the double
Hello
a_cute_person wrote:
Lo, seriously, dude you do not make to_char thing, when I select sysdate, sysdate + 1.1 double I see clearly there is time change, I wanted to know what the weather has changed when I do sysdate + 1.1, and why there is no change in time sysdate + 1. hope you have the hand on what I ask
Understand this:
When you add 1 to SYSDATE, a full day is added. So, if the current time i.e. SYSDATE is January 22, 2015 16:55 ', by adding 1, it will be named January 23, 2015 16:55 '. Simple.
But, 1.1 means one-tenth day and fractional hour comes in picture.
Yes, day 1.1
= 1 + 1/10 of the next whole day
= 24 * 60 * 60 seconds + (1/10) * 24 * 60 * 60 seconds
and here the time portion changes.
HTH.
-Nordine
-
I have data like below
p_no s_text
1-abcdefgh
1 ijklmnop
1 qrstuvwx
what I need, it is print the output as below, I do not want to use sys_connect_by_path and please advise me not to look at the lines of examples of columns
p_no s_text_1 s_text_2 s_text_3
1 abcdefgh ijklmnop qrstuvwx
Strange HM. You have 'only' with the statement.
with tab (p_no, o_text)
as - look here, have you?
(
Select 1, 'asdasd' from dual Union of all the Select 1, 'xcvxcvxc' from dual Union of all the Select 1, 'Souleymane' from dual ) Select P_no, min (case when r = 1 then end s_text) S_text_1,. min (case when r = 2 end s_text) S_text_2,. min (case when r = 3 there end s_text) S_text_3 de) Select p_no, o_text, row_number() over (partition by order p_no by s_text) r of the tab) P_no group; try using this table querry.
Select P_no, min (case when r = 1 then end s_text) S_text_1,.
min (case when r = 2 end s_text) S_text_2,.
min (case when r = 3 there end s_text) S_text_3
de)
Select p_no, o_text, row_number() over (partition by order p_no by s_text) r of
) - put your table here P_no group;
-
Problem with the simple Select statements
Hi experts,
I have with SQL Server and I'm going to hurt when I use the similar syntax in sqlplus to query an Oracle table.
For example... my table contains column SCHID SET in the numeric form. Table has thousands of lines and the SCHID column is filled.
Select TOP 100 AFTSCHAUXDATA SCHID;
Get the "Word FROM key not found where expected" error
Select DISTINCT from AFTSCHAUXDATA SCHID;
Download "no selected lines.
Can someone help me please?
Thank you, JohnCan someone tell me how to find the names of the 20 largest tables (bigger which means that most of the files)?
Once you have updated statistics on the table, you can query the DataDictionary: USER_TABLES/ALL_TABLES/DBA_TABLES.
I'm assuming that user_tables will do:select * from ( select table_name , num_rows from user_tables order by num_rows desc nulls last ) where rownum <= 20;
You can find more explanations about the DataDictionary in the Oracle Online Documentation.
Just do a quick and easy search
http://www.Oracle.com/pls/db112/homepage
or
http://www.Oracle.com/pls/db102/homepage
Depending on your version of the database. -
Set the Variable in the select statement
Hello
Can we define a variable in the select statement.
Example:
Select firstname, lastname
employees;
in this simple select statement we can define x as number?select fname,lname from employees where rownum <= 30;
-
Add more than 2 lines for a select statement without inserting rows in the base table
Hi all
I have a below a simple select statement that is querying a table.
Select * from STUDY_SCHED_INTERVAL_TEMP
where STUDY_KEY = 1063;
but here's the situation. As you can see its return 7 ranks. But I must add
2 rows more... with everything else, default or what exist... except the adding more than 2 lines.
I can't insert in the base table. I want my results to end incrementing by 2 days in
measurement_date_Taken on 01-APR-09... so big measurement_date_taken expected to
end at study_end_Date...
IS IT STILL POSSIBLE WITHOUT INSERT ROWS IN THE TABLE AND PLAYIHY ALL AROUND WITH
THE SELECT STATEMENT?
Sorry if this is confusing... I'm on 10.2.0.3
Published by: S2K on August 13, 2009 14:19Well, I don't know if this request is as beautiful as my lawn, but seems to work even when ;)
I used the "simplified" version, but the principle should work for your table, S2K.
As Frank has already pointed out (and I fell on it while clunging): simply select your already existing lines and union them with the 'missing documents', you calculate the number of days that you are "missing" based on the study_end_date:MHO%xe> alter session set nls_date_language='AMERICAN'; Sessie is gewijzigd. Verstreken: 00:00:00.01 MHO%xe> with t as ( -- generating your data here, simplified by me due to cat and lawn 2 select 1063 study_key 3 , to_date('01-MAR-09', 'dd-mon-rr') phase_start_date 4 , to_date('02-MAR-09', 'dd-mon-rr') measurement_date_taken 5 , to_date('01-APR-09', 'dd-mon-rr') study_end_date 6 from dual union all 7 select 1063, to_date('03-MAR-09', 'dd-mon-rr') , to_date('04-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all 8 select 1063, to_date('03-MAR-09', 'dd-mon-rr') , to_date('09-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all 9 select 1063, to_date('03-MAR-09', 'dd-mon-rr') , to_date('14-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all 10 select 1063, to_date('03-MAR-09', 'dd-mon-rr') , to_date('19-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all 11 select 1063, to_date('22-MAR-09', 'dd-mon-rr') , to_date('23-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all 12 select 1063, to_date('22-MAR-09', 'dd-mon-rr') , to_date('30-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual 13 ) -- actual query: 14 select study_key 15 , phase_start_date 16 , measurement_date_taken 17 , study_end_date 18 from t 19 union all 20 select study_key 21 , phase_start_date 22 , measurement_date_taken + level -- or rownum 23 , study_end_date 24 from ( select study_key 25 , phase_start_date 26 , measurement_date_taken 27 , study_end_date 28 , add_up 29 from ( 30 select study_key 31 , phase_start_date 32 , measurement_date_taken 33 , study_end_date 34 , study_end_date - max(measurement_date_taken) over (partition by study_key 35 order by measurement_date_taken ) add_up 36 , lead(measurement_date_taken) over (partition by study_key 37 order by measurement_date_taken ) last_rec 38 from t 39 ) 40 where last_rec is null 41 ) 42 where rownum <= add_up 43 connect by level <= add_up; STUDY_KEY PHASE_START_DATE MEASUREMENT_DATE_TA STUDY_END_DATE ---------- ------------------- ------------------- ------------------- 1063 01-03-2009 00:00:00 02-03-2009 00:00:00 01-04-2009 00:00:00 1063 03-03-2009 00:00:00 04-03-2009 00:00:00 01-04-2009 00:00:00 1063 03-03-2009 00:00:00 09-03-2009 00:00:00 01-04-2009 00:00:00 1063 03-03-2009 00:00:00 14-03-2009 00:00:00 01-04-2009 00:00:00 1063 03-03-2009 00:00:00 19-03-2009 00:00:00 01-04-2009 00:00:00 1063 22-03-2009 00:00:00 23-03-2009 00:00:00 01-04-2009 00:00:00 1063 22-03-2009 00:00:00 30-03-2009 00:00:00 01-04-2009 00:00:00 1063 22-03-2009 00:00:00 31-03-2009 00:00:00 01-04-2009 00:00:00 1063 22-03-2009 00:00:00 01-04-2009 00:00:00 01-04-2009 00:00:00 9 rijen zijn geselecteerd.
Is there a simpler way (in SQL), I hope that others join, and share their ideas/example/thoughts.
I feel that it is using more resources there.
But I have to cut the daisies before now, they interfere my 'grass-green-ess";) -
Need help with the use of GROUP BY in a select statement UNION
I am writing a query that allows to combine a legacy system that interfaces it is trial balance in the Oracle of R12 GL. It was only meant to continue for a month or two, but it is likely to continue for 6 months. Please Auditors Auditors, to provide proof that the system is in balance with Oracle GL. By my verification requirements, I need to make a full reconciliation from the month of conversion (life in the amount of date), then PTD for each month.
The legacy account is placed in attribute1 on the lines of the journals. Uses of the old system balancing segments that are also used on the platform in Oracle for this division, i.e., Procure-to-Pay has been cut over Oracle, but not everything yet. So, I can't count on the GL_BALANCES table for the info, I get from the JE_LINES.
My problem is not the only request for the month. But when I try to combine the queries with a Union, to aggregation of each measurement period in its own column, the group is necessary after each selected instruction rather than allowing me to put at the end of the UNION. (When I put the group by at the end of the UNION, I have the 'not one group' function)
So I get duplicate for each month of discrete measure accounts. When I duplicate in my Oracle database accounts, I can't count on the VLOOKUP function in excel to exactly match an account of inheritance. I know there are more sophisticated ways to provide this output, but I'm hoping to get this info in a simple query.
Thank you in advance for any advice you can provide
Example of data output (the goal for me is to get the two rows to appear as one based on common points on the LEGACY_ACCOUNT and the ORACLE ACCOUNT
The LEGACY ACCOUNT ORACLE ACCOUNT JUN_15 JUL_15 AUG_15 SEP_15 OCT_15 NOV_15 DEC_15 010000001109000003584 190-600552-1001-100231-000-0000-0000-0000 0 0 -242961.04 0 0 0 0 010000001109000003584 190-600552-1001-100231-000-0000-0000-0000 0 192588.02 0 0 0 0 0 Here is a simplified version of my code that returns both records. In my research, I had found a number of conversations where it has been shown that the group could be put at the end of the select statement. However, when I remove the group from the first select statement I get SQL error: ORA-00937: not a function of simple-group
Select
l.attribute1 LEGACY_ACCOUNT,
C.SEGMENT1: '-' | C.SEGMENT2: '-' | C.SEGMENT3: '-' | C.SEGMENT4: '-' | C.SEGMENT5: '-' | C.SEGMENT6: '-' | C.SEGMENT7: '-' | COMBINATION OF C.SEGMENT8,
JUN_15 TO_NUMBER('0').
JUL_15, sum (NVL(l.accounted_dr,0.00)-NVL(l.accounted_cr,0.00)),
TO_NUMBER('0') AUG_15.
TO_NUMBER('0') SEP_15.
TO_NUMBER('0') OCT_15.
TO_NUMBER('0') NOV_15.
DEC_15 TO_NUMBER('0')
Of
b GL.gl_je_batches,
GL.gl_je_headers h,
GL.gl_je_lines l,
GL.gl_code_combinations c,
GL.gl_je_sources_tl j
where b.je_batch_id = h.je_batch_id
and h.je_header_id = l.je_header_id
and l.code_combination_id = c.code_combination_id
and h.je_source = j.je_source_name
and c.segment1 ('190 ', '191', '192', '193', '194', ' 195 ', ' 196',' 197', ' 198 ', ' 199',)
('200 ', '203', ' 205', '206 ', '330', '331', '332',' 333 ', ' 334',' 335', ' 336 ', ' 337')
and j.language = 'en '.
and h.PERIOD_NAME ("JUL-15'")
Group
l.attribute1,
C.SEGMENT1: '-' | C.SEGMENT2: '-' | C.SEGMENT3: '-' | C.SEGMENT4: '-' | C.SEGMENT5: '-' | C.SEGMENT6: '-' | C.SEGMENT7: '-' | C.SEGMENT8
UNION
Select
l.attribute1 LEGACY_ACCOUNT,
C.SEGMENT1: '-' | C.SEGMENT2: '-' | C.SEGMENT3: '-' | C.SEGMENT4: '-' | C.SEGMENT5: '-' | C.SEGMENT6: '-' | C.SEGMENT7: '-' | COMBINATION OF C.SEGMENT8,
JUN_15 TO_NUMBER('0').
TO_NUMBER('0') JUL_15.
AUG_15, sum (NVL(l.accounted_dr,0.00)-NVL(l.accounted_cr,0.00)),
TO_NUMBER('0') SEP_15.
TO_NUMBER('0') OCT_15.
TO_NUMBER('0') NOV_15.
DEC_15 TO_NUMBER('0')
Of
b GL.gl_je_batches,
GL.gl_je_headers h,
GL.gl_je_lines l,
GL.gl_code_combinations c,
GL.gl_je_sources_tl j
where b.je_batch_id = h.je_batch_id
and h.je_header_id = l.je_header_id
and l.code_combination_id = c.code_combination_id
and h.je_source = j.je_source_name
and c.segment1 ('190 ', '191', '192', '193', '194', ' 195 ', ' 196',' 197', ' 198 ', ' 199',)
('200 ', '203', ' 205', '206 ', '330', '331', '332',' 333 ', ' 334',' 335', ' 336 ', ' 337')
and j.language = 'en '.
and h.PERIOD_NAME ("AUG-15'")
Group
l.attribute1,
C.SEGMENT1: '-' | C.SEGMENT2: '-' | C.SEGMENT3: '-' | C.SEGMENT4: '-' | C.SEGMENT5: '-' | C.SEGMENT6: '-' | C.SEGMENT7: '-' | C.SEGMENT8
order by 1
Is there a good reason to make this period both as a series of trade unions? This looks like a classic pivot for me query. This will make a way through the tables and should get the desired results.
Select l.attribute1 legacy_account,
c.Segment1: '-' | c.Segment2: '-' | c.segment3: '-' | c.segment4: '-' |
c.segment5: '-' | c.segment6: '-' | c.segment7: '-' | combination of c.segment8,
sum (case when h.period_name = 'JUN-15'
then nvl(l.accounted_dr,0.00)-nvl(l.accounted_cr,0.00)
otherwise 0 end) jun_15,.
sum (case when h.period_name = 'JUL-15'
then nvl(l.accounted_dr,0.00)-nvl(l.accounted_cr,0.00)
otherwise 0 end) jul_15,.
- and similar to DEC - 15
GL.gl_je_batches b, gl.gl_je_headers h, gl.gl_je_lines l.
GL.gl_code_combinations c, gl.gl_je_sources_tl j
where b.je_batch_id = h.je_batch_id
and h.je_header_id = l.je_header_id
and l.code_combination_id = c.code_combination_id
and h.je_source = j.je_source_name
and c.segment1 ('190', '191', '192', '193', '194', '195',' 196', ' 197',
'198 ', '199', '200', '203', '205' ', 206',' 330 ', ' 331',
"332 ', '333', '334', '335',' 336 ', ' 337')
and j.language = 'en '.
and h.period_name (' Jun-15', ' 15 JUL', ' AUG-15'... "" ")
L.attribute1 group,
c.Segment1: '-' | c.Segment2: '-' | c.segment3: '-' |
c.segment4: '-' | c.segment5: '-' | c.segment6: '-' |
c.segment7: '-' | c.segment8
If you're on the 11G version of the database, you might want to look at the PIVOT keyword that will do the same thing in a more concise expression.
John
-
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.
-
Hello community, I have a problem when creating a function. The purpose of this function is to check the table of weather gave yesterday or not. We must check this on different tables on different sachems. We are creating a function with input variables.
CREATE OR REPLACE FUNCTION IN_SCHEMA.IS_YDAYDATA_TO_TABLE
(
in_schema IN VARCHAR2,
in_tablename IN VARCHAR2,
in_datefield IN VARCHAR2,
)
RETURNS INTEGER
AS
-Declaring variables
v_is_true INTEGER.
BEGIN
SELECT
CASE
WHEN MAX (in_datefield) = TRUNC(SYSDATE-1)
THEN 1
ON THE OTHER
0
END
IN
v_is_true
Of
in_schema.in_tablename
;
RETURN v_is_true;
END;
/
When creating, I got error: [error] ORA-00942 (44:19): PL/SQL: ORA-00942: table or view does not exist
How to use the values of the input variables on the table select statement names?
Hello
Here's a way you can use dynamic SQL statements for this task:
CREATE OR REPLACE FUNCTION IS_YDAYDATA_TO_TABLE
(
in_schema IN VARCHAR2,
in_tablename IN VARCHAR2,
in_datefield IN VARCHAR2,
in_first_date DATE DEFAULT SYSDATE - 1,.
in_last_date DATE by DEFAULT NULL
)
RETURNS INTEGER
AS
-IS_YDAYDATA_TO_TABLE returns 1 if in_schema.in_tablename.in_datefield
-contains all the dates in the in_first_date of the range through included in_last_date
- and it returns 0 if there is no such lines.
-If in_last_date is omitted, the search only the data on in_first_date.
-If in_first_date is omitted, it defaults to yesterday.
-Time parts of the in_first_date and in_last_date are ignored.
-Declaring variables
sql_txt VARCHAR2 (1000);
v_is_true INTEGER.
BEGIN
sql_txt: = 'SELECT COUNT (*).
|| 'FROM ' | in_schema | '.' || in_tablename
|| 'WHERE ' | in_datefield | ' > =: d1'
|| «AND» | in_datefield | '< > >
|| 'AND ROWNUM = 1';
dbms_output.put_line (sql_txt |) '= sql_txt in IS_YDAYDATA_TO_TABLE"); -For debugging
Sql_txt EXECUTE IMMEDIATE
IN v_is_true
With the HELP of TRUNC (in_first_date) - d1
TRUNC (NVL (in_last_date
in_first_date
)
) + 1 -- d2
;
RETURN v_is_true;
END is_ydaydata_to_table;
/
DISPLAY ERRORS
If you must use dynamic SQL statements, put all the SQL statement in a single string variable, such as sql_txt in the example above. In this way, you can easily see exactly what will be executed. Comment out the call to dbms_output under test is completed.
Try to write functions that will address not only the question that you have now, but similar questions that you may have in the future. For example, now that interest you only to the verification of the data of yesterday, but later, you might want to check another day or range of days. The above function combines the convenience of a function simple (looks like yesterday data if you don't tell him otherwise) with the power of a more complex function (you can use the same function to check any day or range of days).
-
TimesTen create a lock for a select statement through sqldev
What ttisql use connect to TimesTen Release 7.0.6.15.0 to autocommit = 1, there is no lock for a select statement.
but when I use sql developer (driver is ttjdbc5.jar, regardless of the version) to connect, even with autocommit = 1, there will be locks for the select statement.
Is this a bug? How can I achieve the same no lock for a select statement through sql developer? Thank you.
-your update told me that you are connected to a remote timesten data store using the client driver
-the output from ttXactAdmin shows that SqlNavigator has a shared lock on the database itself: it will not interfere with someone else "read operations and I think that until you actually try a kind of DML against the database that e IX lock on the database lock will not interfere with any other DML either."
-sharing database lock is still acquired for any transaction TimesTen. You can test it for yourself ttisql: set off autocommit, perform a simple update and do not commit the transaction. Then, open a separate session and run ttxactadmin - you will have the database IX lock as well as the various locks on the tables and indexes.
-I think this pretty much proves my original thought: this sqlDeveloper attaches to TimesTen in transaction mode. However, the IX lock on the database will not interfere with anyone else's work and should not be a problem.
-
Invalid identifier on the Select statement
New to SQL. I'm having some trouble with a function.
Assignment is:
1. develop and execute a CREATE FUNCTION statement to create the DAY_ORD_SF function. Use the column DTCREATED table bb_basket as the date that the basket was created. Call the function TO_CHAR using the option of the DAY to extract the day of the week for a date value.
1. create a SELECT statement that lists the basket id and the day of the week set for each basket.
3. create a SELECT with a GROUP BY clause query to list the total number of baskets by day of the week. Who is the most popular of a day shopping? (Should discover that it is FRIDAY).
So far, I have the function:
Have you tried a select invalid identifier and get on o_dt. have you tried several different variables and impossible to find one that works.CREATE OR REPLACE FUNCTION DAY_ORD_SF (P_ORDER_DATE IN BB_BASKET.DTORDERED%TYPE) RETURN VARCHAR2 IS LV_DAY_WK VARCHAR2(3); BEGIN SELECT TO_CHAR(P_ORDER_DATE, 'DAY') INTO LV_DAY_WK FROM BB_BASKET WHERE P_ORDER_DATE = DTORDERED; RETURN LV_DAY_WK; END; /
Any help would be appreciated.SELECT DAY_ORD_SF(O_DT) "DAY", COUNT(*) FROM BB_BASKET GROUP BY DAY_ORD_SF(O_DT) ;
>
DTCREATED is a column name in the table BB_BASKET. When I pass O_DT to DTCREATED, I get an error:
>
So track what causes this error. Your instructions were to use DTCREATED.You use this query in your service
SELECT TO_CHAR(P_ORDER_DATE, 'DAY') INTO LV_DAY_WK FROM BB_BASKET WHERE P_ORDER_DATE = DTORDERED;
And the error tells you that LV_DAY_WK is too small. Why is it too small? Look at how it is defined and then look at the results of this query
SELECT TO_CHAR(DTCREATED, 'DAY') FROM BB_BASKET
and see if you can see what the problem is.
You do your development backward. Failed to start by trying to call a function that does not work. And you can't start by writing a function that includes queries that have not been tested.
The right way to generate code is to create simple components. Then test these simple components (for example a query) to ensure they work. Then mix the simple components in a component more complex as a function. Then, you can test the function of another request call.
The key is to start with simple things that work.
-
Create table as select statement (ETG) takes a long time.
Hi all
One of my procedure launched a table create as select statement each month.
Usually it ends in 20 minutes. for 6172063 records and 1 hour in 13699067.
But this time it never even takes to 38076 records.
When I checked everything he does is the CPU usage. No e/s.
I did a count (*) using the query, it has brought very good results.
BUT guard going on DEC.
I use Oracle 10.2.0.4.
temp_ip of the main table has 38076
table nhs_opcs_hier has 26769 records.
and table nhs_icd10_hier 49551 records.
-------------------
Query is:
create the table analytic_hes.temp_ip_hier as
Select b.*, (select nvl (max (hierarchy), 0))
of ref_hd.nhs_opcs_hier one
where fiscal_year = b.hd_spell_fiscal_year
and a.code in
(primary_PROCEDURE, secondary_procedure_1, secondary_procedure_2,
secondary_procedure_3, secondary_procedure_4, secondary_procedure_5,
secondary_procedure_6, secondary_procedure_7, secondary_procedure_8,
secondary_procedure_9, secondary_procedure_10,
secondary_procedure_11, secondary_procedure_12)) as hd_procedure_hierarchy,
(select nvl (max (hierarchy), 0) for ref_hd.nhs_icd10_hier one)
where fiscal_year = b.hd_spell_fiscal_year
and a.code in
(primary_diagnosis, secondary_diagnosis_1,
secondary_diagnosis_2, secondary_diagnosis_3,
secondary_diagnosis_4, secondary_diagnosis_5,
secondary_diagnosis_6, secondary_diagnosis_7,
secondary_diagnosis_8, secondary_diagnosis_9,
secondary_diagnosis_10, secondary_diagnosis_11,
secondary_diagnosis_12, secondary_diagnosis_13,
secondary_diagnosis_14)) as hd_diagnosis_hierarchy
of analytic_hes.temp_ip b
-----------------
Any help would be greatly appreciatedHello
It is a bit of a wild card, I think because it will require 14 scans to fill the table temp_ip to unpivot codes diagnostic and procedure, so this lilkely things are moving slower than the original. However, as it is a temporary table, I guess you could have some control over its structure, or at least be able to dismiss it and try something else. If you are able to change the structure of this table, you could make the application much simpler and probably much faster. I think that you need a list of codes of procedure for the year and a list of diagnosis for fiscal codes. I do this through the large list of UNION all THE INSTRUCTIONS, but you can have a more efficient way to do according to the base tables you are people temp_ip of. In any case, it's here (as far as I can tell this will do the same job)
WITH codes AS ( SELECT bd.primary_key_column_s, hd_spell_fiscal_year, primary_PROCEDURE procedure_code, primary_diagnosis diagnosis_code, FROM temp_ip UNION ALL SELECT bd.primary_key_column_s, hd_spell_fiscal_year, secondary_procedure_1 procedure_code, secondary_diagnosis_1 diagnosis_code FROM temp_ip UNION ALL SELECT bd.primary_key_column_s, hd_spell_fiscal_year, secondary_procedure_2 procedure_code , secondary_diagnosis_2 diagnosis_code FROM temp_ip UNION ALL SELECT bd.primary_key_column_s, hd_spell_fiscal_year, secondary_procedure_3 procedure_code, secondary_diagnosis_3 diagnosis_code FROM temp_ip UNION ALL SELECT bd.primary_key_column_s, hd_spell_fiscal_year, secondary_procedure_4 procedure_code, secondary_diagnosis_4 diagnosis_code FROM temp_ip UNION ALL SELECT bd.primary_key_column_s, hd_spell_fiscal_year, secondary_procedure_5 procedure_code, secondary_diagnosis_5 diagnosis_code FROM temp_ip UNION ALL SELECT bd.primary_key_column_s, hd_spell_fiscal_year, secondary_procedure_6 procedure_code, secondary_diagnosis_6 diagnosis_code FROM temp_ip UNION ALL SELECT bd.primary_key_column_s, hd_spell_fiscal_year, secondary_procedure_7 procedure_code, secondary_diagnosis_7 diagnosis_code FROM temp_ip UNION ALL SELECT bd.primary_key_column_s, hd_spell_fiscal_year, secondary_procedure_8 procedure_code, secondary_diagnosis_8 diagnosis_code FROM temp_ip UNION ALL SELECT bd.primary_key_column_s, hd_spell_fiscal_year, secondary_procedure_9 procedure_code, secondary_diagnosis_9 diagnosis_code FROM temp_ip UNION ALL SELECT bd.primary_key_column_s, hd_spell_fiscal_year, secondary_procedure_10 procedure_code, secondary_diagnosis_10 diagnosis_code FROM temp_ip UNION ALL SELECT bd.primary_key_column_s, hd_spell_fiscal_year, secondary_procedure_11 procedure_code, secondary_diagnosis_11 diagnosis_code FROM temp_ip SELECT bd.primary_key_column_s, hd_spell_fiscal_year, secondary_procedure_12 procedure_code, secondary_diagnosis_12 diagnosis_code FROM temp_ip ), hd_procedure_hierarchy AS ( SELECT NVL (MAX (a.hierarchy), 0) hd_procedure_hierarchy, a.fiscal_year FROM ref_hd.nhs_opcs_hier a, codes pc WHERE a.fiscal_year = pc.hd_spell_fiscal_year AND a.code = pc.procedure_code GROUP BY a.fiscal_year ),hd_diagnosis_hierarchy AS ( SELECT NVL (MAX (a.hierarchy), 0) hd_diagnosis_hierarchy, a.fiscal_year FROM ref_hd.nhs_icd10_hier a, codes pc WHERE a.fiscal_year = pc.hd_spell_fiscal_year AND a.code = pc.diagnosis_code GROUP BY a.fiscal_year ) SELECT b.*, a.hd_procedure_hierarchy, c.hd_diagnosis_hierarchy FROM analytic_hes.temp_ip b, LEFT OUTER JOIN hd_procedure_hierarchy a ON (a.fiscal_year = b.hd_spell_fiscal_year) LEFT OUTER JOIN hd_diagnosis_hierarchy c ON (c.fiscal_year = b.hd_spell_fiscal_year)
HTH
David
-
What operator (ie the Table operator) to use if I have a subquery as part of my select statement? (As I do works, but is not elegant. What I do is to create a table for the subquery, and join with other sources to point to my goal.) But, would appreciate the best way with the characteristics of OWB.
Here is the entire SQL (including the subquery):
SELECT to_numbe (null), course_id
at. Book, lp.NAME,
(by selecting b.pricing in qp_pricing_attributes b
where b.list_id = ll.list_id and b.product = at.product) sign.
LL. Operand price, lhb.comments
Of
pricing_attribs to,.
He's list_lines,
list_h lp,
Lhb Liste_B
WHERE 1 = 1
and ll.list_line_id = atrib.list_line_id
AND ll.list_header_id = lp.list_header_id
AND lp.list_header_id = lhb.list_header_id
Thank you.Hello
Didn't need to be a table in the target. A very simple example, let's say you wanted to do the following:
Select ename, (select dname dept d where d.deptno = e.deptno) of emp eThen DEPT is the table of your choice and EMP is your table of conduct.
1. Add EMP on the canvas.
2. Add to the search operator
3 link research DEPT
4. tap on finish
5 card EMP. Department at the Dept. INGRP1 (search operator)
6. change the search operator, on tab Lookup Conditions for lookup column DEPTNO and DEPTNO of entry attribute
7. Search full nowYou can add to a table operator target and map of the EMP source table and attributes for release of the search operator. You can change the step 4 to complete the wizard and define the list of choices, but I chose to do 5, to automatically get the names and the data types of the inputs. There are many other options currently in GR 11, 2 in the search.
Hope it makes sense.
See you soon
David -
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?
Maybe you are looking for
-
Satellite Pro M30 harddisc & CD-ROM - it is better to set?
I've had my Toshiba during almost two years now, and that has worked fine until yesterday. First of all something went past that the computer can't find the CD-ROM drive, and then the hard drive started making noice, stronger and stronger until I can
-
I posted this earlier in a thread that was several years old, but received no response, so I thought I would try to create a new thread. Basically, in obtaining my wife, put in place a new Macbook Pro, a series of unlikely mishap led to the loss of m
-
MY MacBook cursor moves and I have very little control over it.
-
I installed the Puzzle of pets on my HP steam 7 tablet. It was working fine yesterday, but today it does not open. I have removed and reinstalled the app, stop the Tablet and still does not work. Everything else on the Tablet works fine.
-
The lid opening rear of the hp Pavilion 23 - f250 all-in-one desktop
Hi TwoPointOh Thank you for let me know the step by step process the opening on the back of the NEW (2013) hp Pavilion 23-f250 Office all-in-one to add ram memory. There are a few online video, but not for 23-f250, is there one for a Jules Destrooper