(Editable report) SQL query with line selector
I used this code to get the update of the records in a query SQL (editable report).Updates a value in a selection box.
because me in 1... apex_application.g_f01. Count
loop
UPDATE CONTRACTS
SET LOAD_FLAG =: P8_SELECT
WHERE ID = apex_application.g_f01 (i); -i'the checked the file 'primary key '.
end loop;
Here's my dilemma.
Line selector seems to be in a fixed position.
By linking the line for identification number selector (1, 2, 3, etc.)
Sort by ID (1, 2, 3, etc.)
If it is sorted by another field with say ID 29 now in the 1st row, by checking the box and update, you update ID #1 located elsewhere on the page.It works perfectly, as long as the ID is sorted in order. < <
Any ideas how to make the line selector literally equal to the line, it is displayed in?
Thank you
Bob
I think I have an idea of what is wrong and, eventually, how to fix it. Try this:
make your field primary key (NO ROWID!) in a column in a table column, either through the "wizard" (i.e. through the report attributes screen), or using the APEX_ITEM api (as described by Vee). I often have my primary key as a hidden; If you really need to see it, you can use "DISPLAY_AND_SAVE".
So if your primary key 'ID' colum is now in the 2nd table as a table (i.e. f02 - adjust accordingly!), your PL/SQL process should look like this:
for i in 1 .. apex_application.g_f01.count
loop
UPDATE CONTRACTS
SET LOAD_FLAG = :P8_SELECT
where ID = apex_application.g_f02(apex_application.g_f01(i));
end loop;
It of a little confusing at first but it it makes sense when you train how tabular tables work with check boxes. The length of this array represents only what is verified - so if you have 3 values checked, the cardinality of the table in a particular table 3. On the other hand, your other tabular berries (containing the 'normal' values) has a cardinality of the count of all the visible lines.
In this case, the record selector (F01) contains the ID of the relevant line in your report - so passing this value in the array index 2 (F02) should give you the correct primary key for that particular line value. If you subsequently order the report by another field, it should work again.
I should add that Vee method will work well - the difference is that, instead of organizing the rowid, f01 contains the actual key value. Hope this helps
Published by: Joel_C on March 21, 2011 11:50
Tags: Database
Similar Questions
-
Report of update SQL query with line selector. Update process.
I have a report of update SQL query with the selectors in line.
How to identify line selector in a process update on the page.
I want to update some columns with a value of an area of selection on the page.
With the help of the base:
UPDATE table_name
SET Column1 = value
WHERE some_column = some_value
I would need to do:
UPDATE table_name
SET column1 =: P1_select
WHERE [line selector] =?
Now sure how to identify [line selector] and/or validate it is checked.
Thank you
BobIdentify the name of the checkbox of the source of the page element, it should be of the fxx format (f01, f02... f50).
Suppose that we f01.for i in 1 .. apex_application.g_f01.count loop UPDATE CONTRACTS SET SIP_LOAD_FLAG = :P16_STATUS where
= apex_application.g_f01(i); --i'th checked record' primary key end loop; -
Write a SQL query with lines in columns
All the
I need help in writing a SQL query with lines in columns, let give u an example...
drop table activity;
CREATE TABLE 'ACTIVITY '.
(
"PROJECT_WID" NUMBER (22.0) NOT NULL,
VARCHAR2 (150 CHAR) "PROJECT_NO."
VARCHAR2 (800 CHAR) 'NAME '.
);
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1683691, '10007', 12-121');
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1684994, '10008', 12-122');
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1686296, '10009', 12-123');
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (2225222, '9040', 12-124');
drop table lonet;
CREATE TABLE 'LONET.
(
VARCHAR2 (150 CHAR) "NAME."
NUMBER OF THE "ROOT."
VARCHAR2 (150 CHAR) "ENTRYVALUE".
);
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1683691, "LDE");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1683691, 'LME');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1683691, 'ICE');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1683691, 'IKE');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1686291, "QTY");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1686291, 'MAX');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1684994, "MTE");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1684994, 'MAC');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMT', 1684994, 'NICE');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMR', 1684994, 'RAY');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1686296, "CAQ");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("PAP", 1686296, "QAQ");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("VANESSA", 1686296, "THEW");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("ANDR", 1686296, "REYL");
commit;
Link: activity.project_wid = lonet.root
look like output
Project_wid Project_no NAME GAC NAM BAG RAC 1683691 10007 12-121 LDE LME LCE LKE 1684994 10008 12-122 MTE null null MAC 1686296 10009 12-123 null null CAQ QAQ 2225222 9040 12-124 null null null null two problems, in that I am running
1. I dono how simply we can convert rows to columns
2. for root = 1683691, there are double NAM and RAC in lonet table... ideally these data should not be there, but since its here, we can take a MAX so that it returns a value
3. There are undesirables who should be ignored
Once again my thought process is that we join the activity and 4 alias table lonet.
ask for your help in this
Thank you
Hello
This is called pivoting.
Here's a way to do it:
WITH relevant_data AS
(
SELECT a.project_wid, a.project_no, b.SID
, l.name AS lonet_name, l.entryvalue
Activity one
LEFT OUTER JOIN lonet l.root = a.project_wid l
)
SELECT *.
OF relevant_data
PIVOT (MAX (entryvalue)
FOR lonet_name IN ("GAC" IN the gac
"NAM" AS nam
'BAG' IN the bag
"RAC" AS cars
)
)
ORDER BY project_wid
;
Output:
PROJECT_WID PROJECT_NO GAC NAM BAG RAC NAME
----------- ---------- ---------- ---------- ---------- ---------- ----------
1683691 12 - 10007 121 LDE LME LCE LKE
1684994 MAC MTE 10008 12-122
1686296 12 - 10009 123 QAC QAQ
2225222 9040 12 - 124
To learn more about swivel, see the FAQ in the Forum: Re: 4. How can I convert rows to columns?
Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!
-
(Updated report) SQL query
Is it possible to convert an existing SQL query report area to an "application SQL (editable report)? If not, where should we do to create a SQL (editable report) region?I had the same problem.
The way I ended up converting my sql to a (editable report) SQL query was:
Create a new page with the type of form and tabular presentation, run through all the steps required Wizard.
Once done, you can go back and modify the report and paste in your original sql code.
Worked for me.
It will be useful.
Jen
Published by: munsej on August 7, 2009 08:42
-
More than 1 SQL query with checkbox and error invalid number report
Hi all
I have two SQL query reports that each has an apex_item.checkbox and two processes for each report. A report/process works very well. It gives me an error of invalid number.
In addition, another query SQL (editable report) gives me the following error when using the Multi line process, delete.
ORA-06502: PL/SQL: digital or value error: character number conversion
error ORA-06502: PL/SQL: digital or value error: character number conversion
errorOk When I got a report from SQL query (with box and a process) and the query SQL (editable report) everything worked. It stopped working when I added another SQL query report (with box and a process).
A SQL query has the following in my query: apex_item.checkbox(3,email_id,'UNCHECKED') ""
The other SQL query has the following: apex_item.checkbox(2,b.file_id,'UNCHECKED') ""
Any help will be greatly appreciated,
Sylvia
Hi Reema,
I've recreated the region and now it works!
Thank you for this, looking at
Sylvia
-
Hello
I use the database 12.1.0.2 with a node 2 RAC on Windows.
I am struck by a really weird performance problem with a particular query. Bear with me while I try to explain...
I have a chart with lines 30 sdo_geometry million, in 7 partitions with a local partitioned spatial index divided. Called BIG_PARTITIONED_TABLE for this example.
I query the table to search for one line with a geometry that is equal to the geometry of my request. In this case I use sdo_relate with "mask = equal". Instantly returns:
SQL> select id, geometry 2 from BIG_PARTITIONED_TABLE o 3 where sdo_relate(o.geometry, sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), 4 SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272)), 'mask=equal') = 'TRUE' 5 and rownum = 1; ID ---------- GEOMETRY(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES) ------------------------------------------------------------------------------- 2.5405E+12 SDO_GEOMETRY(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272)) Elapsed: 00:00:00.10
But if I put the same query in PL/SQL, so it takes 21 seconds:
SQL> declare 2 l_id number; 3 l_geom sdo_geometry; 4 l_window_geom sdo_geometry; 5 begin 6 l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), 7 SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272)); 8 9 select id, geometry 10 into l_id, l_geom 11 from BIG_PARTITIONED_TABLE o 12 where sdo_relate(o.geometry, l_window_geom, 'mask=equal') = 'TRUE' 13 and rownum = 1; 14 15 end; 16 / PL/SQL procedure successfully completed. Elapsed: 00:00:21.13
If I remove the "rownum = 1", then it returns instantly:
SQL> declare 2 l_id number; 3 l_geom sdo_geometry; 4 l_window_geom sdo_geometry; 5 begin 6 l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), 7 SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272)); 8 9 select id, geometry 10 into l_id, l_geom 11 from BIG_PARTITIONED_TABLE o 12 where sdo_relate(o.geometry, l_window_geom, 'mask=equal') = 'TRUE'; 13 14 end; 15 / PL/SQL procedure successfully completed. Elapsed: 00:00:00.03
If using sdo_equal instead of sdo_relate and keep the "rownum = 1", then it returns instantly.
SQL> declare 2 l_id number; 3 l_geom sdo_geometry; 4 l_window_geom sdo_geometry; 5 begin 6 l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), 7 SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272)); 8 9 select id, geometry 10 into l_id, l_geom 11 from BIG_PARTITIONED_TABLE o 12 where sdo_equal(o.geometry, l_window_geom) = 'TRUE' 13 and rownum = 1; 14 15 end; 16 / PL/SQL procedure successfully completed. Elapsed: 00:00:00.13
Here is a comparison of the plans to explain. First, here's the good thing, that is using the spatial index (BIG_PARTITIONED_TABLE_SPIND):
select id, GEOMETRY FROM BIG_PARTITIONED_TABLE O WHERE SDO_EQUAL(O.GEOMETRY, :B1 ) = 'TRUE' AND ROWNUM = 1 call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.01 0.02 0 39 0 0 Fetch 1 0.00 0.01 0 31 0 1 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 3 0.01 0.04 0 70 0 1 Misses in library cache during parse: 0 Optimizer mode: ALL_ROWS Parsing user id: 263 (recursive depth: 1) Number of plan statistics captured: 1 Rows (1st) Rows (avg) Rows (max) Row Source Operation ---------- ---------- ---------- --------------------------------------------------- 1 1 1 COUNT STOPKEY (cr=99 pr=0 pw=0 time=43307 us) 1 1 1 PARTITION RANGE ALL PARTITION: 1 7 (cr=99 pr=0 pw=0 time=43297 us cost=0 size=66 card=1) 1 1 1 TABLE ACCESS BY LOCAL INDEX ROWID BIG_PARTITIONED_TABLE PARTITION: 1 7 (cr=99 pr=0 pw=0 time=43280 us cost=0 size=66 card=1) 1 1 1 DOMAIN INDEX BIG_PARTITIONED_TABLE_SPIND (cr=98 pr=0 pw=0 time=43250 us)
Then the slow that does not use the spatial index.
select id, GEOMETRY FROM BIG_PARTITIONED_TABLE O WHERE SDO_RELATE(O.GEOMETRY, :B1 , 'mask=equal') = 'TRUE' AND ROWNUM = 1 call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.01 0.00 0 0 0 0 Execute 1 0.03 0.03 0 1123 0 0 Fetch 1 24.25 24.25 0 499429 0 1 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 3 24.30 24.29 0 500552 0 1 Misses in library cache during parse: 1 Misses in library cache during execute: 1 Optimizer mode: ALL_ROWS Parsing user id: 263 (recursive depth: 1) Number of plan statistics captured: 1 Rows (1st) Rows (avg) Rows (max) Row Source Operation ---------- ---------- ---------- --------------------------------------------------- 1 1 1 COUNT STOPKEY (cr=499532 pr=0 pw=0 time=24289612 us) 1 1 1 HASH JOIN RIGHT SEMI (cr=499532 pr=0 pw=0 time=24289586 us cost=32 size=144 card=1) 1 1 1 VIEW VW_NSO_1 (cr=103 pr=0 pw=0 time=31110 us cost=29 size=98016 card=8168) 1 1 1 COLLECTION ITERATOR PICKLER FETCH SDO_PQRY (cr=103 pr=0 pw=0 time=31104 us cost=29 size=16336 card=8168) 16914892 16914892 16914892 PARTITION RANGE ALL PARTITION: 1 7 (cr=499429 pr=0 pw=0 time=28678375 us cost=3 size=6600 card=100) 16914892 16914892 16914892 TABLE ACCESS FULL BIG_PARTITIONED_TABLE PARTITION: 1 7 (cr=499429 pr=0 pw=0 time=23406547 us cost=3 size=6600 card=100)
I tried adding an indication / * + index (o BIG_PARTITIONED_TABLE_SPIND) * / but that did not help.
I am struck this issue during testing of upgrade 10.2.0.5 to 12.1.0.2. The query works perfectly on 10g - we note only that this question on 12 c.
I can't use sdo_equal as the real mask that we want is equal + dommagescausdspar + covers. I'm just using equal here to simplify the test.
I use "rownum = 1" because I want to just the first result. In practice I can rewrite probably is a FOR LOOP, I get out after the first result, but that seems all just awful.
Any ideas? If anyone has seen anything like this before? Its an optimizer delivers really so I'm going to cross post the SQL Forum after a certain time, but thought I would post it here first.
Thank you
John
Hi John,.
Can you please try the following before your slow queries event?
"ALTER session set events ' trace 54669 name context forever."
Thank you
Ying
-
SQL query with the troubleshooting Subselects
I have a query with the 3 Subselects. Each of the Subselects works very well on its own. I run the query in Oracle SQL Developer and get ORA 933 "sql command not completed successfully" at 47 48 line pass. I am unable to say what is causing the error. The pointers you know sincerely!
Here is the code:SELECT adjud.country, adjud.site, adjud.prodtype, sum(adjud.acount) + sum(denied.dcount) as TotalClosed, case when adjud.adtype = 'Paid' then adjud.acount End as NumPaid, case when adjud.adtype = 'Paid' then adjud.totalpaid End as AmtPaid, count(adjud.contest) + count(denied.contest) + count(pend.contest) as CntContestable, sum(pend.pcount) as PendingCount, Case when pend.overunder = 'Over' Then count(pend.pcount) End as Over90Count, sum(pend.facevalue) as PendingAmount From ( select count(clm.clm_nbr) as acount, sum(clm.rsrv_amt) as facevalue, sum(clm.tot_pd_amt) as totalpaid, clm.prdt_type_nm as prodtype, clm.cntsbl_indc as contest, case when clm.exam_co_cd in ('107','134') then 'Hong Kong' else case when clm.exam_co_cd = '234' then 'Singapore' else 'US' End End as country, clm.exam_admin_site_cd as site, Case when clm.rmk_cd in ('R00', 'R01', 'R02') then 'Denied' Else 'Paid' End as adtype from afp_cds.claim_vw clm where clm.adjud_dt is not null and clm.adjud_dt > :startDate and clm.adjud_dt < :EndDate group by clm.prdt_type_nm, clm.cntsbl_indc, case when clm.exam_co_cd in ('107','134') then 'Hong Kong' else case when clm.exam_co_cd = '234' then 'Singapore' else 'US' End End, clm.exam_admin_site_cd, Case when clm.rmk_cd in ('R00', 'R01', 'R02') then 'Denied' Else 'Paid' End ) as adjud, ( select count(clm.clm_nbr) as dcount, sum(clm.rsrv_amt) as facevalue, clm.prdt_type_nm as prodtype, case when clm.exam_co_cd in ('107','134') then 'Hong Kong' else case when clm.exam_co_cd = '234' then 'Singapore' else 'US' End End as country, clm.exam_admin_site_cd as site, clm.cntsbl_indc as contest from afp_cds.claim_vw clm where clm.deny_dt is not null and clm.deny_dt > :startDate and clm.deny_dt < :EndDate group by clm.prdt_type_nm, case when clm.exam_co_cd in ('107','134') then 'Hong Kong' else case when clm.exam_co_cd = '234' then 'Singapore' else 'US' End End, clm.exam_admin_site_cd, clm.cntsbl_indc ) as denied, ( select count(clm.clm_nbr) as pcount, sum(clm.rsrv_amt) as facevalue, clm.prdt_type_nm as prodtype, case when clm.exam_co_cd in ('107','134') then 'Hong Kong' else case when clm.exam_co_cd = '234' then 'Singapore' else 'US' End End as country, clm.exam_admin_site_cd as site, clm.cntsbl_indc as contest, case when sysdate - clm.regtrtn_dt > 90 then 'Over' else 'Under' End as overunder from afp_cds.claim_vw clm where clm.adjud_dt is null and clm.deny_dt is null group by clm.prdt_type_nm, case when clm.exam_co_cd in ('107','134') then 'Hong Kong' else case when clm.exam_co_cd = '234' then 'Singapore' else 'US' End End, clm.exam_admin_site_cd, clm.cntsbl_indc, case when sysdate - regtrtn_dt > 90 then 'Over' else 'Under' End ) as pend where adjud.prodtype = denied.prodtype and adjud.country = denied.country and adjud.site = denied.site and adjud.contest = denied.contest and adjud.prodtype = pend.prodtype and adjud.country = pend.country and adjud.site = pend.site and adjud.contest = pend.contest group by adjud.country, adjud.site, adjud.prodtype, case when adjud.adtype = 'Paid' then adjud.acount End, case when adjud.adtype = 'Paid' then adjud.totalpaid End, Case when pend.overunder = 'Over' Then count(pend.pcount) End
Do not use "Sub" with the table alias.
Change this stmt type:
) as adjud,
TO
) adjud,
-
SQL query with terms and calculations?
Hello
How do I create a query with terms and calculations?
For example, I have this table
Start | End | At work | Mandatory
------------------------------------------------------------------------------------
1ST JANUARY 13 | JANUARY 11, 13. Office | 1
JANUARY 14, 13. 25 JANUARY 13 | Ministry of the Interior. 0
04-MRZ-13 | 15-MRZ-13 | Office | 0
FEBRUARY 11, 13. FEBRUARY 22, 13. Office | 1
Now, if the workplace of the column = office and required column = 0
the new 'price' column should calculate: (end-start) * $25.00
and if workplace = Office and required column = 1
the 'price' column must calculate: (end-start) * $20.60
any other $0.00
I tried with the case statement, but I didn't know how
to calculate my values and display in the virtual column 'price '.
Something like
case
When Working_Place = 'Office' and mandatory = 1
then...
else ' 0.00'. "
end PRICE
?????
Or is that not possible?
Published by: DB2000 on 12.03.2013 05:09Use CASE:
select start_dt, end_dt, working_place, mandatory, case when working_place = 'Office' and mandatory = 0 then (end_dt - start_dt) * 25 when working_place = 'Office' and mandatory = 1 then (end_dt - start_dt) * 20.60 else 0 end price from tbl / START_DT END_DT WORKING_PLA MANDATORY PRICE --------- --------- ----------- ---------- ---------- 01-JAN-13 11-JAN-13 Office 1 206 14-JAN-13 25-JAN-13 Home Office 0 0 04-MAR-13 15-MAR-13 Office 0 275 11-FEB-13 22-FEB-13 Office 1 226.6 SQL>
SY.
-
How to upgrade the value of line in a report by using the line selector (check box)
Hello
I have a requirement where I need to make PLSQL update process on a specific line in my report.
Based on the line selector (marked) the plsql process update on the values of the selected line.
I have to update status of the employee selected as 3.
But regardless of the choice of line selector, juice processing SRM application in a sequence that is., this is row selected, application takes the first line and updates the status.
My update process from looks like this:
BEGIN
BECAUSE me in 1... apex_application.g_f01. COUNTY - checkbox
LOOP
If apex_application.g_f01 (i) only IS NOT NULL then - box marked
insert into values TEMP_T (apex_application.g_f03 (i), V ('APP_USER')); -f03:Deptno
update status set Table_x = 3 where deptno in (select deptno from TEMP_T where rtrim (lower (apex_user)) = rtrim (lower (V ('APP_USER')));
delete from TEMP_T where rtrim (lower (apex_user)) = rtrim (lower (V ('APP_USER')));
end if;
END LOOP;
END;
Once the user selects the line selector, application needs to update the status of this particular emp 3 in Table_X.
Currently, if I select a line, using the line selection box, my update process changes the status of the first record line. If I select three rows, then my first three rows updated.
So I have to update the particular line or selected using the selector (checkbox) row lines
If you could help me solve this question would be really appreciated.
Thank you
VijayThis example shows how to use checkboxes in tabular form:
http://HTMLDB.Oracle.com/pls/OTN/f?p=31517:95
Denes Kubicek
------------------------------------------------------------------------------
http://deneskubicek.blogspot.com/
http://www.Opal-consulting.de/training
http://Apex.Oracle.com/pls/OTN/f?p=31517:1
------------------------------------------------------------------------------ -
(Updated report) SQL query - may not know how to make one
Hi people,
Can someone tell me how to make a report where the data can be updated? Not an interactive report, SQL report that selects a single row. The only options in the menu dropdown I see are "SQL query" and 'SQL Query (body of function from PL/SQL returning SQL query)', but I have a report elsewhere that says: this type are "SQL Query (updated report)", but I do not remember how :(
Thank you very much
-AdamHi Adam,.
An updated report is a 'tabular form' - see: http://download.oracle.com/docs/cd/E10513_01/doc/appdev.310/e10497/frm_tabular.htm#CHDFBHDB
Andy
-
SQL query with dynamic exercise
Hello
I wrote this query with static exercise and exercise, I need info on making the dynamic variables
Exercise: starts from July1st. This year up to June 30 is "2011" and July ' 1's '2012'
Exercise: July1st his '1' and June ' 1 his '12'
Query:
Select distinct o.c_num, o.ac_num, s.sub_ac_num, o.fiscal_year, o.ac_exp_date, s.sub_ac_ind
of org_account o
outer join left sub_account s
on o.c_num = s.c_num and o.ac_num = s.ac_num
where (o.ac_exp_date > = CURRENT_DATE or o.ac_exp_date is null)
and o.fiscal_year = * '2011' * -> need to be dynamic
and o.fiscal_period = * '12' * -> need to be dynamic
Thank you
Mano
Published by: user9332645 on June 2, 2011 18:55Hi, Mano,
Welcome to the forum!
Whenever you have a question, please post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data.
Always tell what version of Oracle you are using.Since this is your first thread, I will post some examples of data for you:
CREATE TABLE table_x ( dt DATE ); INSERT INTO table_x (dt) VALUES (DATE '2010-12-31'); INSERT INTO table_x (dt) VALUES (DATE '2011-01-01'); INSERT INTO table_x (dt) VALUES (DATE '2011-06-02'); INSERT INTO table_x (dt) VALUES (DATE '2011-06-30'); INSERT INTO table_x (dt) VALUES (DATE '2011-07-01');
What is the output you can from these data?
DT FISCAL_YEAR FISCAL_PERIOD ----------- --------------- --------------- 31-Dec-2010 2011 06 01-Jan-2011 2011 07 02-Jun-2011 2011 12 30-Jun-2011 2011 12 01-Jul-2011 2012 01
If so, here's a way to get it:
SELECT dt , TO_CHAR ( ADD_MONTHS (dt, 6) , 'YYYY' ) AS fiscal_year , TO_CHAR ( ADD_MONTHS (dt, 6) , 'MM' ) AS fiscal_period FROM table_x ORDER BY dt ;
Since your exercise begins 6 months prior to the calendar year, you must add 6 months to the actual date for the fiscal year and month.
The above query produces strings for fiscal_year and fiscal_period. If you prefer to have the numbers, then use EXTRACT instead of TO_CHAR:
SELECT dt , EXTRACT ( YEAR FROM ADD_MONTHS (dt, 6) ) AS fiscal_year , EXTRACT ( MONTH FROM ADD_MONTHS (dt, 6) ) AS fiscal_period FROM table_x ORDER BY dt ;
The first query will work in Oracle 6 (and more).
I don't know when EXTRACT was introduced. Certainly, it works in Oracle 10 and may be available in older versions too. -
What line has been activated in a (updated report) SQL query?
I have an app with a report based on a query SQL (PL/SQL function...) defined on the Global Page.
I want on the pages where the report is used, click on a particular column (TCKT_ID), and then pass the values of this line to another page for treatment.
I would like to know things:
(1) how to determine which line clicked? The column is TCKT_ID and it is used as a link to another page. The SQLis a significant (for me!) join the tables.
(2) how to see the values of other columns in the same row? Because I format with 'div', columns are named - no "f02", of "f03", etc.
(3) how to pass multiple values (ENAME, JOB, MGR, SAL, COMM) to the target page? You might ask: why not just re - query data using a unique key. Great idea, but the unique key is four columns if I still need a way to pass these four values for this unique key.
I built a 'pretty close' example of the situation in the present case:
WS APEX_EXAMPLES_01
Demo / demo
Application: Line Info 10782 - Page 0 has the report. Page 1 poster with a link (in red) on page 2.
I think I can fill most of what I need if someone can just show me how to make, say, the ENAME of the line clicked on page 1, so I can use it to filter the query on page 2 for just this line clicked on page 1.
From < tt > < /tt >, I tried show the actual line view - Source of the actual report than just let me but it comes out like this
M FMM_O_BD_DAILY. CTL (D046 ftp) CMM_O_BD_DAILY.sh (ftp D046) 17:15
10-13 JUNE AT 17:00:5210-13 JUNE AT 17:00:5317:15
10-13 JUNE AT 17:00:5210-13 JUNE AT 17:00:5317:00
10-13 JUNE AT 17:00:5910-13 JUNE AT 17:01THEREARS003_TEST NEXT BUSINESS DAY
I wonder if I'm not understanding something. This seems to be a very simple thing to do without 'tricks '.
Take a look, I modified the column LINKING_NUMBER of the report of p0.
Basically, you specify only the fields you want to fill and their assignments. I added 4 fields of destination on p2 to receive assignments. Then you can do whatever you want with them as editing a report, etc...
The only trick here is to get more than 3 elements in the URL, you must change your Page link type in this URL request. You can specify lost elements in this way.
Thank you
-Jorge
-
Help setting up a SQL query with poor performance
Hi all
Database version: 10.2.0.5
I'm working on a new report to view the top users by the number of calls. The table is truncated and filled again every month with records for the previous month; It contains approximately 400 000 records.
I created a view with the columns needed for the report; also, the two functions of view calls to determine if a phone number is assigned to multiple staffs or several departments.
It's full again table every month:
CREATE TABLE "VOIP"."MONTHLY_BILLING_DETAILS" ( "ID" NUMBER NOT NULL ENABLE, "CDRRECORDTYPE" NUMBER, "G_CALLMANAGERID" NUMBER, "G_CALLID" NUMBER, "O_LEGCALLIDENTIFIER" NUMBER, "DATETIMEORIGINATION" NUMBER, "O_NODEID" NUMBER, "O_SPAN" NUMBER, "O_IPADDR" NUMBER, "CALLINGPARTYNUMBER" VARCHAR2(50 BYTE) NOT NULL ENABLE, "CALLINGPARTY_USERID" VARCHAR2(128 BYTE), "O_CAUSE_LOCATION" NUMBER, "O_CAUSE_VALUE" NUMBER, "O_PRECEDENCELEVEL" NUMBER, "O_MEDIATRANSPORTADDR_IP" NUMBER, "O_MEDIATRANSPORTADDR_PORT" NUMBER, "O_MCAP_PAYLOADCAPABILITY" NUMBER, "O_MCAP_MAXFRAMESPERPACKET" NUMBER, "O_MCAP_G723BITRATE" NUMBER, "O_VCAP_CODEC" NUMBER, "O_VCAP_BANDWIDTH" NUMBER, "O_VCAP_RESOLUTION" NUMBER, "O_VIDEOTRANSPORTADDR_IP" NUMBER, "O_VIDEOTRANSPORTADDR_PORT" NUMBER, "O_RSVPAUDIOSTAT" VARCHAR2(64 BYTE), "O_RSVPVIDEOSTAT" VARCHAR2(64 BYTE), "DESTLEGIDENTIFIER" NUMBER, "DESTNODEID" NUMBER, "DESTSPAN" NUMBER, "DESTIPADDR" NUMBER, "ORIGINALCALLEDPARTYNUMBER" VARCHAR2(50 BYTE), "FINALC_PARTYNUMBER" VARCHAR2(50 BYTE), "FINALC_PARTY_USERID" VARCHAR2(128 BYTE), "DESTCAUSE_LOCATION" NUMBER, "DESTCAUSE_VALUE" NUMBER, "DESTPRECEDENCELEVEL" NUMBER, "DESTMEDIATRANSPORTADDR_IP" NUMBER, "DESTMEDIATRANSPORTADDR_PORT" NUMBER, "DESTMCAP_PAYLOADCAPABILITY" NUMBER, "DESTMCAP_MAXFRAMESPERPACKET" NUMBER, "DESTMCAP_G723BITRATE" NUMBER, "DV_CAP_CODEC" NUMBER, "DV_CAP_BANDWIDTH" NUMBER, "DV_CAP_RESOLUTION" NUMBER, "DV_TRANSPORTADDR_IP" NUMBER, "DV_TRANSPORTADDR_PORT" NUMBER, "DESTRSVPAUDIOSTAT" VARCHAR2(64 BYTE), "DESTRSVPVIDEOSTAT" VARCHAR2(64 BYTE), "DATETIMECONNECT" NUMBER, "DATETIMEDISCONNECT" NUMBER, "LASTREDIRECTDN" VARCHAR2(50 BYTE), "PKID" VARCHAR2(4000 BYTE), "O_INALCALLEDPARTYNUM_PARTITION" VARCHAR2(50 BYTE), "CALLINGPARTYNUM_PARTITION" VARCHAR2(50 BYTE), "FINALC_PARTYNUM_PARTITION" VARCHAR2(50 BYTE), "LASTREDIRECTDNPARTITION" VARCHAR2(50 BYTE), "DURATION" NUMBER, "O_DEVICENAME" VARCHAR2(129 BYTE), "DESTDEVICENAME" VARCHAR2(129 BYTE), "O_CALLTERMINATION_BEHALF" NUMBER, "DESTCALLTERMINATION_BEHALF" NUMBER, "O_CALLEDPARTYREDIRECT_BEHALF" NUMBER, "LASTREDIRECTREDIRECT_BEHALF" NUMBER, "O_CALLEDPARTYREDIRECTREASON" NUMBER, "LASTREDIRECTREDIRECTREASON" NUMBER, "DESTCONVERSATIONID" NUMBER, "G_CALLID_CLUSTERID" VARCHAR2(50 BYTE), "JOIN_BEHALF" NUMBER, "COMMENTS" VARCHAR2(2048 BYTE), "AUTHCODEDESCRIPTION" VARCHAR2(50 BYTE), "AUTHORIZATIONLEVEL" NUMBER, "CLIENTMATTERCODE" VARCHAR2(32 BYTE), "O_DTMFMETHOD" NUMBER, "DESTDTMFMETHOD" NUMBER, "CALLSECUREDSTATUS" NUMBER, "O_CONVERSATIONID" NUMBER, "O_MCAP_BANDWIDTH" NUMBER, "DESTMCAP_BANDWIDTH" NUMBER, "AUTHORIZATIONCODEVALUE" VARCHAR2(32 BYTE), "OUTPULSEDCALLINGPARTYNUMBER" VARCHAR2(50 BYTE), "OUTPULSEDCALLEDPARTYNUMBER" VARCHAR2(50 BYTE), "O_IPV4V6ADDR" VARCHAR2(64 BYTE), "DESTIPV4V6ADDR" VARCHAR2(64 BYTE), "O_VCAP_CODEC_CHAN2" NUMBER, "O_VCAP_BANDWIDTH_CHAN2" NUMBER, "O_VCAP_RESOLUTION_CHAN2" NUMBER, "O_V_TRANSPORTADDR_IP_CHAN2" NUMBER, "O_V_TRANSPORTADDR_PORT_CHAN2" NUMBER, "O_V_OCHANNEL_ROLE_CHAN2" NUMBER, "DV_CAP_CODEC_CHAN2" NUMBER, "DV_CAP_BANDWIDTH_CHAN2" NUMBER, "DV_CAP_RESOLUTION_CHAN2" NUMBER, "DV_TRANSPORTADDR_IP_CHAN2" NUMBER, "DV_TRANSPORTADDR_PORT_CHAN2" NUMBER, "DV_CHANNEL_ROLE_CHAN2" NUMBER, "DATE_CREATED" DATE, "DATETIME_CONNECT" DATE, "DATETIME_DISCONNECT" DATE, "USERID_EMAIL_ADDRESS" VARCHAR2(100 BYTE), "FROM_FULL_TELEPHONE" VARCHAR2(20 BYTE), "TO_FULL_TELEPHONE" VARCHAR2(20 BYTE), "FROM_EXCHANGE" VARCHAR2(7 BYTE), "TO_EXCHANGE" VARCHAR2(20 BYTE), "FROM_CITY" VARCHAR2(200 BYTE), "FROM_STATE" VARCHAR2(2 BYTE), "TO_CITY" VARCHAR2(200 BYTE), "TO_STATE" VARCHAR2(2 BYTE), "CALL_TYPE" VARCHAR2(10 BYTE), CONSTRAINT "MONTHLY_BILLING_PK" PRIMARY KEY ("ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ENABLE ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 75497472 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX1" ON "VOIP"."MONTHLY_BILLING_DETAILS" (TRUNC("DATETIME_CONNECT")) PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX10" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("CALL_TYPE") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX2" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("FROM_EXCHANGE") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX3" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("FROM_FULL_TELEPHONE", TRUNC("DATETIME_CONNECT")) PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX4" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT", NVL("FROM_FULL_TELEPHONE","CALLINGPARTYNUMBER")) PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 5242880 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX5" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT", NVL("TO_FULL_TELEPHONE","ORIGINALCALLEDPARTYNUMBER")) PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 5242880 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX6" ON "VOIP"."MONTHLY_BILLING_DETAILS" (TO_CHAR("DATETIME_CONNECT",'fmMONTH YYYY')) PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX7" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("TO_EXCHANGE") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX8" ON "VOIP"."MONTHLY_BILLING_DETAILS" (NVL("FROM_FULL_TELEPHONE","CALLINGPARTYNUMBER")) PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ; CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX9" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VOIPDATA" ;
These are the functions to determine if a phone number is assigned to multiple staffs or departments:
FUNCTION GET_EMPLOYEE_NAME (P_FROM_FULL_TELEPHONE IN VARCHAR2) RETURN VARCHAR2 AS L_NAME EMPLOYEES.NAME%TYPE; BEGIN SELECT NAME INTO L_NAME FROM EMPLOYEES WHERE WORK_PHONE_1_FORMAT = P_FROM_FULL_TELEPHONE; RETURN L_NAME; EXCEPTION WHEN TOO_MANY_ROWS THEN L_NAME := 'Multiple Employees'; RETURN L_NAME; WHEN NO_DATA_FOUND THEN L_NAME := 'No Employee Assigned'; RETURN L_NAME; WHEN OTHERS THEN NULL; END;
FUNCTION GET_DEPARTMENT_NAME (P_FROM_FULL_TELEPHONE IN VARCHAR2) RETURN VARCHAR2 AS L_DEPT_DESCR EMPLOYEES.DEPT_DESCR%TYPE; BEGIN SELECT DEPT_DESCR INTO L_DEPT_DESCR FROM EMPLOYEES WHERE WORK_PHONE_1_FORMAT = P_FROM_FULL_TELEPHONE; RETURN L_DEPT_DESCR; EXCEPTION WHEN TOO_MANY_ROWS THEN L_DEPT_DESCR := 'Multiple Departments'; RETURN L_DEPT_DESCR; WHEN NO_DATA_FOUND THEN L_DEPT_DESCR := 'No Department Assigned'; RETURN L_DEPT_DESCR; WHEN OTHERS THEN NULL; END;
This is the point of view that I'll use in the report:
CREATE OR REPLACE FORCE VIEW "VOIP"."TOP_USERS_BY_CALLS_V" ("TOP_NO", "EMPLOYEE_NAME", "EMPLOYEE_DEPARTMENT", "PHONE_NUMBER", "QUANTITY_CALLS") AS SELECT ROWNUM, VOIP_PKG.GET_EMPLOYEE_NAME(FROM_FULL_TELEPHONE), VOIP_PKG.GET_DEPARTMENT_NAME(FROM_FULL_TELEPHONE), FROM_FULL_TELEPHONE, QUANTITY_CALLS FROM ( SELECT MBD.FROM_FULL_TELEPHONE, COUNT(1) QUANTITY_CALLS FROM MONTHLY_BILLING_DETAILS MBD WHERE MBD.FROM_FULL_TELEPHONE IS NOT NULL AND MBD.FROM_FULL_TELEPHONE <> '000-000-0000' AND LENGTH(MBD.FROM_FULL_TELEPHONE) = 12 AND LENGTH(MBD.TO_FULL_TELEPHONE) = 12 AND SUBSTR(MBD.TO_FULL_TELEPHONE,1,3) NOT IN (SELECT AREA_CODE FROM NYNJ_METRO_AREA_CODES) AND SUBSTR(MBD.TO_FULL_TELEPHONE,1,3) NOT IN ('800','822','833','844', '855','866','877','888') GROUP BY MBD.FROM_FULL_TELEPHONE ORDER BY QUANTITY_CALLS DESC ) WHERE ROWNUM <= 100;
Explain Plan output and Extended SQL Trace:
SQL> SQL> show parameter user_dump_dest NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ user_dump_dest string D:\ORACLEHOMES\ADMIN\RTS9\UDUM P SQL> SQL> show parameter optimizer NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ optimizer_dynamic_sampling integer 2 optimizer_features_enable string 10.2.0.5 optimizer_index_caching integer 0 optimizer_index_cost_adj integer 100 optimizer_mode string ALL_ROWS optimizer_secure_view_merging boolean TRUE SQL> SQL> show parameter db_file_multi NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_file_multiblock_read_count integer 16 SQL> SQL> show parameter db_block_size NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_block_size integer 8192 SQL> SQL> show parameter cursor_sharing NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ cursor_sharing string EXACT SQL> SQL> column sname format a20 SQL> column pname format a20 SQL> column pval2 format a20 SQL> SQL> select 2 sname 3 , pname 4 , pval1 5 , pval2 6 from 7 sys.aux_stats$; SNAME PNAME PVAL1 PVAL2 -------------------- -------------------- ---------- -------------------- SYSSTATS_INFO STATUS COMPLETED SYSSTATS_INFO DSTART 02-09-2009 15:46 SYSSTATS_INFO DSTOP 02-09-2009 15:46 SYSSTATS_INFO FLAGS 1 SYSSTATS_MAIN CPUSPEEDNW 1259.6206 SYSSTATS_MAIN IOSEEKTIM 10 SYSSTATS_MAIN IOTFRSPEED 4096 SYSSTATS_MAIN SREADTIM SYSSTATS_MAIN MREADTIM SYSSTATS_MAIN CPUSPEED SYSSTATS_MAIN MBRC SYSSTATS_MAIN MAXTHR SYSSTATS_MAIN SLAVETHR 13 rows selected. Elapsed: 00:00:00.03 SQL> SQL> explain plan for 2 SELECT 3 TOP_NO, 4 EMPLOYEE_NAME, 5 EMPLOYEE_DEPARTMENT, 6 PHONE_NUMBER, 7 QUANTITY_CALLS 8 FROM 9 TOP_USERS_BY_CALLS_V 10 ORDER BY 11 QUANTITY_CALLS DESC; Explained. Elapsed: 00:00:00.18 SQL> SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Plan hash value: 826236322 ---------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 4042 | 1313 (1)| 00:00:16 | | 1 | SORT ORDER BY | | 1 | 4042 | 1313 (1)| 00:00:16 | | 2 | VIEW | TOP_USERS_BY_CALLS_V | 1 | 4042 | 1312 (1)| 00:00:16 | |* 3 | COUNT STOPKEY | | | | | | | 4 | VIEW | | 1 | 25 | 1312 (1)| 00:00:16 | |* 5 | SORT ORDER BY STOPKEY | | 1 | 26 | 1312 (1)| 00:00:16 | | 6 | HASH GROUP BY | | 1 | 26 | 1312 (1)| 00:00:16 | |* 7 | FILTER | | | | | | |* 8 | TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS | 1 | 26 | 1310 (1)| 00:00:16 | |* 9 | INDEX FULL SCAN | MONTHLY_BILL_INDEX3 | 934 | | 449 (1)| 00:00:06 | |* 10 | INDEX FULL SCAN | NYNJ_METRO_AREA_CODES_UK1 | 1 | 4 | 1 (0)| 00:00:01 | ---------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter(ROWNUM<=100) 5 - filter(ROWNUM<=100) 7 - filter( NOT EXISTS (SELECT 0 FROM VOIP."NYNJ_METRO_AREA_CODES" "NYNJ_METRO_AREA_CODES" WHERE LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3)))) 8 - filter(LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888') 9 - filter(LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000' AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL) 10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3))) 33 rows selected. Elapsed: 00:00:00.82 SQL> SQL> rollback; Rollback complete. Elapsed: 00:00:00.00 SQL> SQL> set autotrace traceonly arraysize 100 SQL> SQL> alter session set tracefile_identifier = 'mytrace1'; Session altered. Elapsed: 00:00:00.01 SQL> SQL> alter session set events '10046 trace name context forever, level 8'; Session altered. Elapsed: 00:00:00.15 SQL> SQL> SELECT 2 TOP_NO, 3 EMPLOYEE_NAME, 4 EMPLOYEE_DEPARTMENT, 5 PHONE_NUMBER, 6 QUANTITY_CALLS 7 FROM 8 TOP_USERS_BY_CALLS_V 9 ORDER BY 10 QUANTITY_CALLS DESC; 100 rows selected. Elapsed: 00:10:37.68 Execution Plan ---------------------------------------------------------- Plan hash value: 826236322 ---------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 4042 | 1313 (1)| 00:00:16 | | 1 | SORT ORDER BY | | 1 | 4042 | 1313 (1)| 00:00:16 | | 2 | VIEW | TOP_USERS_BY_CALLS_V | 1 | 4042 | 1312 (1)| 00:00:16 | |* 3 | COUNT STOPKEY | | | | | | | 4 | VIEW | | 1 | 25 | 1312 (1)| 00:00:16 | |* 5 | SORT ORDER BY STOPKEY | | 1 | 26 | 1312 (1)| 00:00:16 | | 6 | HASH GROUP BY | | 1 | 26 | 1312 (1)| 00:00:16 | |* 7 | FILTER | | | | | | |* 8 | TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS | 1 | 26 | 1310 (1)| 00:00:16 | |* 9 | INDEX FULL SCAN | MONTHLY_BILL_INDEX3 | 934 | | 449 (1)| 00:00:06 | |* 10 | INDEX FULL SCAN | NYNJ_METRO_AREA_CODES_UK1 | 1 | 4 | 1 (0)| 00:00:01 | ---------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter(ROWNUM<=100) 5 - filter(ROWNUM<=100) 7 - filter( NOT EXISTS (SELECT 0 FROM VOIP."NYNJ_METRO_AREA_CODES" "NYNJ_METRO_AREA_CODES" WHERE LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3)))) 8 - filter(LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888') 9 - filter(LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000' AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL) 10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3))) Statistics ---------------------------------------------------------- 365 recursive calls 0 db block gets 689543 consistent gets 212906 physical reads 0 redo size 5984 bytes sent via SQL*Net to client 400 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 2 sorts (memory) 0 sorts (disk) 100 rows processed SQL> SQL> disconnect
Part of the automatic trace output:
SELECT TOP_NO, EMPLOYEE_NAME, EMPLOYEE_DEPARTMENT, PHONE_NUMBER, QUANTITY_CALLS FROM TOP_USERS_BY_CALLS_V ORDER BY QUANTITY_CALLS DESC call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.43 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 2 24.70 635.81 212587 631823 0 100 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 4 24.70 636.25 212587 631823 0 100 Misses in library cache during parse: 1 Optimizer mode: ALL_ROWS Parsing user id: 148 Rows Row Source Operation ------- --------------------------------------------------- 100 SORT ORDER BY (cr=689531 pr=212900 pw=0 time=636823070 us) 100 VIEW TOP_USERS_BY_CALLS_V (cr=689531 pr=212900 pw=0 time=642681672 us) 100 COUNT STOPKEY (cr=631823 pr=212587 pw=0 time=635667026 us) 100 VIEW (cr=631823 pr=212587 pw=0 time=635666810 us) 100 SORT ORDER BY STOPKEY (cr=631823 pr=212587 pw=0 time=635666493 us) 2512 HASH GROUP BY (cr=631823 pr=212587 pw=0 time=635666125 us) 27112 FILTER (cr=631823 pr=212587 pw=0 time=519230237 us) 315563 TABLE ACCESS BY INDEX ROWID MONTHLY_BILLING_DETAILS (cr=381523 pr=212587 pw=0 time=580209555 us) 394473 INDEX FULL SCAN MONTHLY_BILL_INDEX3 (cr=2679 pr=2679 pw=0 time=26793918 us)(object id 206675) 226627 INDEX FULL SCAN NYNJ_METRO_AREA_CODES_UK1 (cr=250300 pr=0 pw=0 time=3575488 us)(object id 206605) Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 2 0.00 0.00 db file sequential read 212587 0.20 611.67 SQL*Net message from client 2 0.00 0.00 SQL*Net more data to client 2 0.00 0.00 ********************************************************************************
DBMS_XPLAN. Output DISPLAY_CURSOR:
SQL> SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST')); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- SQL_ID 1ut636vt58jdw, child number 0 ------------------------------------- SELECT /*+ gather_plan_statistics */ TOP_NO, EMPLOYEE_NAME, EMPLOYEE_DEPARTMENT, PHONE_NUMBER, QUANTITY_CALLS FROM TOP_USERS_BY_CALLS_V ORDER BY QUANTITY_CALLS DESC Plan hash value: 826236322 -------------------------------------------------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads | OMem | 1Mem | Used-Mem | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | | 100 |00:09:56.06 | 689K| 210K| | | | | 1 | SORT ORDER BY | | 1 | 1 | 100 |00:09:56.06 | 689K| 210K| 13312 | 13312 |12288 (0)| | 2 | VIEW | TOP_USERS_BY_CALLS_V | 1 | 1 | 100 |00:10:04.98 | 689K| 210K| | | | |* 3 | COUNT STOPKEY | | 1 | | 100 |00:09:54.89 | 631K| 210K| | | | | 4 | VIEW | | 1 | 1 | 100 |00:09:54.89 | 631K| 210K| | | | |* 5 | SORT ORDER BY STOPKEY | | 1 | 1 | 100 |00:09:54.88 | 631K| 210K| 6144 | 6144 | 6144 (0)| | 6 | HASH GROUP BY | | 1 | 1 | 2512 |00:09:54.88 | 631K| 210K| 821K| 821K| 1153K (0)| |* 7 | FILTER | | 1 | | 27112 |00:08:58.57 | 631K| 210K| | | | |* 8 | TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS | 1 | 1 | 315K|00:08:57.07 | 381K| 210K| | | | |* 9 | INDEX FULL SCAN | MONTHLY_BILL_INDEX3 | 1 | 934 | 394K|00:00:23.02 | 2679 | 2679 | | | | |* 10 | INDEX FULL SCAN | NYNJ_METRO_AREA_CODES_UK1 | 250K| 1 | 226K|00:00:03.47 | 250K| 0 | | | | -------------------------------------------------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter(ROWNUM<=100) 5 - filter(ROWNUM<=100) 7 - filter( IS NULL) 8 - filter((LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888')) 9 - filter((LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000' AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL)) 10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3))) 35 rows selected. Elapsed: 00:00:00.50 SQL> SQL> spool off
Any help will be greatly appreciated. Please let me know if you need additional information.
Thank you
Erick
ediazjorge wrote:
Please let me know if you need additional information or do additional tests.
Thanks again!
Erick
It's to you if you are satisfied or interested in improvements (if possible).
If so the first thing I would like if you had your refreshed perspective as advised. According to expected area_code table cardinalities I doubt.
So, if not cool off with dbms_stats.gather_table_stats on two tables, area_codes and MONTHLY_BILLING_DETAILS.
Bottlenecks are now obviously the full table of MONTHLY_BILLING_DETAILS as well as the ANTI of LOOPS IMBRIQUEES scan.
At the moment I don't think that an index of MONTHLY_BILLING_DETAILS will help a lot, because most of the lines will pass filter predicates, and because we need some columns in it, I have now I there will be gain a full index scan.
I was surprissed that the optimizer pushes the substr <> predicates to both tables.
So depending on your data, you might try
1 make a factory of subquery select the two MONTHLY_BILLING_DETAILS columns that all directly apply predicates of membership and use it directly in the join instead of the table.
or
2. If all subtr to so are part of the table area_code choose in it using a subquery (or inline view) plant excluding these values.
Both are attempts to get rid of the substr excluding as filters of join predicates.
In fact, I was expecting a hash join anti as shown in the plan to explain instead of the nested loops anti, I expect to be more effective in this case.
Perhaps with correct cardinalities the optimizier would understand himself.
Just to test it, you can try the use_hash hint in the join:
Select / * + USE_HASH (MBD, one) * /.
..
OF MONTHLY_BILLING_DETAILS MBD,.
NYNJ_METRO_AREA_CODES one
(It's a good habit anyway usually use aliases and precede the names of columns. In the, it is easier to read queries are only trivial).
-
Report, SQL query based on the values of the elements (question SQL)
Hello
I use APEX 4.0 with Oracle 10 g r2 under Windows XP Pro SP3.
I have an interactive report and a menu with a few items to filter the report.
It works with most of the elements, but my problem is to select lists that have additional values, for example:
and I will return null as ' (return '%').SELECT '(null)' display_value, 'NULL' return_value FROM DUAL UNION ALL select distinct(SPAT_AREA_NAME) display_value, SPAT_AREA_NAME return_value from SPATIAL_POINTS order by 1
For example, if the user selects "(null)", the report should return all rows with a NULL value in the column AREA_NAME.
If he chooses "", the report should return all the lines. "
and if the user selects a value, the report should return all the lines containing the value in column AREA_NAME.
I don't know how to build my application. I tried with the CASE statements, DECODE, etc... but I still can't!
My report query is for now:
Any idea?select SPAT_ID, SPAT_ACCL_NAME, SPAT_AREA_NAME, SPAT_CLASS, SPAT_NUMBER, SPAT_PT, SPAT_TYPE, SPAT_STATUS, from SPATIAL_POINTS where upper(SPAT_AREA_NAME) LIKE upper(:P3_FILTRE_AREA_NAME) AND upper(SPAT_ACCL_NAME) LIKE upper(:P3_FILTRE_ACC_NAME) AND upper(SPAT_CLASS) LIKE '%'||upper(:P3_SPATIAL_CLASS)||'%' AND instr(upper(:P3_SPATIAL_TYPE_VALUES),upper(SPAT_TYPE)) > 0 AND instr(upper(:P3_SPATIAL_STATUS_VALUES),upper(SPAT_STATUS)) > 0 AND instr(upper(:P3_SPATIAL_POINT_VALUES),upper(SPAT_PT)) > 0
Thank you!
Yann.Hello
Then, assuming that spat_accl_name is not a string value "NULL" then you can try this...
SELECT spat_id, spat_accl_name, spat_area_name, spat_class, spat_number, spat_pt, spat_type, spat_status, ROUND(spat_cumul, (SELECT up_number_precision FROM user_preferences WHERE UPPER(up_nice_login) = UPPER(v('APP_USER')))) AS "SPAT_CUMUL" FROM spatial_points WHERE :p3_filtre_acc_name IS NULL AND spat_accl_name IS NULL OR(CASE WHEN :p3_filtre_acc_name = '%' THEN NVL(spat_accl_name,'NULL') ELSE :p3_filtre_acc_name END = NVL(spat_accl_name, 'NULL'))
See you soon
Ben
-
pl - sql query with index by table errors
Hello once again
I'm stuck again with the following query
I want to display the name of the Department, employee id name count and avg sal
rec type is rendered
(
not a number (8.0).
DNAME varchar2 (40),
mgr_nm varchar2 (55),
d_hc number (8.0).
SAL number (8.2)
);
rec1 is the rec index table directory.
Start
for rec1 in)
Select a1.dnm, a1.nm, b.did, b.hc, b.sal
Of
(
Select d.department_id as did e1.first_name |' '|| E1.last_name like nm, d.department_name as dnm
of hr.employees e1, hr.departments d
where e1.department_id = d.department_id) a1.
(
Select d.department_id as did, count (e1.employee_id) as hc, avg (e1.salary) as sal
of hr.employees e1, hr.departments d
where e1.department_id = d.department_id
D.department_id group) b
where a1.did = b.did)
loop
dbms_output.put_line (REC1);
end loop;
end;
/
my error is
ORA-00900: invalid SQL statement
Help, please
Thank you!!!Try this:
begin for rec1 in ( select a1.dnm , a1.nm , b.did , b.hc , b.sal from ( select d.department_id as did , e1.first_name||' '||e1.last_name as nm , d.department_name as dnm from hr.employees e1 , hr.departments d where e1.department_id=d.department_id ) a1 , ( select d.department_id as did , count(e1.employee_id) as hc , avg(e1.salary)as sal from hr.employees e1 , hr.departments d where e1.department_id=d.department_id group by d.department_id ) b where a1.did=b.did ) loop dbms_output.put_line(rec1.dnm||' - '||rec1.nm||' - '||rec1.did||' - '||rec1.hc||' - '||rec1.sal); end loop; end; /
Edit
Use code tags when you post for example, keep formatting and indenting.
See: http://wiki.oracle.com/page/Oracle+Discussion+Forums+FAQ (scroll down a bit)Published by: hoek on November 24, 2009 16:01
Maybe you are looking for
-
What happened to the Mozilla Store?
I bought a bag on back of the store to mozilla a few years ago and I loved it. What happened to the store I want to buy more products.
-
Can I do this with iCloud?
I have an iPhone and an iPad and I get messages that I have about 237 MB of free space, and I am considering the upgrade. 1 mail seems to take a lot of space in iCloud, although I do not use Apple mail servers. How is used this space? 2. I will not u
-
Cannot install the MFP M177fw printer driver
I try again to install the driver and follow the instructions at the bottom of the link but still cannot install. I start small windows and even to create a new user, but can not run. http://h30434.www3.HP.com/T5/printer-software-and-drivers/not-able
-
can I update my laptop graphics card
Hi I was just wondering if it is possible for me to update my laptop computer graphics card, like the one I have is an integrated intel hd and it's simply not enough good for games, I want to play The laptop I have is hp Pavilion g6 and the model num
-
Transcript of the old-fashioned way
Microsoft has a program that I can use to transcribe the audio repeating automatically?