Query on the PL/SQL Collections
Hi allPlease help me with the code below.
I wrote this package, now I want to see the result by calling this package.
Please take a look at the below scenario. It is just a POC that I tried on the EMPLOYEE table, once it is a success I will apply this original code.
How to call this package and how to capture the values will be stored in the OUTPUT parameters, please help me with this.
-Package Spec
create or replace PACKAGE emp_dtls_pkg
AS
Dept_rec_type RECORD TYPE IS
(DEPARTMENT_NAME HR.departments.DEPARTMENT_NAME%TYPE
Location_id HR.departments.LOCATION_ID%TYPE);
Emp_rec_type RECORD TYPE IS
(Employe_id HR.employees.EMPLOYEE_ID%TYPE
HR.employees.FIRST_NAME%TYPE name
LAST_NAME HR.employees.LAST_NAME%TYPE
E-MAIL HR.employees.EMAIL%TYPE
PHONE_NUMBER HR.employees.PHONE_NUMBER%TYPE
HR.employees.HIRE_DATE%TYPE HIRE_DATE
HR.employees.JOB_ID%TYPE JOB_ID
HR.employees.SALARY%TYPE SALARY
HR.employees.COMMISSION_PCT%TYPE COMMISSION_PCT);
TYPE emp_tbl_type IS TABLE OF THE emp_rec_type;
PROCEDURE get_emp_dtls
(p_dept_number number
p_dept_rec ON emp_dtls_pkg.dept_rec_type
p_emp_rec ON emp_dtls_pkg.emp_tbl_type
);
END emp_dtls_pkg;
-Package body
CREATE or REPLACE PACKAGE BODY emp_dtls_pkg AS
PROCEDURE get_emp_dtls
(p_dept_number number
p_dept_rec ON emp_dtls_pkg.dept_rec_type
p_emp_rec ON emp_dtls_pkg.emp_tbl_type
)
IS
cursor emp_cur is
Select EMPLOYEE_ID
FIRST NAME
LAST_NAME
PHONE_NUMBER
HIRE_DATE
JOB_ID
SALARY
COMMISSION_PCT HR.employees
where department_id = p_dept_number;
l_emp_tbl emp_dtls_pkg.emp_tbl_type: = emp_dtls_pkg.emp_tbl_type ();
l_dname HR.departments.DEPARTMENT_NAME%TYPE;
l_loc HR.departments.LOCATION_ID%TYPE;
BEGIN
Select DEPARTMENT_NAME, location_id
in l_dname, l_loc
of HR.departments
where department_id = p_dept_number;
IF l_loc is not null THEN
p_dept_rec. DEPARTMENT_NAME: = l_dname;
p_dept_rec. location_id: = l_loc;
FOR SheikYerbouti in emp_cur
LOOP
I'm in l_emp_tbl.first... l_emp_tbl. Last
LOOP
l_emp_tbl (l_emp_tbl. LAST YEAR). Employe_id: = SheikYerbouti. EMPLOYEE_ID;
l_emp_tbl (l_emp_tbl. LAST YEAR). First name: = SheikYerbouti. FIRST_NAME;
l_emp_tbl (l_emp_tbl. LAST YEAR). Name: = SheikYerbouti. LAST_NAME;
l_emp_tbl (l_emp_tbl. LAST YEAR). E-MAIL: = SheikYerbouti. E-MAIL ADDRESS;
l_emp_tbl (l_emp_tbl. LAST YEAR). PHONE_NUMBER: = SheikYerbouti. PHONE_NUMBER;
l_emp_tbl (l_emp_tbl. LAST YEAR). HIRE_DATE: = SheikYerbouti. HIRE_DATE;
l_emp_tbl (l_emp_tbl. LAST YEAR). Job_id: = SheikYerbouti. JOB_ID;
l_emp_tbl (l_emp_tbl. LAST YEAR). SALARY: = SheikYerbouti. SALARY;
l_emp_tbl (l_emp_tbl. LAST YEAR). COMMISSION_PCT: = emp_rec.COMMISSION_PCT;
END LOOP;
END LOOP;
END IF;
p_emp_rec: = l_emp_tbl;
EXCEPTION
WHILE OTHERS THEN
DBMS_OUTPUT. PUT_LINE (' ERROR: ' |) SQLERRM);
END get_emp_dtls;
END emp_dtls_pkg;
/
Thanks and greetings
Srinivas
Hi Srinivas,
I hope code below will be useful for you...
-- Package Specification
create or replace PACKAGE emp_dtls_pkg AS
TYPE dept_rec_type IS RECORD(
DEPARTMENT_NAME HR.departments.DEPARTMENT_NAME%TYPE,
LOCATION_ID HR.departments.LOCATION_ID%TYPE);
TYPE emp_rec_type IS RECORD(
EMPLOYEE_ID HR.employees.EMPLOYEE_ID%TYPE,
FIRST_NAME HR.employees.FIRST_NAME%TYPE,
LAST_NAME HR.employees.LAST_NAME%TYPE,
EMAIL HR.employees.EMAIL%TYPE,
PHONE_NUMBER HR.employees.PHONE_NUMBER%TYPE,
HIRE_DATE HR.employees.HIRE_DATE%TYPE,
JOB_ID HR.employees.JOB_ID%TYPE,
SALARY HR.employees.SALARY%TYPE,
COMMISSION_PCT HR.employees.COMMISSION_PCT%TYPE);
TYPE emp_tbl_type IS TABLE OF emp_rec_type;
PROCEDURE get_emp_dtls(p_dept_number IN number,
p_dept_rec OUT emp_dtls_pkg.dept_rec_type,
p_emp_rec OUT emp_dtls_pkg.emp_tbl_type);
END emp_dtls_pkg;
-- Package Body
create or replace PACKAGE body emp_dtls_pkg IS
PROCEDURE get_emp_dtls(p_dept_number IN number,
p_dept_rec OUT emp_dtls_pkg.dept_rec_type,
p_emp_rec OUT emp_dtls_pkg.emp_tbl_type) is
begin
SELECT DEPARTMENT_NAME, LOCATION_ID
INTO p_dept_rec
FROM departments d
WHERE d.department_id = p_dept_number;
SELECT EMPLOYEE_ID,
FIRST_NAME,
LAST_NAME,
EMAIL,
PHONE_NUMBER,
HIRE_DATE,
JOB_ID,
SALARY,
COMMISSION_PCT BULK COLLECT
INTO p_emp_rec
FROM employees e
WHERE e.department_id = p_dept_number;
end get_emp_dtls;
end emp_dtls_pkg;
-- Invokeing the Package
DECLARE
l_deptrec emp_dtls_pkg.dept_rec_type;
l_emptab emp_dtls_pkg.emp_tbl_type;
p_dept_number number(5) := 20;
BEGIN
emp_dtls_pkg.get_emp_dtls(p_dept_number, l_deptrec, l_emptab);
dbms_output.put_line(l_deptrec.DEPARTMENT_NAME);
for i in l_emptab.first .. l_emptab.last loop
dbms_output.put_line(l_emptab(i).FIRST_NAME);
end loop;
END emp_dtls_pkg;
Tags: Database
Similar Questions
-
Select the query within the PL/SQL block.
Hello Experts,
I'm just a beginner with PL/SQL.
If I write a select query of client like fire against a database and SQL dev, it gives me result.
For example: select * from employee;
Now suppose that when I use the same query within a PL/SQL block:
Declare
Start
Select * from employee;
end;
/
It gives error during execution, by mentioning that an INTO should etc...
I have my doubts here:
1. is it impossible to use a simple select statement within a PL/SQL block (If yes why?)
I know it's a very basic question, I tried to search it on the forum but could not find the thread, please redirect me to the link if it is already the answer.Please read this first. may ask why?
http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/TOC.htm
-
To bulk table the PL/SQL collection
Hi all
version 10g 10.2.0.1
Can what I do to accomplish the following.
I need to build a collection based on the result of two SQL statements in a loop.
Example:
IS FUNCTION (get_info)
RETURN retrieval_pkg_public_ty
PIPELINED
TYPE ret_tab IS TABLE OF THE ret_rec;
BECAUSE me in 1... 2
LOOP
SELECT...
BULK COLLECT into ret_tbl
FROM (SELECT...
FROM (SELECT...
Quite a big SQL statement...
WHERE
x = parameter_value, - I'm from the changes of parameters to values
y = parameter_value,-I'm from the changes of parameters to values
END LOOP;
BECAUSE me IN ret_tbl. FIRST... ret_tbl. LAST
LOOP
COURSE OF ACTION...
END LOOP;
I can use a global temporary table to store the results of each loop and select TWG, but I prefer to use a table function.
Thank you
Markuser1602736 wrote:
Currently I have a procedure that is called in a package that returns a SYS_REFCURSOR.Course code of procedure is
I'm in 1.2
LOOP
INSERt INTO TWGEND LOOP;
Why not just fill the TWG using a TWG INSERT INTO SELECT... Source FROM WHERE... ?
I wanted to avoid creating a TWG to accomplish above.
Why? You do the problems with this approach TWG think there?
The cursor returns only about 50 records. The record includes data fields about 20
Don't forget that if you store it as a collection of PL/SQL (there is no such thing as PL "+ table + '), this collection resides in expensive private process memory (PGA). Is there are 100 sessions by using this code, then it will have a 100 copies of this collection.
On the other hand, a TWG does not lie in the expensive private memory. And it adapts to a 1000 lines in the future, without affecting performance (do not forget that the TWG can be indexed - not collections). For a collection, you will need to pay an excessive price in memory to keep this 1000 lines in the PGA.
TWG is not a bad thing. The collections are not a bad thing. They are tools to solve specific problems. Your task is to select the right tool for the job. Cached data line SQL in a PL/SQL collection is almost never the right tool for the job, because it requires private process memory and uses a very simplistic data structure (does not support the index and so on).
-
I have a process that creates a collection with data from several tables. The query returns multiple lines in the tab "Sql commands". The same query is used to create the collection 'Head before' and when I create a region with the source of the region as
Select * from apex_collections where collection_name = "load_dashboard";
At the time of the rendering of the page, shows me "no data found".
What could be the problem? Are there requirements before creating the collection?
Thanks in advance,
Sriram
Name of the collection must be uppercase. That's your problem.
Denes Kubicek
-------------------------------------------------------------------
http://deneskubicek.blogspot.com/
http://www.Apress.com/9781430235125
https://Apex.Oracle.com/pls/Apex/f?p=31517:1
http://www.Amazon.de/Oracle-Apex-XE-Praxis/DP/3826655494
-------------------------------------------------------------------
-
Single SQL query for the analysis of the date of customs declaration under the table of Stock codes
Dear all,
Please tell us a single SQL query for the below,
We have a Table of Stock as shown below,
STOCK_TABLE
ITEM_CODE
(item code)
BAT_NO
(lot no.)
TXN_CODE
(transaction code)
DOC_NO
(number)
BOE_DT
(date of the customs declaration)
I1
B1
I1
I2
I3
B70
I4
B80
I5
B90
T102
1234
JULY 2, 2015
I6
B100
We have to find the date of customs declaration (i.e. the date when the items have come under this particular table) for items that are not attached to any document (that is, who have TXN_CODE, DOC_NO and BOE_DT fields with a NULL value).
For each item in the table of actions, which is not attached to any document, the customs declaration date is calculated as follows.
- If (code section, lot number) combination is present under HISTORY_TABLE, the date of customs declaration will receive the UPDT_DT, the transaction code (TXN_CODE) is an IN or transactions (which can be analyzed from the TRANSACTIONS table).
- If (code section, lot number) combination is NOT currently at the HISTORY_TABLE (or) the transaction code respective to item - batch number combination code is an operation then customs declaration date will be the date of the document (DOC_DT) that we receive from one of the 3 tables IN_TABLE_HEAD that contains the element of that particular lot.
- If the case 1 and case 2 fails, our customs declaration date will be the last date of document (DOC_DT) that we receive from one of the 3 tables IN_TABLE_HEAD containing that particular item and the BAT_NO in expected results will be that corresponding to this document, as appropriate, to another NULL.
- If the case 1 or case 2 is successful, the value of the last field (in the output expected, shown further below) BATCH_YN will be 'Y', because it fits the lot. Otherwise it will be 'n'.
-
Vs. runtime vs. ViewObject ViewObject SQL query in the xml file.
Hello
I wonder what is the difference between query SQL in the long term, creating a view object in the duration and the creation of a display with an XML object.
I'm not trying to have the result set cached just to pick once.
My code for a creation of a view in a run-time object:
HashSet<Integer> allPersonIdThatUserHasAccessTo = new HashSet<Integer>(); AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl"); String sqlStr = "SELECT up.person_id FROM user_person up where up.user_id = " + userId; ViewObjectImpl vo = (ViewObjectImpl)am.createViewObjectFromQueryStmt("AllPeopleUserHasAccessToVo", sqlStr); vo.executeQuery(); RowSetIterator rsi = vo.createRowSetIterator(null); while (rsi.hasNext()) { Row personRow = rsi.next(); Integer personId = ((BigDecimal)personRow.getAttribute(0)).intValue(); allPersonIdThatUserHasAccessTo.add(personId); } rsi.closeRowSetIterator(); vo.remove();
When should I use SQL query, when the view object use at time of execution and time to create the view object to an xml file?
In general you should not write this code in a managed bean. Access code or in your case creating a VO belongs behind the façade in the module of the application.
You can create the original Version, but the main difference is that it takes more time. Code everything that the definition of VO created in the data model of the application module would make too and it clears directly after the query only to create the same code again the next time you call the method.
If the goal is not to keep the data, you can create the hashset class and call executeEmptyRowSet() on the VO (https://blogs.oracle.com/smuenchadf/entry/what_does_executeemptyrowset_d for details). This way you only need a VO that takes a parameter and gets you the same result in less time.
Timo
-
With separate SQL query and the counter is wrong.
Hello
I have another problem with a query.
The following data:
Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
And my request:CREATE TABLE TABLE_1 ( "ORDER_NR" VARCHAR2 (12) , "PRIORITY" VARCHAR2 (2) , "WO_STATUS" VARCHAR2 (1) , "STATUS_DATE" DATE , "ART_NR" VARCHAR2 (9) , "DESCRIPTION" VARCHAR2 (255) , "PRICE" VARCHAR2 (10) ); CREATE TABLE TABLE_2 ( "ART_NR" VARCHAR(9) , "MODELL" VARCHAR2(10) , "MANUFACT" VARCHAR2(20) ); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300612', '12', 'U', TO_DATE('05-FEB-13 10:22:39','DD-MON-RR HH24:MI:SS'), '005231987', '1ST ANNUAL SERVICE', '5000.2546'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300638', '05', 'U', TO_DATE('05-FEB-13 11:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '3RD ANNUAL SERVICE', '5269.7856'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300638', '12', 'U', TO_DATE('06-FEB-13 12:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '1ST BIENNIAL SERVICE', '1234.4468'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300638', '12', 'U', TO_DATE('07-FEB-13 13:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '3RD ANNUAL SERVICE', '4366.7856'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300762', '12', 'U', TO_DATE('22-FEB-13 14:55:48','DD-MON-RR HH24:MI:SS'), '018743356', '3RD ANNUAL SERVICE', '4462.8632'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300766', '12', 'U', TO_DATE('22-FEB-13 08:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '2ND ANNUAL SERVICE', '8762.6643'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300766', '05', 'U', TO_DATE('23-FEB-13 12:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '1ST BIENNIAL SERVICE', '3425.6643'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300766', '12', 'U', TO_DATE('24-FEB-13 14:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '2ND BIENNIAL SERVICE', '6678.6643'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300612', '12', 'U', TO_DATE('06-FEB-13 10:22:39','DD-MON-RR HH24:MI:SS'), '005231987', '1ST ANNUAL SERVICE', '5000.2546'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300638', '05', 'U', TO_DATE('05-FEB-13 11:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '3RD ANNUAL SERVICE', '5269.7856'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300638', '12', 'U', TO_DATE('06-FEB-13 12:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '1ST BIENNIAL SERVICE', '1234.4468'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300638', '12', 'U', TO_DATE('07-FEB-13 13:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '3RD ANNUAL SERVICE', '4366.7856'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300762', '12', 'U', TO_DATE('22-FEB-13 14:55:48','DD-MON-RR HH24:MI:SS'), '018743356', '3RD ANNUAL SERVICE', '4462.8632'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300766', '12', 'U', TO_DATE('22-FEB-13 08:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '2ND ANNUAL SERVICE', '8762.6643'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300766', '05', 'U', TO_DATE('23-FEB-13 12:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '1ST BIENNIAL SERVICE', '3425.6643'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE) VALUES ('1KKA1Z300766', '12', 'U', TO_DATE('24-FEB-13 14:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '2ND BIENNIAL SERVICE', '6678.6643'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT1'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT2'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT3'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT4'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT5'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT6'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT1'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT2'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT3'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT4'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT1'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT2'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT3'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT4'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT5'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT6'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT1'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT2'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT3'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT4'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT5'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005231987', 'X-RAY1', 'MANUFACT6'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT1'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT2'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT3'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('005667821', 'LASER', 'MANUFACT4'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT1'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT2'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT3'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT4'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT5'); INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT) VALUES ('018743356', 'VACCUM', 'MANUFACT6'); COMMIT;
And the result:SELECT T1.ART_NR , T2.MODELL , SUM(ROUND(T1.PRICE, 2)) AS TOTAL_PRICE , COUNT(*) AS QTY , TO_CHAR(T1.STATUS_DATE, 'MON-RR') AS MONTH FROM TABLE_1 T1, TABLE_2 T2 WHERE T1.WO_STATUS = 'U' AND T1.ART_NR = T2.ART_NR AND TO_CHAR(T1.STATUS_DATE, 'MON-RR') = 'FEB-13' GROUP BY T2.MODELL , T1.ART_NR , TO_CHAR(T1.STATUS_DATE, 'MON-RR')
My problem now is the OTY ist wrong field should count how many times the equipment was in service in Feb - 13 and group them by "MODEL" the production area is not interesting to me, but this is my problem, a model can have several Manufacter and so I had a bad count for my Qty.ART_NR MODELL TOTAL_PRICE QTY MONTH --------- ---------- ----------- ---------- ------ 018743356 VACCUM 559916.16 96 FEB-13 005667821 LASER 173936.48 48 FEB-13 005231987 X-RAY1 120006 24 FEB-13
The next step that I need is to group the result also by type of Service (annual or biannual), like this:
These values are only out of my head, not the table, just to show what I need.ART_NR MODELL TOTAL_PRICE QTY MONTH SERVICE_TYPE --------- ---------- ----------- ---------- ------ --------------------- 018743356 VACCUM 1234.56 4 FEB-13 ANNUAL 018743356 VACCUM 4423.48 10 FEB-13 BIENNIAL 005667821 LASER 4783.11 2 FEB-13 ANNUAL 005667821 LASER 1123.77 22 FEB-13 BIENNIAL 005231987 X-RAY1 8966.12 6 FEB-13 ANNUAL 005231987 X-RAY1 7826.44 12 FEB-13 BIENNIAL
Thanks for your help.
Hosts ReinhardHello
990524 wrote:
HelloWow it's great.
Thanks Frank.In my database, this query works like a charm, but I have a problem, sometimes the round command do not work then I get a total price of 1231.0000000000001, I
tried of TRUNCATES the value, but it's always the same value.Sorry, I can not re - create the problem.
And I put another line in the query that calculates the average price per model:
, ROUND ( SUM (g.price) / COUNT(*) ,2 ) AS average
Why not just
, ROUND (AVG (g.price), 2) AS average
?
and in this line, I have the same problem with bad ROUNDS.
Do you have an idea in this case?
No, sorry. If I can't get the same behavior, myself, it is not that I do.
Instead of ROUND, you can use TO_CHAR to (for example) display 2 digits after the decimal point. To_char will automatically round the result. Your front end (for example, the SQL * Plus COLUMN...) FORMAT command) can probably do the same thing.
-
Hi team,
For example if I have a demo table with 4 columns (A, B, C, D) DEMO.
I want a report on this table, such that the report contains the headers and the Details section.
For each unique combination of (A, B) I must first of all show header based on the header information I want to display the detailed section.
In my header section I want to display 2 columns (A, B) that are common to the detailed section. Remaining 2 columns in the detailed section.
Here is an example: -.
A B C D
1 5 9 3
1 5P8
1 5 P O
1-5-9
1 8 9
1 D * /
2 8 33 P
2 P O O
2 P L L
YOU WILL SEE
A AND B
1 5
C D
9 3
P 8
P O
A AND B
1 D
C D
5 9
8 9
* /
A AND B
2 P
C D
8 33
O O
L L
Please suggest the solution (sql query) for above the problem and how to nest gernerated headers dynamically in the report area.
I use APEX 4.0
Any position in this regard is very significant.
Thanks and greetings
RajendraTry this:
SQL> select * from tab; 1 5 9 3 1 5 P 8 1 5 P O 1 D 5 9 1 D 8 9 1 P 8 3 1 P O O 7 rows selected. SQL> select a,b from (select r,a,b from ( select to_char(rownum)||'a' r, 'A' a,'B' b from (select distinct a, b from tab order by a,b)) union ( select to_char(rownum)||'c' r, 'C' c,'D' d from (select distinct a, b from tab order by a,b)) union ( select to_char(rownum)||'b' r, a,b from (select distinct a, b from tab order by a,b)) union select parent.r, tab.c, tab.d from ( select to_char(rownum)||'d' r, a,b from (select distinct a, b from tab order by a,b)) parent , tab where parent.a=tab.a and parent.b=tab.b ) order by r ; A B 1 5 C D 9 3 P 8 P O A B 1 D C D 5 9 8 9 A B 1 P C D 8 3 O O
-
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,
-
Dynamic SQL query in the DB adapter
Hello
I want to use the following custom SQL query in the DB adapter:
SELECT EMP_ID, EMP_NAME, EMP_LOCATION FROM EMP WHERE EMP_ID IN (#iNPUT_PARAMETER)
the problem I'm facing is that I don't know at the time of the development that EMP_ID how much will be passed to the process so that I can not use the input parameter specific number. I cannot use it IN the query within which statement I concatenate all the EMP_ID separated by comma and passed under INPUT_PARAMETER, but when running, he read the full concatenated string as a single string rather than identify them as a list of different: with comma separation. could someone help me in this case
Thank you
SunilUse the following query with two parameters. Build the string with delimiter when running and pass this string and delimiter to query... (in this example, the input value would be the same for both Delimiter1 and Delimiter2.)
Select * from EMP WHERE deptno IN (SELECT SUBSTR (STRING_TO_TOKENIZE, DECODE (LEVEL, 1, 1, INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL-1) + 1), INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL)-DECODE (LEVEL, 1, 1, INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL-1) + 1)) FROM (SELECT #StringToTokenizer | #Delimiter1 AS STRING_TO_TOKENIZE, #Delimiter2 AS DELIMITER FROM DUAL) CONNECT BY INSTR (STRING_TO_TOKENIZE SEPARATOR) ((, 1, LEVEL) > 0)
Thank you
-Sreeny -
SQL query to avoid the PL/SQL
Hello
I'm doing below pl/sql block in a single stm SQL, let me know how could achieve us.
Here I use SELECT * FROM TEMP_ORDER WHERE DB_NAME = V_DBNAME which runs a cursor to get the separate database names.
This V_DBNAME could be avoided? and put everything in a single SQL?
(The PL/SQL block is not running properly because several rows are returned) I would be interested in the SQL solution.
create table TEMP_ORDER ( ORD1 VARCHAR2(25), ORD2 VARCHAR2(25), DB_NAME VARCHAR2(25) ) INSERT INTO TEMP_ORDER(ORD1,ORD2,DB_NAME) VALUES('A1','FIRST ORDER','DB1'); INSERT INTO TEMP_ORDER(ORD1,ORD2,DB_NAME) VALUES('A2','SECOND ORDER','DB2'); INSERT INTO TEMP_ORDER(ORD1,ORD2,DB_NAME) VALUES('A3','THIRD ORDER','DB1'); create table TEMP_PAYMENT ( PAY1 VARCHAR2(25), PAY2 VARCHAR2(25), DB_NAME VARCHAR2(25) ) INSERT INTO TEMP_PAYMENT(PAY1,PAY2,DB_NAME) VALUES('A1','FIRST PAYMENT','DB1'); INSERT INTO TEMP_PAYMENT(PAY1,PAY2,DB_NAME) VALUES('A2','SECOND PAYMENT','DB2'); INSERT INTO TEMP_PAYMENT(PAY1,PAY2,DB_NAME) VALUES('A3','THIRD PAYMENT','DB1'); create table TEMP_DELIVER ( DEL1 VARCHAR2(25), DEL2 VARCHAR2(25), DB_NAME VARCHAR2(25) ) INSERT INTO TEMP_DELIVER(DEL1,DEL2,DB_NAME) VALUES('A1','FIRST DELIVER','DB1'); INSERT INTO TEMP_DELIVER(DEL1,DEL2,DB_NAME) VALUES('A2','SECOND DELIVER','DB2'); INSERT INTO TEMP_DELIVER(DEL1,DEL2,DB_NAME) VALUES('A3','THIRD DELIVER','DB1'); --------------------------------- DECLARE V_DBNAME TEMP_ORDER.DB_NAME%TYPE; V_ORDER_NAME TEMP_ORDER.ORD2%TYPE; V_PAYMENT_NAME TEMP_PAYMENT.PAY2%TYPE; V_DELIVER_NAME TEMP_DELIVER.DEL2%TYPE; CURSOR DBCURSOR IS SELECT UNIQUE DB_NAME from TEMP_ORDER; BEGIN IF NOT DBCURSOR%ISOPEN THEN OPEN DBCURSOR; END IF; LOOP FETCH DBCURSOR INTO V_DBNAME; EXIT WHEN DBCURSOR%NOTFOUND; SELECT A.ORD2, B.PAY2, C.DEL2 INTO V_ORDER_NAME,V_PAYMENT_NAME,V_DELIVER_NAME FROM (SELECT * FROM TEMP_ORDER WHERE DB_NAME = V_DBNAME)A, (SELECT * FROM TEMP_PAYMENT WHERE DB_NAME = V_DBNAME)B, (SELECT * FROM TEMP_DELIVER WHERE DB_NAME = V_DBNAME)C WHERE A.ORD1 = B.PAY1 AND B.PAY1 = C.DEL1; DBMS_OUTPUT.put_line(V_ORDER_NAME || ':' || V_PAYMENT_NAME || ':' || V_DELIVER_NAME); END LOOP; CLOSE DBCURSOR; END;
Hello
Do you mean something like this?
SELECT a.db_name, a.ord2 || ':' || b.pay2 || ':' || c.del2 string FROM TEMP_ORDER A, TEMP_PAYMENT B, TEMP_DELIVER C WHERE A.ORD1 = B.PAY1 AND B.PAY1 = C.DEL1 AND a.db_name = b.db_name AND b.db_name = c.db_name; DB_NAME STRING ------- ------------------------------------------ DB1 FIRST ORDER:FIRST PAYMENT:FIRST DELIVER DB2 SECOND ORDER:SECOND PAYMENT:SECOND DELIVER DB1 THIRD ORDER:THIRD PAYMENT:THIRD DELIVER
I hope this helps.
Kind regards.
-
Different plan for the same sql id
Hello
Our team of application reported recently that a query ran longer than usual.
Search in tables AWR (dba_hist_active_sess_history & dba_hist_sqlstat), it was a change of plan_hash_value. The next day, without intervention from anyone (collect statistics did not run, no change in the tables involved) the sql used the former plan and completed quickly.
The differences in the plan was the index that was used to access the table.
What could be the reason for the optimizer to choose a bad plan and return once more the good thing. ?
The code sql that has been run twice & three in one day and then it years off cursor cache.
Regime shifts are normal.
Flipfloppping plans are quite normal.
I'd be willing to bet that a large percentage of your SQL shows variations in implementation plans and you never notice.
And there are several reasons why you might get a different plan.
1 bind variable peeking - it is normal SQL for the age from the cache and then get analyzed once again with different bind variable leading to different cardinality estimates and plans
2. the statistics change - it is normal that the statistics of change over time causing different cardinality estimates and the various plans, especially if the histograms are involved and changing buckets
3. data change - especially if you use dynamic sampling it is normal to get a different sample of data leading to different cardinality estimates and plans
4 SYSDATE - it's normal for queries with SYSDATE in them to recognize that time is never on leave and which, in conjunction with statistics or data, can lead to different cardinality estimates and plans
5. integrated optimization features - it's normal for features like ACS to kick in and notice that they got forecasts wrong in an execution plan and force the recalculation to a different plan with an adjusted cardinality.
Using DBMS_XPLAN. DISPLAY_CURSOR or DISPLAY_AWR you can get different plans (provided that they are in memory or AWR). The notes section should indicate cardinality comments have been a factor. You can also get links peeked with format mask of "+ PEEKED_BINDS".
-
Trouble with the adapter SQL Loader
Hi all
I'm trying to sue the adapter SQL Loader to collect my SQL server instance performance statistics. I followed the instructions in Appendix A of this document: https://www.vmware.com/files/pdf/solutions/Monitoring-Business-Critical-Applications-VMware-vCenter-Operations-Manager-white-paper.pdf
Our environment is one vCOps 5.8 vCloud Suite Enterprise license licensed. SQL server SQL 2008 R2 and is reasonably up-to-date on patches, etc. (CUA8, I think)
I've gotten to the point where the database is logged in and my query is running, but it seems that the values returned by the query correspond to default values (0). I don't know why this is happening, but because the newspapers seem to show the actual values from the database:
2014-02-10 17:29:50, 438 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - #SELECT "SQL LOADER" ADAPTERKIND, query
"SQL Server PERFMON STATS" RESOURCEKIND,.
GETUTCDATE() TIMESTAMP,
'Agent' RESOURCEKIND,
"SVC-mgmt-sql SQL Server" RESOURCENAME,.
(LTRIM (RTRIM (replace ([parameter], ':', '-'))) + "|" + counter_name) METRICNAME1,
Sum (cntr_value) VALUE1
FROM sys.dm_os_performance_counters
WHERE
(GETUTCDATE() > = (CONVERT (datetime, ' 02/10/2014 17:9:0 ', 101))) AND
(' 01 / 01/2000 ' < (CONVERT (datetime, ' 02/10/2014-17:29:50 ', 101))) AND
counter_name in)
"User connections"
"Compilations SQL/s."
"SQL Recompilations/sec."
"Server memory target (KB)"
"Total server memory (KB)"
"Scriptures delayed/s."
"Checkpoint pages/sec.
"Page life expectancy."
'Memory waiting requests',
"IO Page lock expects."
"Wait worker."
"Writing waiting to connect."
"IO expects network")
GROUP BY (LTRIM (RTRIM (replace ([parameter], ':', '-'))) + "|" + counter_name)
ORDER OF TIMESTAMP
2014-02-10 17:29:50, 467 com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB DEBUG [Collector worker thread 8] (20583) - try to connect...
2014-02-10 17:29:50, 478 com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB DEBUG [Collector worker thread 8] (20583) - connected...
2014-02-10 17:29:50, 490 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - QueryExecutionTime = 12
2014-02-10 17:29:50, 509 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - strMetricCount = 0
2014-02-10 17:29:50, 533 DEBUG [Collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.getResourceKeyFromResultSet (20583) - work on resource: SVC - mgmt - sql SQL Server
2014-02-10 17:29:50, 538 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.isResourceRenameAllowed - rename audit allowed for resource key {resourceName = SVC - mgmt - sql SQL Server & adapterKindKey = SQL LOADER & resourceKindKey = SQL Server PERFORMANCE Monitor STATS}
2014-02-10 17:29:50, 571 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - resource of treatment: SVC-mgmt-sql SQL Server extract the metric values are 12921
2014-02-10 17:29:50, 612 DEBUG [Collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.getResourceKeyFromResultSet (20583) - work on resource: SVC - mgmt - sql SQL Server
2014-02-10 17:29:50, 624 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.isResourceRenameAllowed - rename audit allowed for resource key {resourceName = SVC - mgmt - sql SQL Server & adapterKindKey = SQL LOADER & resourceKindKey = SQL Server PERFORMANCE Monitor STATS}
2014-02-10 17:29:50, 624 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - resource of treatment: SVC-mgmt-sql SQL Server extract the metric values are 10
2014-02-10 17:29:50, 626 DEBUG [Collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.getResourceKeyFromResultSet (20583) - work on resource: SVC - mgmt - sql SQL Server
2014-02-10 17:29:50, 626 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.isResourceRenameAllowed - rename audit allowed for resource key {resourceName = SVC - mgmt - sql SQL Server & adapterKindKey = SQL LOADER & resourceKindKey = SQL Server PERFORMANCE Monitor STATS}
2014-02-10 17:29:50, 626 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - resource of treatment: SVC-mgmt-sql SQL Server extract the metric values are 72869
2014-02-10 17:29:50, 626 DEBUG [Collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.getResourceKeyFromResultSet (20583) - work on resource: SVC - mgmt - sql SQL Server
2014-02-10 17:29:50, 626 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.isResourceRenameAllowed - rename audit allowed for resource key {resourceName = SVC - mgmt - sql SQL Server & adapterKindKey = SQL LOADER & resourceKindKey = SQL Server PERFORMANCE Monitor STATS}
2014-02-10 17:29:50, 626 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - resource of treatment: SVC-mgmt-sql SQL Server extract the metric values are 17
2014-02-10 17:29:50, 627 DEBUG [Collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.getResourceKeyFromResultSet (20583) - work on resource: SVC - mgmt - sql SQL Server
2014-02-10 17:29:50, 627 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.isResourceRenameAllowed - rename audit allowed for resource key {resourceName = SVC - mgmt - sql SQL Server & adapterKindKey = SQL LOADER & resourceKindKey = SQL Server PERFORMANCE Monitor STATS}
2014-02-10 17:29:50, 627 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - resource of treatment: SVC-mgmt-sql SQL Server extract the metric values are 72869
2014-02-10 17:29:50, 627 DEBUG [Collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.getResourceKeyFromResultSet (20583) - work on resource: SVC - mgmt - sql SQL Server
2014-02-10 17:29:50, 628 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.isResourceRenameAllowed - rename audit allowed for resource key {resourceName = SVC - mgmt - sql SQL Server & adapterKindKey = SQL LOADER & resourceKindKey = SQL Server PERFORMANCE Monitor STATS}
2014-02-10 17:29:50, 628 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - resource of treatment: SVC-mgmt-sql SQL Server extract the metric values are 10644
2014-02-10 17:29:50, 628 DEBUG [Collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.getResourceKeyFromResultSet (20583) - work on resource: SVC - mgmt - sql SQL Server
2014-02-10 17:29:50, 628 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.isResourceRenameAllowed - rename audit allowed for resource key {resourceName = SVC - mgmt - sql SQL Server & adapterKindKey = SQL LOADER & resourceKindKey = SQL Server PERFORMANCE Monitor STATS}
2014-02-10 17:29:50, 628 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - resource of treatment: SVC-mgmt-sql SQL Server extract the metric values are 77
2014-02-10 17:29:50, 629 DEBUG [Collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.getResourceKeyFromResultSet (20583) - work on resource: SVC - mgmt - sql SQL Server
2014-02-10 17:29:50, 629 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.isResourceRenameAllowed - rename audit allowed for resource key {resourceName = SVC - mgmt - sql SQL Server & adapterKindKey = SQL LOADER & resourceKindKey = SQL Server PERFORMANCE Monitor STATS}
2014-02-10 17:29:50, 629 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - resource of treatment: SVC-mgmt-sql SQL Server extract the metric values are 0
2014-02-10 17:29:50, 629 DEBUG [Collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.getResourceKeyFromResultSet (20583) - work on resource: SVC - mgmt - sql SQL Server
2014-02-10 17:29:50, 629 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.isResourceRenameAllowed - rename audit allowed for resource key {resourceName = SVC - mgmt - sql SQL Server & adapterKindKey = SQL LOADER & resourceKindKey = SQL Server PERFORMANCE Monitor STATS}
2014-02-10 17:29:50, 630 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - resource of treatment: SVC-mgmt-sql SQL Server extract the metric values are 425692
2014-02-10 17:29:50, 630 DEBUG [Collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.getResourceKeyFromResultSet (20583) - work on resource: SVC - mgmt - sql SQL Server
2014-02-10 17:29:50, 630 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.isResourceRenameAllowed - rename audit allowed for resource key {resourceName = SVC - mgmt - sql SQL Server & adapterKindKey = SQL LOADER & resourceKindKey = SQL Server PERFORMANCE Monitor STATS}
2014-02-10 17:29:50, 630 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - resource of treatment: SVC-mgmt-sql SQL Server extract the metric values are 11747062
2014-02-10 17:29:50, 630 DEBUG [Collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.getResourceKeyFromResultSet (20583) - work on resource: SVC - mgmt - sql SQL Server
2014-02-10 17:29:50, 631 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.isResourceRenameAllowed - rename audit allowed for resource key {resourceName = SVC - mgmt - sql SQL Server & adapterKindKey = SQL LOADER & resourceKindKey = SQL Server PERFORMANCE Monitor STATS}
2014-02-10 17:29:50, 631 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - resource of treatment: SVC-mgmt-sql SQL Server extract the metric values are 29360128
2014-02-10 17:29:50, 631 DEBUG [Collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.getResourceKeyFromResultSet (20583) - work on resource: SVC - mgmt - sql SQL Server
2014-02-10 17:29:50, 631 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.isResourceRenameAllowed - rename audit allowed for resource key {resourceName = SVC - mgmt - sql SQL Server & adapterKindKey = SQL LOADER & resourceKindKey = SQL Server PERFORMANCE Monitor STATS}
2014-02-10 17:29:50, 631 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - resource of treatment: SVC-mgmt-sql SQL Server extract the metric values are 29360128
2014-02-10 17:29:50, 632 DEBUG [Collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.getResourceKeyFromResultSet (20583) - work on resource: SVC - mgmt - sql SQL Server
2014-02-10 17:29:50, 632 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.isResourceRenameAllowed - rename audit allowed for resource key {resourceName = SVC - mgmt - sql SQL Server & adapterKindKey = SQL LOADER & resourceKindKey = SQL Server PERFORMANCE Monitor STATS}
2014-02-10 17:29:50, 632 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - resource of treatment: SVC-mgmt-sql SQL Server extract the metric values are 0
2014-02-10 17:29:50, 632 DEBUG [Collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB (20583) - number of records processed 13 - used memory (MB): free Mem in 1757 (Mo): 1104
2014-02-10 17:29:50, 632 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.getDataFromDB - for request #= "SQL LOADER' SELECT ADAPTERKIND,.
"SQL Server PERFMON STATS" RESOURCEKIND,.
GETUTCDATE() TIMESTAMP,
'Agent' RESOURCEKIND,
"SVC-mgmt-sql SQL Server" RESOURCENAME,.
(LTRIM (RTRIM (replace ([parameter], ':', '-'))) + "|" + counter_name) METRICNAME1,
Sum (cntr_value) VALUE1
FROM sys.dm_os_performance_counters
WHERE
(GETUTCDATE() > = %f)) AND
(' 01 / 01/2000 ' < %t)) AND
counter_name in)
"User connections"
"Compilations SQL/s."
"SQL Recompilations/sec."
"Server memory target (KB)"
"Total server memory (KB)"
"Scriptures delayed/s."
"Checkpoint pages/sec.
"Page life expectancy."
'Memory waiting requests',
"IO Page lock expects."
"Wait worker."
"Writing waiting to connect."
"IO expects network")
GROUP BY (LTRIM (RTRIM (replace ([parameter], ':', '-'))) + "|" + counter_name)
ORDER OF TIMESTAMP
RecordCount = 13 FilteredRecordCount = 0
2014-02-10 17:29:50, 632 DEBUG [Collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.addDefaultData - Default Metrics size after a data loop = 13
2014-02-10 17:29:50, 633 INFO [collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.addDefaultData - number of default values for this piece of data = 13
2014-02-10 17:29:50, 633 INFO [collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.DataReader.read - 26 returned query parameters
2014-02-10 17:29:50, 634 INFO [collector worker thread 8] com.integrien.adapter3.generalsqldataloader.DataReader.updateResourceTimeMapAndRemoveDuplicates (20583) - 26 data 0 resource comments who have been sent the last time.
2014-02-10 17:29:50, 634 INFO [collector worker thread 8] (20583) com.integrien.adapter3.generalsqldataloader.GeneralSQLDataLoaderAdapter.groupByResource - grouping of resources
2014-02-10 17:29:50, 634 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 634 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 634 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 634 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 634 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 634 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 634 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 634 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 635 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 635 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 635 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 635 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 635 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 635 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 635 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 635 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 635 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 635 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 636 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 636 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 636 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 636 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 636 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 636 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 636 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2014-02-10 17:29:50, 636 DEBUG [Collector worker thread 8] (20583) com.integrien.alive.common.adapter3.AdapterBase.addMetricData - 1 added metrics to collect the result for the "SVC - mgmt - sql SQL Server" resource, resId = 20584, adapter "GeneralSQLDataLoaderAdapter".
2
Has anyone out there dealt with this or found a way around this kind of problem? There only seems to be a lot of information regarding the use of this (or of the) adapters.
Thank you
Jason
IS to use the option you gave.
Looks like that time is not the same timezone between solutions if he just started working after 5 to 6 hours. Make sure you that you don't need to use a different zone such as GMT.
-
AWR report cannot locate the bad SQLs
DB version: 11.2.0.2
Platform: Solaris 10
In our data base RAC 2 nodes, we have patterns of 20 applications. When an application is faced with performance problems, we try to generate AWR for the period in question. But the stats (like bad SQLs) for this scheme to be buried because there is another application SQLs performing even worse.
I know that we cannot create AWR report for specific patterns. But I wonder how his stats are collected in a multi-schema RAC environments that will differentiate between applications.But the stats (like bad SQLs) for this scheme to be buried because there is another application SQLs performing even worse.
Since all applications run in a database and query of the other application run bad then they will be the first candidate of tunning since these are taking more resources and impact on other application requests.
You can also generate report of ASH for module specific or customer with assistance from under the option set in report of ash.set target_module_name = ";
set target_action_name = ";
set target_client_id = "; -
PL/SQL, Collection and email 'question '.
Hi all
I'm spending external monitoring scripts to internal procedures or packages.
In this specific case, I create a procedure (it can be a lot, but I started to test it as a procedure) that checks free space on storage space (the percentage estimate).
Everything works fine but...
I want to send the result set to my email account (in the body of the message, not as an attachment.). So, first, I used the following code:
The problem with that I get an email for each tablespace from the list (if I don't make a mistake, this behavior is because I make a loop of sending an email for each row in the cursor).create or replace PROCEDURE TBSALERT AS tbs VARCHAR(100); per NUMBER; conn utl_smtp.connection; v_From VARCHAR2(80) := '[email protected]'; v_Recipient VARCHAR2(80) := '[email protected]'; v_Subject VARCHAR2(80) := 'TBS Status'; v_Mail_Host VARCHAR2(30) := 'smtp.domain.com.com'; CURSOR tbs_alertc IS SELECT A.tablespace_name "Tablespace", trunc(b.free/A.total*100) "Free %" FROM (SELECT tablespace_name,sum(bytes)/1024/1024 total FROM sys.dba_data_files where tablespace_name not like 'UNDO%' GROUP BY tablespace_name) A,(SELECT tablespace_name,sum(bytes)/1024/1024 free FROM sys.dba_free_space where tablespace_name not like 'UNDO%' GROUP BY tablespace_name) B WHERE A.tablespace_name=b.tablespace_name; BEGIN OPEN tbs_alertc; LOOP FETCH tbs_alertc INTO tbs,per; EXIT WHEN tbs_alertc%NOTFOUND; conn := UTL_SMTP.OPEN_CONNECTION(v_Mail_Host); UTL_SMTP.HELO(conn, v_Mail_Host); UTL_SMTP.MAIL(conn, v_From); UTL_SMTP.RCPT(conn, v_Recipient); UTL_SMTP.OPEN_DATA(conn); UTL_SMTP.WRITE_DATA(conn, UTL_TCP.CRLF ||'Alerta TBS: '||tbs|| ' Free%: '||per); DBMS_OUTPUT.PUT_LINE('Alerta TBS :'||tbs||' Percent :'||per); UTL_SMTP.CLOSE_DATA(conn); UTL_SMTP.QUIT(conn); END LOOP; CLOSE tbs_alertc; END; /
So, I think that "I must use a PL/SQL collection", but, unfortunately, I am not able to solve my 'problem '.
This is the code with I was playing around:
Somethings to notice:create or replace PROCEDURE TBSALERTNEW AS TYPE tbslst IS TABLE OF SPACESTATUS_VW.TABLESPACE%TYPE; TYPE perlst IS TABLE OF SPACESTATUS_VW.Free%TYPE; CURSOR c1 IS SELECT TABLESPACE, FREE from SPACESTATUS_VW; tbs tbslst; per perlst; TYPE spacestlst IS TABLE OF c1%ROWTYPE; spacest spacestlst; conn utl_smtp.connection; v_From VARCHAR2(80) := '[email protected]'; v_Recipient VARCHAR2(80) := '[email protected]'; v_Subject VARCHAR2(80) := 'TBS Status'; v_Mail_Host VARCHAR2(30) := 'smtp.domain.com'; PROCEDURE print_results IS BEGIN -- dbms_output.put_line('Results:'); IF tbs IS NULL OR tbs.COUNT = 0 THEN RETURN; -- Don't print anything if collections are empty. END IF; FOR i IN tbs.FIRST .. tbs.LAST LOOP dbms_output.put_line(' i Tablespace: ' || tbs(i) || ' Free %:' || per(i)); END LOOP; END; BEGIN dbms_output.put_line('--- Processing all results at once ---'); OPEN c1; FETCH c1 BULK COLLECT INTO tbs, per; CLOSE c1; print_results; dbms_output.put_line('--- Fetching records rather than columns ---'); OPEN c1; FETCH c1 BULK COLLECT INTO spacest; FOR i IN spacest.FIRST .. spacest.LAST LOOP -- Now all the columns from the result set come from a single record. dbms_output.put_line(' h Tablespace ' || spacest(i).TABLESPACE || ' Free %: ' || spacest(i).Free); END LOOP; END;
a. This code is not exactly mine, she is part of an Oracle example (I thought it should be easier to play with something that worked).
b. I created a display from the query in the first procedure, in order to facilitate the work on the second procedure.
c. when debug you the code, it works fine.
d I don't know where (or how) to use the UTL_SMTP part to send the complete set of results in the body of the email.
e. I am company running Oracle 10.2.0.4 on Linux x86_64
Any help will be appreciated.
Thanks in advance.>
So I think that "I have to use a collection of PL/SQL.
>
Why? Simply create a long string with a line for each table space. Add a newline at the end of each line.
What makes a string body.Create VARCHAR2 (32000);
The loop allows you to add a line for each table space.
Easy to use a PL/SQL table.
HISTORY_TABLE
ITEM_CODE | BAT_NO |
TXN_CODE
DOC_NO
UPDT_DT
I1
B1
T1
1234
JANUARY 3, 2015
I1
B20
T20
4567
MARCH 3, 2015
I1
B30
T30
7890
FEBRUARY 5, 2015
I2
B40
T20
1234
JANUARY 1, 2015
TRANSACTION
TXN_CODE | TXN_TYPE |
T1 | IN |
T20 |
OFF
T30
ALL THE
T50
IN
T80
IN
T90
IN
T60
ALL THE
T70
ALL THE
T40
ALL THE
IN_TABLE_HEAD_1
H1_SYS_ID (primary key) | TXN_CODE | DOC_NO |
DOC_DATE
H1ID1
T1
1234
JANUARY 1, 2015
H1ID2
T70
1234
FEBRUARY 1, 2015
IN_TABLE_ITEM_1
I1_SYS_ID |
H1_SYS_ID
(foreign key referencing H1_SYS_ID in IN_TABLE_HEAD_1)
ITEM_CODE
I1ID1
H1ID1
I1
I1ID2
H1ID1
I100
I1ID3
H1ID2
I3
IN_TABLE_BATCH_1
B1_SYS_ID | TXN_CODE DOC_NO (now in IN_TABLE_HEAD_1) | BAT_NO |
B1ID1
T1
1234
B1 / can be empty
B1ID2
T70
1234
B70
IN_TABLE_HEAD_2
H2_SYS_ID (primary key) | TXN_CODE |
DOC_NO
DOC_DATE
H2ID1
T30
4567
FEBRUARY 3, 2015
H2ID2
T60
1234
JANUARY 3, 2015
IN_TABLE_ITEM_2
I2_SYS_ID | H2_SYS_ID (foreign key referencing H2_SYS_ID in IN_TABLE_HEAD_2) | ITEM_CODE |
I2ID1 | H2ID1 |
I1
I2ID2
H2ID1
I200
I2ID3
H2ID2
I2
IN_TABLE_BATCH_2
B2_SYS_ID |
I2_SYS_ID
(foreign key referencing I2_SYS_ID in IN_TABLE_ITEM_2)
BAT_NO
B2ID1
I2ID1
B30 / null
B2ID2
I2ID2
B90
B2ID2
I2ID3
B60
IN_TABLE_HEAD_3
H3_SYS_ID (primary key) | TXN_CODE | DOC_NO | DOC_DATE |
H3ID1 |
T50
1234
JANUARY 2, 2015
H3ID2
T80
1234
JANUARY 3, 2015
H3ID3
T90
1234
JANUARY 4, 2015
H3ID4
T40
1234
AUGUST 5, 2015
IN_TABLE_ITEM_3
I3_SYS_ID |
H3_SYS_ID
(foreign key referencing H3_SYS_ID in IN_TABLE_HEAD_3)
ITEM_CODE
BAT_NO
I3ID1
H31D1
I2
B50
I3ID2
H3ID2
I4
B40
I3ID3
H3ID3
I4
I3ID4
H3ID4
I6
There is no IN_TABLE_BATCH_3
Please find below the expected results.
OUTPUT
ITEM_CODE | BAT_NO | TXN_CODE | DOC_NO |
BOE_DT
BATCH_YN
I1
B1
T1
1234
JANUARY 3, 2015
THERE
I1
B30
T30
7890
FEBRUARY 5, 2015
N
I2
B60
T60
1234
JANUARY 3, 2015
N
I3
B70
T70
1234
FEBRUARY 1, 2015
THERE
I4
T90
1234
JANUARY 4, 2015
N
I6
T40
1234
AUGUST 5, 2015
N
Controls database to create the tables above and insert the records.
CREATE TABLE stock_table()item_code VARCHAR2()80),bat_no VARCHAR2()80),txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), boe_dt DATE );
INSERT EN stock_table
VALUES ('I1', 'B1', '', '', '');
INSERT EN stock_table
VALUES ('I1', '', '', '', '');
INSERT IN stock_table
VALUES ('I2', '', '', '', '');
INSERT EN stock_table
VALUES ('I3', 'B70', '', '', '');
INSERT EN stock_table
VALUES ('I4', 'B80', '', '', '');
INSERT EN stock_table
VALUES ('I5', 'B90', 'T102', '1234', '02-JUL-2015');
INSERT EN stock_table
VALUES ('I6', 'B100', '', '', '');
SELECT *
FROM stock_table
CREATE TABLE history_table()item_code VARCHAR2()80),bat_no VARCHAR2()80),txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), updt_dt DATE );
INSERT IN history_table
VALUES ('I1', 'B1', 'T1', '1234', '03-JAN-2015');
INSERT IN history_table
VALUES ('I1', 'B20', 'T20', '4567', '03-MAR-2015');
INSERT IN history_table
VALUES ('I1', 'B30', 'T30', '7890', '05-FEB-2015');
INSERT IN history_table
VALUES ('I2', 'B40', 'T20', '1234', '01-JAN-2015');
SELECT *
FROM history_table
CREATE TABLE transaction1()txn_code VARCHAR()80),txn_type VARCHAR()80));
INSERT INTO transaction1
VALUES ('T1', 'IN');
INSERT INTO transaction1
VALUES ('T20', 'OUT');
INSERT INTO transaction1
VALUES ('T30', 'ALL');
INSERT INTO transaction1
VALUES ('T40', 'ALL');
INSERT INTO transaction1
VALUES ('T50', 'IN');
INSERT INTO transaction1
VALUES ('T60', 'ALL');
INSERT INTO transaction1
VALUES ('T70', 'ALL');
INSERT INTO transaction1
VALUES ('T80', 'IN');
INSERT INTO transaction1
VALUES ('T90', 'IN');
SELECT *
FROM transaction1
CREATE TABLE in_table_head_1()h1_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), doc_dt DATE );
CREATE TABLE in_table_head_2()h2_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), doc_dt DATE );
CREATE TABLE in_table_head_3()h3_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), doc_dt DATE );
INSERT IN in_table_head_1
VALUES ('H1ID1', 'T1', '1234', '01-JAN-2015');
INSERT IN in_table_head_1
VALUES ('H1ID2', 'T70', '1234', '01-FEB-2015');
INSERT IN in_table_head_2
VALUES ('H2ID1', 'T30', '4567', '03-FEB-2015');
INSERT IN in_table_head_2
VALUES ('H2ID2', 'T60', '1234', '03-JAN-2015');
INSERT IN in_table_head_3
VALUES ('H3ID1', 'T50', '1234', '02-JAN-2015');
INSERT IN in_table_head_3
VALUES ('H3ID2', 'T80', '1234', '03-JAN-2015');
INSERT IN in_table_head_3
VALUES ('H3ID3', 'T90', '1234', '05-JAN-2015');
INSERT IN in_table_head_3
VALUES ('H3ID4', 'T40', '1234', '05-AUG-2015');
CREATE TABLE in_table_item_1()i1_sys_id VARCHAR2()80) PRIMARY KEY,
h1_sys_id VARCHAR2 (80) REFERENCES in_table_head_1()h1_sys_id),item_code VARCHAR2()80));
CREATE TABLE in_table_item_2()i2_sys_id VARCHAR2()80) PRIMARY KEY,
h2_sys_id VARCHAR2 (80) REFERENCES in_table_head_2()h2_sys_id),item_code VARCHAR2()80));
CREATE TABLE in_table_item_3(i3_sys_id VARCHAR2(80) PRIMARY KEY,
h3_sys_id VARCHAR2 (80) REFERENCES in_table_head_3()h3_sys_id),item_code VARCHAR2()80),
bat_no VARCHAR2 (80));
INSERT IN in_table_item_1
VALUES ('I1ID1', 'H1ID1', 'I1');
INSERT IN in_table_item_1
VALUES ('I1ID2', 'H1ID1', 'I100');
INSERT IN in_table_item_1
VALUES ('I1ID3', 'H1ID2', 'I3');
INSERT IN in_table_item_2
VALUES ('I2ID1', 'H2ID1', 'I1');
INSERT IN in_table_item_2
VALUES ('I2ID2', 'H2ID1', 'I200');
INSERT IN in_table_item_2
VALUES ('I2ID3', 'H2ID2', 'I2');
INSERT IN in_table_item_3
VALUES ('I3ID1', 'H3ID1', 'I2','B50');
INSERT IN in_table_item_3
VALUES ('I3ID2', 'H3ID2', 'I4','B40');
INSERT IN in_table_item_3
VALUES ('I3ID3', 'H3ID3', 'I4','');
INSERT IN in_table_item_3
VALUES ('I3ID4', 'H3ID4', 'I6','');
SELECT *
FROM in_table_item_1
SELECT *
FROM in_table_item_2
SELECT *
FROM in_table_item_3
CREATE TABLE in_table_batch_1()b1_sys_id VARCHAR2()80) PRIMARY KEY,
txn_code VARCHAR2 (80), doc_no VARCHAR2 (80), bat_no VARCHAR2 (80));
CREATE TABLE in_table_batch_2()b2_sys_id VARCHAR2()80) PRIMARY KEY,
i2_sys_id VARCHAR2 (80) REFERENCES in_table_item_2()i2_sys_id),bat_no VARCHAR2()80));
INSERT IN in_table_batch_1
VALUES ('B1ID1', 'T1', '1234', 'B1');
INSERT IN in_table_batch_1
VALUES ('B1ID2', 'T70', '1234', 'B70');
INSERT IN in_table_batch_2
VALUES ('B2ID1', 'I2ID1', 'B30');
INSERT IN in_table_batch_2
VALUES ('B2ID2', 'I2ID2', 'B90');
INSERT IN in_table_batch_2
VALUES ('B2ID3', 'I2ID3', 'B60');
Please advise a solution for the same.
Thank you and best regards,
Séverine Suresh
very forced (question subfactoring used to allow easy testing/verification - could work with these test data only)
with
case_1 as
(select s.item_code,
s.bat_no,
h.txn_code,
h.doc_no,
h.updt_dt boe_dt,
cases where s.bat_no = h.bat_no then 'Y' else ' n end batch_yn.
cases where h.txn_code is not null
and h.doc_no is not null
and h.updt_dt is not null
then 'case 1' '.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, boe_dt
of w_stock_table
where bat_no is null
or txn_code is null
or doc_no is null
or boe_dt is null
) s
left outer join
w_history_table h
On s.item_code = h.item_code
and s.bat_no = h.bat_no
and exists (select null
of w_transaction1
where txn_code = nvl (s.txn_code, h.txn_code)
and txn_type in ('IN', 'ALL')
)
),
case_2 as
(select s.item_code,
NVL (s.bat_no, h.bat_no) bat_no.
NVL (s.txn_code, h.txn_code) txn_code.
NVL (s.doc_no, h.doc_no) doc_no.
NVL (s.boe_dt, h.updt_dt) updt_dt.
cases where s.bat_no = h.bat_no then 'Y' else ' n end batch_yn.
cases where h.txn_code is not null
and h.doc_no is not null
and h.updt_dt is not null
then 'case 2'.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, boe_dt
of case_1
where refers_to is null
) s
left outer join
w_history_table h
On s.item_code = h.item_code
and exists (select null
of w_transaction1
where txn_code = nvl (s.txn_code, h.txn_code)
and txn_type in ('IN', 'ALL')
)
and not exists (select null
of case_1
where item_code = h.item_code
and bat_no = h.bat_no
and txn_code = h.txn_code
and doc_no = h.doc_no
and updt_dt = h.updt_dt
)
),
case_31 as
(select s1.item_code,
NVL (S1.bat_no, W1.bat_no) bat_no.
NVL (S1.txn_code, W1.txn_code) txn_code.
NVL (S1.doc_no, W1.doc_no) doc_no.
NVL (S1.updt_dt, W1.doc_dt) updt_dt.
cases where s1.bat_no = w1.bat_no then 'Y' else ' n end batch_yn.
cases where w1.txn_code is not null
and w1.doc_no is not null
and w1.doc_dt is not null
then "case 31'.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to
of case_2
where refers_to is null
) s1
left outer join
(select i1.item_code, h1.txn_code, h1.doc_no, h1.doc_dt, b1.bat_no
of w_in_table_item_1 i1
inner join
w_in_table_head_1 h1
On i1.h1_sys_id = h1.h1_sys_id
inner join
w_in_table_batch_1 b1
On h1.txn_code = b1.txn_code
and h1.doc_no = b1.doc_no
) w1
On s1.item_code = w1.item_code
),
case_32 as
(select s2.item_code,
NVL (S2.bat_no, W2.bat_no) bat_no.
NVL (S2.txn_code, W2.txn_code) txn_code.
NVL (S2.doc_no, W2.doc_no) doc_no.
NVL (S2.updt_dt, W2.doc_dt) updt_dt.
cases where s2.bat_no = w2.bat_no then 'Y' else ' n end batch_yn.
cases where w2.txn_code is not null
and w2.doc_no is not null
and w2.doc_dt is not null
then "case 32'.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to
of case_2
where refers_to is null
) s2
left outer join
(select i2.item_code, h2.txn_code, h2.doc_no, h2.doc_dt, b2.bat_no
of w_in_table_item_2 i2
inner join
w_in_table_head_2 h2
On i2.h2_sys_id = h2.h2_sys_id
inner join
w_in_table_batch_2 b2
On i2.i2_sys_id = b2.i2_sys_id
) w2
On s2.item_code = w2.item_code
),
case_33 as
(select s3.item_code,
w3.bat_no,
NVL (S3.txn_code, w3.txn_code) txn_code.
NVL (S3.doc_no, w3.doc_no) doc_no.
NVL (S3.updt_dt, w3.doc_dt) updt_dt.
cases where s3.bat_no = w3.bat_no then 'Y' else ' n end batch_yn.
cases where w3.txn_code is not null
and w3.doc_no is not null
and w3.doc_dt is not null
then "case 33'.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to
of case_2
where refers_to is null
) s3
left outer join
(select i3.item_code, h3.txn_code, h3.doc_no, h3.doc_dt, i3.bat_no
of w_in_table_item_3 i3
inner join
w_in_table_head_3 h3
On i3.h3_sys_id = h3.h3_sys_id
) w3
On s3.item_code = w3.item_code
)
Select item_code, bat_no, txn_code, doc_no, boe_dt, batch_yn
of case_1
where refers_to is not null
Union of all the
Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
of case_2
where refers_to is not null
Union of all the
Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn,
ROW_NUMBER() over (partition by item_code of updt_dt desc order) rn
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
of case_31
where refers_to is not null
Union of all the
Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
of case_32
where refers_to is not null
Union of all the
Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
of case_33
where refers_to is not null
)
)
where rn = 1
ITEM_CODE | BAT_NO | TXN_CODE | DOC_NO | BOE_DT | BATCH_YN |
---|---|---|---|---|---|
I1 | B1 | T1 | 1234 | JANUARY 3, 2015 | THERE |
I1 | B30 | T30 | 7890 | FEBRUARY 5, 2015 | N |
I2 | B60 | T60 | 1234 | JANUARY 3, 2015 | N |
I3 | B70 | T70 | 1234 | FEBRUARY 1, 2015 | THERE |
I4 | - | T90 | 1234 | JANUARY 5, 2015 | N |
I6 | - | T40 | 1234 | AUGUST 5, 2015 | N |
Concerning
Etbin
Maybe you are looking for
-
3000 x 4 TouchPad / keyboard issue?
I have started to have a rather odd behavior, the mouse pointer "selects" all the time (selection box), what is happening currently with the office and it randomly moving icons as if I have the selected with the mouse (touchpad) the keyboard seems to
-
3 years international warranty extension
Among the positives for the purchase of this computer has been the International 3 year extended warranty.Tried to register thro the site, "unavailable".Anyone have the same problem, or know where to go?
-
Hard drive satellite A80 + weird sounds
When running my hard driveis a weird noiseIt is not like the sound of the wind, but it's like something Daniel inside the hard drive.It does not affect my operating system or performance... for nowbut I don't know about the future...Anyone know what
-
How can I open the case for this model L8L11AV... a HP 17 t it didn't open as most laptops. the standard Panel, or the black botton HP 17 t, the botton is money.
-
I accidentally deleted the Windows fax program in Windows 7. It is not in the trash and I don't have the original Win7 disc to reinstall. Any suggestions?