Please help to write a query to get the result in a different format
The Version of database: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0
Table of scripts create script and data;
CREATE TABLE test ( col1 VARCHAR2 (2), col2 VARCHAR2 (2), col3 VARCHAR2 (2), col4 VARCHAR2 (2), col5 VARCHAR2 (2) ); insert into test values('x','y','','',''); insert into test values('x','','p','',''); insert into test values('x','','q','',''); insert into test values('x','','','t',''); insert into test values('x','','','','s');
select * from test;
COL1 | COL2 | COL3 | COL4 | COL5 |
x | There | |||
x | p | |||
x | q | |||
x | t | |||
x | s |
I need output like below:
COL1 | COL2 | COL3 | COL4 | COL5 |
x | There | p | t | s |
x | q |
Each column is sorted alphabetically.
Thank you
Sam
Hi, Sam,.
Here's one way:
WITH unpivoted_data AS
(
SELECT T.*
ROW_NUMBER () OVER (PARTITION BY col
ORDER BY val
) AS r_num
OF the test
UNPIVOT (val
FOR the collar (col2, col3, col4 col5)
) t
)
SELECT col1, col2, col3, col4, col5 - or SELECT * to display r_num, too
Of unpivoted_data
PIVOT (MIN (val)
FOR col IN ('COL2' AS col2
'COL3' AS col3
'COL4' AS col4
"COL5" AS col5
)
)
ORDER BY col1, r_num
;
This does not imply that all but one of the (col2, col3, col4 col5) will be NULL on line any test.
Tags: Database
Similar Questions
-
I'm looking for only column compare to my same target table as a table source.
My query:
Select case when column_name_s is null and column_name_t is not null
then "alter table GRADE_CONVERSION drop | column_name_t | ';'
When column_name_s is not null and column_name_t is null
then "alter table GRADE_CONVERSION add | column_name_s | ' ' || data_type_s | « ; »
else 'alter table modify GRADE_CONVERSION | column_name_t | ' ' || data_type_t | « ; »
alterations of the end
from (select s.column_name column_name_s, t.column_name column_name_t,
s.data_type data_type_s, t.data_type data_type_t
(select column_name, column_id, data_type
of all_tab_cols@database
where owner = 'erhan.
and table_name = "GRADE_CONVERSION."
+ 1
full outer join
(select column_name, column_id, data_type
of all_tab_cols@database
where owner = 'sarigul.
and table_name = "GRADE_CONVERSION."
+ 6
on s.column_name = t.column_name
)
Tables:
Target table: table GRADE_CONVERSION in sarigul@database
LETTER_GRADE VARCHAR2 (2) GRADE_POINT NUMBER (3.2) MAX_GRADE NUMBER (3) MIN_GRADE NUMBER (3) Table source: Table GRADE_CONVERSION in erhan@database
LETTER_GRADE VARCHAR2 (2) GRADE_POINT NUMBER (3.2) MAX_GRADE NUMBER (3) MIN_GRADE NUMBER (3) CREATED_BY VARCHAR2 (30) CREATED_DATE DATE MODIFIED_BY VARCHAR2 (30) MODIFIED_DATE DATE want to see output that is similar to this * (please ignore the names of column here it's just a clear example :))
ALTER table Target_table change BOOK_ID Varchar2 (4);
ALTER table Target_table I addSBN_10 Varchar2(13), null;
ALTER table drop TITLE Target_table;
Erhan_toronto wrote:
1.I used src.nullable src_nullable and tgt.nullable tgt_nullable but only show Yes as below: but want to see the result as not null or null
ALTER table TEST_TARGET change the NUMBER of MAX_GRADE (3, 2) Yes
Ok. So it's all about the Yes and the no decoding to Default Null or Not Null, isn't it?
So, to test, change one of the table of sample for NOT NULL columns in the source table, and then run the following query:
with src as ( select src.table_name src_table_name, src.column_name src_col_name, src.data_type src_data_type, src.data_length src_data_len, src.data_precision src_data_precision, src.data_scale src_data_scale, src.nullable src_nullable from user_tab_columns src where table_name = 'TEST_SOURCE' ), tgt as ( select tgt.table_name tgt_table_name, tgt.column_name tgt_col_name, tgt.data_type tgt_data_type, tgt.data_length tgt_data_len, tgt.data_precision tgt_data_precision, tgt.data_scale tgt_data_scale, tgt.nullable tgt_nullable from user_tab_columns tgt where table_name = 'TEST_TARGET' ), col_details as ( select src.src_table_name, nvl(tgt.tgt_table_name, first_value(tgt_table_name) over(order by tgt_table_name nulls last)) tgt_table_name, src.src_col_name, src.src_data_type, src.src_data_len, src.src_data_precision, src.src_data_scale, src.src_nullable, tgt.tgt_col_name, tgt.tgt_data_type, tgt.tgt_data_len, tgt.tgt_data_precision, tgt.tgt_data_scale, tgt.tgt_nullable from src left outer join tgt on ( src.src_col_name = tgt.tgt_col_name ) ) select * from ( select case when tgt_data_type != src_data_type or tgt_data_len != src_data_len or tgt_data_precision != src_data_precision or tgt_data_scale != src_data_scale or src_nullable != tgt_nullable then 'alter table ' || tgt_table_name || ' modify ' || tgt_col_name || ' ' || src_data_type || ' (' || case when src_data_type in ('DATE') then null else case when src_data_type in ('VARCHAR', 'VARCHAR2') then nvl(to_char(src_data_len), ' ') || ') ' else decode(nvl(src_data_precision, -1), -1, null, nvl(to_char(src_data_precision), ' ') || ', ' || nvl(to_char(src_data_scale), ' ') || ')') end end || decode(src_nullable, 'NO', ' NOT NULL', ' DEFAULT NULL') when tgt_col_name is null then 'alter table ' || tgt_table_name || ' add ' || src_col_name || ' ' || src_data_type || case when src_data_type in ('DATE') then null else case when src_data_type in ('VARCHAR', 'VARCHAR2') then nvl(to_char(src_data_len), ' ') || ') ' else decode(nvl(src_data_precision, -1), -1, null, nvl(to_char(src_data_precision), ' ') || ', ' || nvl(to_char(src_data_scale), ' ') || ')') end end || decode(src_nullable, 'NO', ' NOT NULL', ' DEFAULT NULL') end alter_statement from col_details ) where alter_statement is not null;
Erhan_toronto wrote:
2. when I run below under user sarigul and erhan I get the result as OWNER, TABLE_NAME, COLUMN_NAME DATA_TYPE... I have a link between two users. They have access to two tables.
- Select * from all_tab_columns
where owner = 'erhan' and table_name = "TEST_SOURCE."
- Select * from all_tab_columns
where owner = 'sarigul' and table_name = "TEST_TARGET."
Alright. This means that you both users are on the same database. Only change, you will have to do in the above query is so change user_tab_columns to all_tab_columns and add the OWNER predicate respectively with the clause.
-
Need for SQL query to get the result.
Region
Month Trx type Summary of the resolution AMERICAS -13 may Adjustments Fix EMEA -13 may Adjustments Incorrect AMERICAS -13 may Credit memo Incorrect EMEA -13 may Invoice Fix AMERICAS -13 may Credit memo Fix OFD -13 may Adjustments Fix AMERICAS -13 may Invoice Incorrect DVL -13 may Adjustments Fix DVL -13 may Adjustments Fix OFD -13 may Adjustments Fix Above my Table and here is the result required. Similarly for other regions as well. Can someone help me with the SQL query?
Region Summary of the resolution Setting Credit memo Invoice Total general AMERICAS Fix 1 1 2 Incorrect 0 1 1 2 Like this?
SQL > select * from transaction_audit;
MTH TRX_TYPE REGION BOARD
-------- ------ ----------- ---------
AMERICAS-13 may SETTINGS CORRECT
EMEA-13 may INCORRECT ADJUSTMENT
AMERICAS-13 may CREDIT MEMO INCORRECT
EMEA-13 may INVOICE CORRECT
AMERICAS-13 may CREDIT MEMO CORRECT
OFD-13 may SETTINGS CORRECT
AMERICAS-13 may INVOICE INCORRECTE
LAD-13 may SETTINGS CORRECT
LAD-13 may SETTINGS CORRECT
OFD-13 may SETTINGS CORRECT10 selected lines.
SQL > select region
2, resolution_summary
3, count (decode (trx_type, "ADJUSTMENTS", trx_type)) adjustments
4, County (decode (trx_type, 'HAVING', trx_type)) credit_memo
5, County (decode (trx_type, "BILL", trx_type)) Bill
transaction_audit 6
Group 7
8 by region
9, resolution_summary
10 Decree
11 by region
12, resolution_summary
13.REGION TAKE ADJUSTMENTS CREDIT_MEMO INVOICE
-------- --------- ----------- ----------- ----------
CORRECT THE AMERICAS 1 1 0
0 1 1 INCORRECT AMERICAS
EMEA CORRECT 0 0 1
INCORRECT EMEA 1 0 0
DAL ADDRESS 2 0 0
OFD CORRECT 2 0 06 selected lines.
SQL >
-
I have a table called claims and I want to know the lines that have the same application id and members
with cert = 'MEMBER' and insert the date exceeds the other rows in the same claim and Member ID.
Help, please.Eg: Insert date claim member Id cert 7/17/2009 2009106 1345678 1345678 8/8/2009 2009106 1345678 MEMBER 12/11/2009 2009107 1345679 MEMBER 12/14/2009 2009107 1345679 1345679 Expected row: 7/17/2009 2009106 1345678 1345678 8/8/2009 2009106 1345678 MEMBER
Hello
Here's a way to do it:
SELECT * FROM table_x WHERE (claim, member_id) IN ( SELECT claim , member_id FROM table_x GROUP BY claim , member_id HAVING MAX (insert_date) = MAX ( CASE WHEN cert = 'MEMBER' THEN insert_date END ) AND COUNT (*) > 1 -- Unclear if you want this ) ;
If you want to post CREATE TABLE and INSERT for some samples statements, then I could test this.
If the combination (claim, member_id, insert_date) is not unique, this will include groups where a row of 'MEMBER' links with no 'MEMBER' for the latest insert_date lines. If links are possible, but you only want to groups where the last row is a 'MEMBER', then you'll need another expression BOX.
-
How to operate the user enter value query and get the result on the text element
Hello
I'm really beginning to JDeveloper and ADF, I want to execute the query below, before with forms, I just add: TEXT_NAME to enhance the users entries, what should I do now with ADF, really unclear question and I would be grateful all help with that.
Select
NVL (min (substr (a.StartTime, 1, 8)), 0) Service_Start_Time, nvl (sum (a.sessionvolume), 0) Total_Traffic_KB
Of
aaa_bill one
where
msid =: TEXT_ITEM
and starttime > = (select max (fee) FROM aaa_bill
where msid =: TEXT_ITEM and accountreason = 5);You can use a form of parameter ADF for this requirement.
https://blogs.Oracle.com/Shay/entry/combining_multiple_queries_and -
Please help me write this SQL query...
Thanks in advanceHi everyone, Please help me in this query. A patient can multiple types of Adresses (types P,M,D).If they have all the 3 types i need to select type: p and if they have (M and D) i need to select type M,and if they have only type D i have to select that. For each address i need to validate whether that particular address is valid or not (by start date and end date and valid flag) Patient table ============= Patient_id First_name last_name 1 sanjay kumar 2 ajay singh 3 Mike John Adress table ============ address_id patient_id adresss city type startdate enddate valid_flg 1 1 6222 dsadsa P 01/01/2007 01/01/2010 2 1 63333 dsad M 01/02/2006 01/01/2007 N 3 1 64564 fdf M 01/01/2008 07/01/2009 4 1 654757 fsdfsa D 01/02/2008 09/10/2009 5 2 fsdfsd fsdfsd M 01/03/2007 09/10/2009 6 2 jhkjk dsad D 01/01/2007 10/10/2010 7 3 asfd sfds D 01/02/2008 10/10/2009 output ===== 1 sanjay kumar 6222 dsadsa P 01/01/2007 01/01/2010 2 ajay singh fsdfsd fsdfsd M 01/03/2007 09/10/2009 3 mike john asfd sfds D 01/02/2008 10/10/2009
PhaniHello, Fabienne,.
This race for you (twisted code of Sarma):
SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate FROM ( SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate, ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1 WHEN 'M' THEN 2 WHEN 'D' THEN 3 END) rn FROM patient p JOIN address a ON (p.patient_id = a.patient_id ) WHERE NVL(valid_flg, 'X') != 'N' AND SYSDATE BETWEEN startdate AND NVL(enddate, SYSDATE) ) WHERE rn = 1;
Edit, currently in the trial:
With Patient AS ( SELECT 1 Patient_id , 'sanjay' First_name, 'kumar' last_name FROM DUAL UNION ALL SELECT 2, 'ajay', 'singh' FROM DUAL UNION ALL SELECT 3, 'Mike', 'John' FROM DUAL), Address AS ( SELECT 1 address_id, 1 patient_id, '6222' address, 'dsadsa' city, 'P' type, to_date('01/01/2007', 'DD/MM/YYYY') startdate, to_date('01/01/2010', 'DD/MM/YYYY') enddate, NULL valid_flg FROM DUAL UNION ALL SELECT 2,1,'63333','dsad','M', to_date('01/02/2006', 'DD/MM/YYYY'), to_date('01/01/2007', 'DD/MM/YYYY'), ' N' FROM DUAL UNION ALL SELECT 3,1,'64564','fdf','M', to_date('01/01/2008', 'DD/MM/YYYY'), to_date('07/01/2009', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 4,1,'654757','fsdfsa','D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 5,2,'fsdfsd ','fsdfsd','M', to_date('01/03/2007', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 6,2,' jhkjk','dsad','D', to_date('01/01/2007', 'DD/MM/YYYY'), to_date('10/10/2010', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 7,3,'asfd',' sfds',' D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('10/10/2009', 'DD/MM/YYYY'), NULL FROM DUAL) -- end test data SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate FROM ( SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate, ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1 WHEN 'M' THEN 2 WHEN 'D' THEN 3 END) rn FROM patient p JOIN address a ON (p.patient_id = a.patient_id ) WHERE NVL(valid_flg, 'X') != 'N' AND SYSDATE BETWEEN startdate AND NVL(enddate, SYSDATE) ) WHERE rn = 1; PATIENT_ID FIRST_ LAST_ ADDRESS CITY TY STARTDATE ENDDATE ---------- ------ ----- ------- ------ -- --------- --------- 1 sanjay kumar 6222 dsadsa P 01-JAN-07 01-JAN-10 2 ajay singh fsdfsd fsdfsd M 01-MAR-07 09-OCT-09 3 Mike John asfd sfds D 01-FEB-08 10-OCT-09
-
How to write a simple select query to get the data of the table as an XML.
How to write a simple select query to get the data of the table as an XML. In the query, I'm just adding items below which i need be there in the XML document
I have need to add the root tag as well in the beginning and the end of < root > < / root > this xml file. Please advice if this is possible with the select queryselect '<test_tag>'||EMP_NAME||'</test_tag>','<date>'||sysdate||'</date>' from temp_table where id_num BETWEEN 1 AND 10;
without using XMLGEN, XMLQUERY or any other packages built and function?I need to URL escapes with the UTF-8 code points that we have already achieved using the utl_http package. Please help how to do that without using the utl_http package.
What is wrong with him?
At present, the only way I can think of to avoid a call to UTL_HTTP. SET_BODY_CHARSET is to write your own little wrapper.
In this way, you can specify the Boolean parameter or omit it if you choose to use named parameters:SQL> create or replace function my_url_escape (url in varchar2) 2 return varchar2 3 deterministic 4 is 5 begin 6 return utl_url.escape(url, false, 'AL32UTF8'); 7 end; 8 / Function created SQL> select my_url_escape('http://some.uri.com/param?lang=fr&text=contrôle') from dual; MY_URL_ESCAPE('HTTP://SOME.URI -------------------------------------------------------------------------------- http://some.uri.com/param?lang=fr&text=contr%C3%B4le
-
Hello
Please help build a sql query
My Table Test2015 has given belowHeader_id Line_id Ordered_item
723887290 199925 MAIN1
199925 723887291 MAIN2
199926 723887292 SH-POS-NO-BR POS-INS
199926 723887293 MAIN2
199927 723887294 IC-ENV-NON-BR-ENV-PXY
199927 723887295 MAIN1
199927 723887297 MAIN2
199927 723887298 PRCSS SH-FAIRY-ELEC DISTR.
199927 723887299 SH-FAIRY-SUM PRO-DE-CONS-HOUSE
I am trying to query my Test2015 table to obtain the records with ordered_item containing 'MAIN1' and 'MAIN2' only. I tried to write a query as below
SELECT * FROM test2015 WHERE ORDERED_ITEM in ('MAIN1', 'MAIN2');
But it gives me all the data with the MAIN2 records found but MAIN1 is absent, I want to retrieve only records to both 'MAIN1' and 'MAIN2' present for Header_id.
While the result below shows me header_id - 199926 and 199929 that he should assume back. I want to fetch documents only with 'MAIN1' and 'MAIN2' both present.
Header_id Line_id Ordered_item
723887290 199925 MAIN1
199925 723887291 MAIN2
199926 723887293 MAIN2
199927 723887295 MAIN1
199927 723887297 MAIN2
199929 723887299 MAIN1
Please suggest.
Thank you and best regards,
Prasad.
Hello
Try like this...
SELECT * FROM test2015 WHERE ORDERED_ITEM in ('MAIN1") and in header_id (select test2015 WHERE ORDERED_ITEM in ('MAIN2') header_id)
-
I'm new in indesign scripting, please tell me how to write a script to get the contents of an XML element and then sort all the content
Hello
Can the code below is useful for you, but I do not know how to sort.
Change the tag based on your employment application.
-
Analysis of query and get the list of used tables
Hi all
I need to parse the sql query (simple & complex as well) and for a list of the tables used in the query.
And need to validate the fact that list the tables against a whitelist that is kept in the file.
I tried to write my own parser, because there are many ways to write complex queries, I'm unable to cover all scenarios.
I need help, is there other ways to get the list of tables used in a query?
Thank you
Manon...
In general you would add a condition 1 = 2 just to restrict the display of the entire table. Then should not be causing any noticeable performance degradation. You can even use ROWNUM< 2.="" that="" will="" do="" a="" count="" stopkey.="" which="" could="" be="">
SQL > select * from emp where rownum<>
no selected line
SQL > select * from table (dbms_xplan.display_cursor);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID, 97f4bd002xfy0, number of children 0
-------------------------------------
Select * from emp where rownum<>Hash value of plan: 4269703525
---------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 2 (100) | |
|* 1 | COUNT STOPKEY | | | | | |
| 2. TABLE ACCESS FULL | EMP | 1. 38. 2 (0) | 00:00:01 |
---------------------------------------------------------------------------Information of predicates (identified by the operation identity card):
---------------------------------------------------1 Filter (ROWNUM<>
19 selected lines.
But its always good to bench mark it yourself.
-
What could be the query to get the amount to spend on a product name in EBS?
Hi Experts,
I need help to write a query in EBS for the amount to be spent for any given product name and category of high-level (Segment1).
It may be a different query two or one only. Please answer if someone knows how to do. I need for the objective test.
Thanks in advance.All good Chassey here.
You can try the SQL below.
MSIB.Description, mcb.segment1, SUM(pla.quantity*pla.unit_price) SELECT total_spend
Of
po_lines_all pla,
mtl_categories_b mcb,
mtl_system_items_b msib
WHERE pla.category_id = mcb.category_id
AND pla.item_id = msib.inventory_item_id
AND msib.organization_id =
GROUP BY msib.description, mcb.segment1If you do not use the PO_LINES_ALL, is there any other source you plan to use for spending.
MCB.segment1, SUM(pla.quantity*pla.unit_price) SELECT total_spend
Of
po_lines_all pla,
mtl_categories_b BCP
WHERE pla.category_id = mcb.category_id
GROUP BY mcb.segment1and did not no need to table po_lines_all. I do between OBIEE reports and data of EBS test validation. In the report I keep only the name of the product and the amount to be spent to make it simple. Now, I need to verify that the values are the same in the report and the EBS. That's the criteria.
Thank you
Nathalie -
Taking a lot of time to get the result of the query
Hi all
The query below takes a long time for results
select vs.task_name, count(*) fallout_count from provco.view_stage_history vs where record_type in ('TASK') and task_name like 'Op-%' and vs.line_of_business = 'OPTIONLESS' -- and vs.task_due_date > ((sysdate - 146)) and vs.task_due_date is not null -- and vs.order_due_date > ((sysdate - 146)) and vs.order_due_date is not null and vs.fallout_date > ((sysdate - 146)) and vs.fallout_date is not null -- and vs.assignment_date > ((sysdate - 146)) and vs.assignment_date is not null -- and upper(vs.install_country_code) like 'US%' and vs.ban is not null -- and vs.task_name not in ('ASR-Assignment', 'SOR-Assignment') group by vs.task_name order by fallout_count desc;
Its takes an hour to get the result. You will find the description of the table and the index below
CREATE TABLE "PROVCO"."VIEW_STAGE_HISTORY" ( "TASK_ID" NUMBER NOT NULL ENABLE, "ASSIGNMENT_DATE" TIMESTAMP (6) NOT NULL ENABLE, "LINE_OF_BUSINESS" VARCHAR2(30 BYTE) NOT NULL ENABLE, "ORDER_ID" NUMBER NOT NULL ENABLE, "ORDER_NUMBER" VARCHAR2(128 BYTE) NOT NULL ENABLE, "ORDER_VERSION" VARCHAR2(15 BYTE) NOT NULL ENABLE, "ORDER_TYPE" VARCHAR2(25 BYTE), "TASK_NAME" VARCHAR2(60 BYTE) NOT NULL ENABLE, "FALLOUT_DATE" TIMESTAMP (6), "JEOP_CODE" VARCHAR2(64 BYTE), "ERROR_CODE" VARCHAR2(64 BYTE), "ERROR_DESC" VARCHAR2(1000 BYTE), "WORKGROUP" VARCHAR2(30 BYTE), "WORKPOOL" VARCHAR2(50 BYTE), "USER_ID" VARCHAR2(32 BYTE), "RECORD_TYPE" VARCHAR2(40 BYTE) NOT NULL ENABLE, "ASSIGNMENT_TYPE" VARCHAR2(40 BYTE), "ORDER_DUE_DATE" TIMESTAMP (6), "COMMIT_DATE" TIMESTAMP (6), "TASK_DUE_DATE" TIMESTAMP (6), "SEED" VARCHAR2(255 BYTE), "BAN" VARCHAR2(100 BYTE), "ORDER_STATUS" VARCHAR2(64 BYTE), "PROJECT_ID" VARCHAR2(20 BYTE), "CUSTOMER_NAME" VARCHAR2(128 BYTE), "CIRCUIT_ID" VARCHAR2(53 BYTE), "SENSITIVITY_LVL" VARCHAR2(10 BYTE), "BANDWIDTH" VARCHAR2(8 BYTE), "WORK_STEP" NUMBER, "MARKETING_APPROVAL_DATE" TIMESTAMP (6), "INSERTED" TIMESTAMP (6), "UPDATED" TIMESTAMP (6), "INSTALL_COUNTRY_CODE" VARCHAR2(3 BYTE), "SOLD_COUNTRY_CODE" VARCHAR2(3 BYTE), "UPSTREAM_ORDER_NUMBER" VARCHAR2(15 BYTE), "SAR_ID" VARCHAR2(15 BYTE), "DUE_DATE_TYPE" VARCHAR2(4 BYTE), "HOTCUT_IND" VARCHAR2(3 BYTE), "MARKET_SEGMENT" VARCHAR2(50 BYTE), "CNTL_TERM" VARCHAR2(25 BYTE), "SVC_ORD_TYPE" VARCHAR2(40 BYTE), "BLENDED_IND" VARCHAR2(1 BYTE), "RELATED_ORDERS" VARCHAR2(100 BYTE), "TERM_ID" VARCHAR2(20 BYTE), "SUB_SVC_ORD_TYPE" VARCHAR2(40 BYTE), "LAST_TASK_NAME" VARCHAR2(40 BYTE), "PRE_OA_STATUS" VARCHAR2(40 BYTE), "TSP_CODE" VARCHAR2(12 BYTE), "ORDER_CATEGORY" NUMBER, "CHANGE_CATEGORY" NUMBER, "COUNTRY_CODE" VARCHAR2(2 BYTE), "RESELLER_ID" VARCHAR2(19 BYTE), "STATUS_CODE" VARCHAR2(32 BYTE), "STATUS_CATEGORY" VARCHAR2(32 BYTE), "PROVISIONING_LOCATION" VARCHAR2(32 BYTE), "INSTALLED_LOCATION" VARCHAR2(32 BYTE), "DATE_ORDERED" TIMESTAMP (6), "CUSTOMER_NAME_ABBR" VARCHAR2(8 BYTE), "CPE_IND" VARCHAR2(1 BYTE), "CUSTOMER_PON" VARCHAR2(20 BYTE), "PRODUCT_ID" VARCHAR2(20 BYTE), "ASR_PON" VARCHAR2(16 BYTE), "ASR_PON_VER" VARCHAR2(3 BYTE), "ASR_TYPE" VARCHAR2(3 BYTE), "ASR_TRAN_TYPE" VARCHAR2(1 BYTE), "PARTNER_CARRIER_ID" VARCHAR2(8 BYTE), "PREMISE_SEQUENCE_NUMBER" VARCHAR2(3 BYTE), "EXPEDITE_IND" VARCHAR2(6 BYTE), "ORDER_SOURCE" VARCHAR2(40 BYTE), "SERVICE_REQ_ID" VARCHAR2(40 BYTE), "SUB_ORDER_VALUE" VARCHAR2(50 BYTE), "SUB_ORDER_TYPE" VARCHAR2(15 BYTE), "PROV_OWNER" VARCHAR2(32 BYTE), "TASC_OWNER" VARCHAR2(32 BYTE), "DM_OWNER" VARCHAR2(32 BYTE), "ORDNBR_TYPE" VARCHAR2(128 BYTE), "WORK_ID" NUMBER, "GARM_TYPE" VARCHAR2(50 BYTE), "USER_TASK_DUE_DATE" TIMESTAMP (6), CONSTRAINT "VIEW_STAGE_HISTORY_PKY" PRIMARY KEY ("TASK_ID", "ASSIGNMENT_DATE") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 131072 NEXT 131072 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "TBS_PROVCO_IDX" ENABLE, SUPPLEMENTAL LOG GROUP "GGS_211360" ("TASK_ID", "ASSIGNMENT_DATE") ALWAYS ) SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 524288 NEXT 524288 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "TBS_PROVCO_DAT" ; CREATE INDEX "PROVCO"."VIEW_STAGE_HISTORY_IDX5" ON "PROVCO"."VIEW_STAGE_HISTORY" ("ORDER_NUMBER", "TASK_NAME") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 131072 NEXT 131072 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "TBS_PROVCO_IDX" ; CREATE INDEX "PROVCO"."VSH_INSERTED_IDX" ON "PROVCO"."VIEW_STAGE_HISTORY" ("INSERTED") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 131072 NEXT 131072 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "TBS_PROVCO_IDX" ; CREATE INDEX "PROVCO"."VSH_LOB_OT_ON_IDX" ON "PROVCO"."VIEW_STAGE_HISTORY" ("LINE_OF_BUSINESS", "ORDER_TYPE", "ORDER_NUMBER") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 131072 NEXT 131072 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "TBS_PROVCO_IDX" ; CREATE INDEX "PROVCO"."VSH_LOB_TN_IDX" ON "PROVCO"."VIEW_STAGE_HISTORY" ("LINE_OF_BUSINESS", "TASK_NAME") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 131072 NEXT 131072 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "TBS_PROVCO_IDX" ;
Explain the plan of the query is
SQL> explain plan for 2 select vs.task_name, count(*) fallout_count from provco.view_stage_history vs where record_type in ('TASK') 3 4 and task_name like 'Op-%' 5 and vs.line_of_business = 'OPTIONLESS' 6 -- and vs.task_due_date > ((sysdate - 146)) and vs.task_due_date is not null 7 -- and vs.order_due_date > ((sysdate - 146)) and vs.order_due_date is not null 8 and vs.fallout_date > ((sysdate - 146)) and vs.fallout_date is not null 9 -- and vs.assignment_date > ((sysdate - 146)) and vs.assignment_date is not null 10 -- and upper(vs.install_country_code) like 'US%' 11 and vs.ban is not null -- and vs.task_name not in ('ASR-Assignment', 'SOR-Assignment') 12 13 group by vs.task_name order by fallout_count desc; Explained. SQL> select plan_table_output from table(dbms_xplan.display('plan_table',null,'typical cost bytes')); PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Plan hash value: 3788003769 ------------------------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 191 | 10505 | | 136K (1)| 00:27:24 | | 1 | SORT ORDER BY | | 191 | 10505 | 1536K| 136K (1)| 00:27:24 | | 2 | SORT GROUP BY NOSORT | | 191 | 10505 | | 136K (1)| 00:27:24 | |* 3 | TABLE ACCESS BY INDEX ROWID| VIEW_STAGE_HISTORY | 21528 | 1156K| | 136K (1)| 00:27:21 | |* 4 | INDEX RANGE SCAN | VSH_LOB_TN_IDX | 229K| | | 1474 (1)| 00:00:18 | ------------------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter("VS"."BAN" IS NOT NULL AND "RECORD_TYPE"='TASK' AND "VS"."FALLOUT_DATE">SYSDATE@!-146) 4 - access("VS"."LINE_OF_BUSINESS"='OPTIONLESS' AND "TASK_NAME" LIKE 'Op-%') filter("TASK_NAME" LIKE 'Op-%') 18 rows selected.
the view_stage_history table has 19504509
Please let me know somehow that we can speed up the query above.
Thank you
Mani
How much time does it take if you suggest a full table scan?
-
Query to get the numbers and percent by date range
11g version.
Hello
I have the following data in the format
I want to get all the charges and % of all users who have accepted_flag the value n. basically, users who have not yet accepted in the format of Opty_id.Opty_Id creation_date user accepted_flag 1 01-mar-2013 ryan N 2 02-mar-2013 sam Y 3 02-mar-2013 ryan Y . . .
The column of aging is creation_date, basically, how much body id, were created between now and 20 days, 21-40 and 41-60 days and have not yet accepted (accept the flag = N)ageing count Percentage 0-20 days 1 10%(this will offcourse depend on the total number of opty id and then out of that how many did not accept within the given period. 21-40 days 0 0% 41-60 days 0 0%
Any help please.
Thank you
RyanI get other results
with t as (select 1 as opty_id, to_date('01/03/2013','DD/MM/YYYY') as date_created, 'ryan' as auser, 'N' as accepted_flag from dual union all select 2, to_date('02/03/2013','DD/MM/YYYY'), 'sun', 'Y' from dual union all select 3, to_date('03/02/2013','DD/MM/YYYY'), 'sun', 'Y' from dual union all select 4, to_date('02/01/2013','DD/MM/YYYY'), 'ryan', 'N' from dual union all select 5, to_date('03/01/2013','DD/MM/YYYY'), 'tom', 'Y' from dual) select decode(grp,1,0,grp*20-19) ||'-'|| grp*20 ageing ,sum(case accepted_flag when 'N' then 1 else 0 end) count ,sum(case accepted_flag when 'N' then 1 else 0 end) /sum(sum(case accepted_flag when 'N' then 1 else 0 end)) over () Percentage from (select ceil(decode((trunc(sysdate) - date_created),0,1,trunc(sysdate) - date_created)/20) grp ,date_created ,accepted_flag from t ) group by grp AGEING COUNT PERCENTAGE "0-20" "1" "0,5" "21-40" "0" "0" "41-60" "0" "0" "61-80" "1" "0,5"
Published by: chris227 on 04.03.2013 03:41
Modified according to response below -
query to get the maximum integer value of varchar columns
I have the following values in the column of type Varchar.
USR_LOGIN (VARCHAR2)
-----------------------------
50
52
53
55
57
123
111
145
XELSYSADM
TESTUSER
USER123
12TESTUSER
But I need to get the result as 145.
Can you help me with the sql query?Maybe it's
SQL> with t as ( select '50' usr_login from dual union all select '52' from dual union all select '53' from dual union all select '55' from dual union all select '57' from dual union all select '123' from dual union all select '111' from dual union all select '145' from dual union all select 'XELSYSADM' from dual union all select 'TESTUSER' from dual union all select 'USER123' from dual union all select '12TESTUSER' from dual ) -- -- select max(to_number(regexp_substr(usr_login, '\d+'))) usr_login from t / USR_LOGIN --------------- 145 1 row selected.
-
SQL query to get the NULL records after the last matching flag
I have a xx1 table with id and flag columns. So I want the data in this table, after the last flag matched. I want that data to id 7 in the rooms. Even if the id 2,3,5 are null flag 'Y' was at 6. ID so I need a query to get the data of the xx1 table after the last correspondence flag (from 7 to 9 id).
SQL > create table xx1
2 (identification number,
3 flag varchar2 (10));
Table created.
SQL > insert into xx1 values (1, 'Y');
1 line of creation.
SQL > insert into values xx1 (2, null);
1 line of creation.
SQL > insert into values xx1 (3, null);
1 line of creation.
SQL > insert into xx1 values (4, 'Y');
1 line of creation.
SQL > insert into values xx1 (5, null);
1 line of creation.
SQL > insert into xx1 values (6, 'Y');
1 line of creation.
SQL > insert into values xx1 (7, null);
1 line of creation.
SQL > insert into values xx1 (8, null);
1 line of creation.
SQL > insert into values xx1 (9, null);
1 line of creation.
SQL > select * from xx1.
FLAG OF THE ID
---------- ----------
1. IS
2
3
4. IS
5
6. IS
7
8
9
9 selected lines.
SQL >
Hello
user11164339 wrote:
Hi Frank - when I run the query, I don't see the results data.
I get
FLAG OF THE ID
----- ----------
7
8
9
What you do differently?
Maybe you are looking for
-
How to install Mozilla if I installed Windows7 Ultimate?
I can't install the browser I think ' couse now I installed Windws 7 Ultimate. When I try you RUN Mozilla kit is apear that I owe to loggin as an administrator with my password. but I do have an account like this, and for that, of course, I can not i
-
Write to the spreadsheet does not work
I compare a string that I enter in a text box, a string a .csv. If the string is found, the data is written to a file, but if the string is not found, other data should be written to another file, but nothing happens. I used the copy of the code that
-
How can I restore my system to factory settings, after replacing the hard drive?
Original title: I have a hard nine; how I can start or put in the back of the recovery disc to my old sistem all gane I need help to start the recovery disc, in all new hard drive, in order to restore my system whole back
-
BlackBerry smartphones remove shortcut
By mistake I deleted my SMS shortcut. I looked through all records have thus shown the hidden shortcuts & go. Any suggestions on how to create or take this shortcut? Thank you
-
Ability to connect to the web interface of C20 by using its IP address as password
Good afternoon One of our customers is trying all their C20 upgrade to version TC5.1.5 and have just accidentally managed to connect the console to web administration using the IP address of units such as password. Set the password also works! They h