SQL statement for the hierarchy of the Organization
Nice dayI was wondering if there is a script/sql statement that would generate the hierarchy of the Organization (similar to the organization hierarchy editor) in Oracle EBS HRMS 11.5.10
Thank you
Elmer
I was wondering if there is a script/sql statement that would generate the hierarchy of the Organization (similar to the organization hierarchy editor) in Oracle EBS HRMS 11.5.10
Please see if (how to extract HR organization hierarchies in SQL? [REF 463359.1]) help.
Thank you
Hussein
Tags: Oracle Applications
Similar Questions
-
SQL statement for the materialized view?
Can someone please tell me what SQL statement creates a materialized view?Syntactically, Yes. Otherwise Yes too (as long as you don't mind the Cartesian join with State B).
Why not just try and see what happens?Concerning
Etbin
-
SQL statement for the click stream analysis
I want to divide the clicks of the user session. A session is defined to include all of the clicks a certain user that occur within 60 seconds of each other:
The output should be:create table clickstream ( t date , userid number(10) ); insert into clickstream values (to_date('5-9-2009 10:00:00','dd-mm-yyyy hh24:mi:ss'), 2); insert into clickstream values (to_date('5-9-2009 10:00:24','dd-mm-yyyy hh24:mi:ss') , 2); insert into clickstream values (to_date('5-9-2009 10:01:23','dd-mm-yyyy hh24:mi:ss') , 2); insert into clickstream values (to_date('5-9-2009 10:02:40','dd-mm-yyyy hh24:mi:ss') , 2); insert into clickstream values (to_date('5-9-2009 0:58:24','dd-mm-yyyy hh24:mi:ss') , 7); insert into clickstream values (to_date('5-9-2009 2:30:33','dd-mm-yyyy hh24:mi:ss') , 7); commit;
This query divides the clickstream sessions:Time t Userid Session 10:00:00 2 0 10:00:24 2 0 10:01:23 2 0 10:02:40 2 1 00:58:24 7 0 02:30:33 7 1
Because when the COUNT = 1 a new session is started by a given user, but I do not know how to proceed?select to_char(t,'hh24:mi:ss') t , userid , count(*) over ( partition by userid order by t RANGE between (1/(24*60)) preceding and current row) count from clickstream order by userid,t T USERID COUNT -------- ---------- ---------- 10:00:00 2 1 10:00:24 2 2 10:01:23 2 2 10:02:40 2 1 00:58:24 7 1 02:30:33 7 1
Seems to me, you can do a bit simpler:
SQL> select userid, t, nvl (sum (s) over (partition by userid order by t), 0) sessionid from (select userid, t, case when t - lag(t) over (partition by userid order by t) > 1 / (24 * 60) then 1 end s from clickstream order by userid, t) / USERID T SESSIONID ---------- --------------------- ---------- 2 05.09.2009 10:00:00 0 2 05.09.2009 10:00:24 0 2 05.09.2009 10:01:23 0 2 05.09.2009 10:02:40 1 2 05.09.2009 10:02:50 1 2 05.09.2009 10:05:40 2 7 05.09.2009 00:58:24 0 7 05.09.2009 02:30:33 1 8 rows selected.
-
Build SQL statements for the conversion error
Hello
I started a conversion after having dropped any object that has been marked blocking conversion (and refreshed + re-read the database).
But the conversion fails with:
Hello
At the revealid of track that he was opening and closing of session trigger failed.
I disabled the trigger, and now the conversion has kciked off as expected.
Thank you.
BR,
Kim
-
Is it possible to make the condition depending on the sql statements in the data models
Hi all
Is it possible to include the condition based on sql statements in the data models.
For example
Is something like this? Also, the good doc is available for ' how to take full advantage of the "data models" in BI Publisher?if (some parameter is not null) <sqlstatement name="STATEMENT_1"> ... </sqlstatement> else <sqlstatement name="STATEMENT_2"> ... </sqlstatement>
Thank you
-SookieHello Sookie,
I couldn't find the time to get a data model of demonstration of work for you, but I'll try to explain.First, write a PL/SQL package. Make sure that you set all the parameters of model of data such as a global variable in the default PL/SQL package.
CREATE OR REPLACE
package as employee
function BeforeReportTrigger return Boolean;
query_text varchar (2000);
number of p_DEPTNO;
END;
/CREATE OR REPLACE
package as body employee
function BeforeReportTrigger return Boolean IS
StartIF (p_DEPTNO = 10) THEN
query_text: = select col1, col2, col3 from HR.
elsif (p_DEPTNO = 20) THEN
query_text: = select col1, col2, col3 hr_history.
on the other
query_text: = select col1, col2, col3 hr_history1.
end if;
Returns true;
end;
/Use this package in the default package in your data model. Check the "defaultPackage ="employee"in the following data model header.
Sample data model
------------------------------
--
--
--
--
Before running the query SQL, data engine reads the "before the release of the report" and all the texte_requete argument based on the p_DeptNo value. When executing the Q1, engine sqlQuery analyze the query ' & quert_text and replace it with the actual value. For example if the p_deptno = 10, the query will be "select col1, col2, col3 from HR.
Try it...
-
Pinning on SQl statement in the library cache
Hello
Do to pin frequently used SQL statement to the shared pool...
I know that dbms_shared_pool.keep does the job for PL/SQL, but on simple SQL statements.
Experts from the clues?
Thank you
KingSee more of scripts:
-- Get address and hash_value of SQL statement select address, hash_value from v$sql where sql_text like 'your query to keep'; ------------------------------------------------------------------------------------------------ 00000000858CA2B0 2239673969 exec dbms_shared_pool.keep('00000000858CA2B0, 2239673969','C');
I think you want to pin the SQL statement that is specific to the moment analysis of long abovid.
I see no reason to pin the SQL more.Dion Cho
-
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'.
-
I have preorganize my Photos (during the trip) on a netbook.
How can I transfer Photos and already made organizations (albums, Tagg,...) to my dektop PC for the Organization of the final?
(Photoshop elements is installed on both computers).
GObi says:
I have preorganize my Photos (during the trip) on a netbook.
How can I transfer Photos and already made organizations (albums, Tagg,...) to my dektop PC for the Organization of the final?
(Photoshop elements is installed on both computers).
This is a typical and very common requirement.
The solution is to store your media library as well as your catalog on an external drive.
You can connect the external drive on both computers alternately. The performance is very good.
One way to make the transfer is to use the backup / restore process:
https://helpx.Adobe.com/Photoshop-elements/KB/backup-restore-move-catalog-Photoshop.html
This is the same process to an external drive or another computer.
Edit:
Make sure that the external drive is recognized by the same drive letter.
-
Recommendations for the Organization of the disk image?
I am moving in Aperture to LR and looking for general comments on the Organization of the image before you start the migration. Since the opening, I will export edited JPEG version final (with metadata), the image of origin (without metadata), which is usually a RAW or TIFF file. I want the original version, in the case where I want to re - edit in LR, while most of the images will never hit again. I intend to place the images in the folder structure as described below and use the import option 'Add' to keep the pictures in the files when importing to the RL. Records will be organized by "Year" with subfolders for files 'Final' and 'Original '. The hierarchy looks like this:
Folder "Images".
> file "1983".
> File "final".
> JPEG 1
> JPEG 2
> etc.
> File "Original".
> TIFF
> TIFF 2
> etc.
> file '1984 '.
> File "final".
> JPEG 1
> JPEG 2
> etc.
> File "Original".
> TIFF 1
> TIFF 2
> etc.
This body will allow me to easily find the original file in case I needed to re - edit an image (the original and final images have different file names). Will there be a major drawback in the use of this method of organization? For example, it seems that the images can be stacked if they reside in different folders. I thought 'stack' the original and final versions, but discarded the idea for other reasons. However, I'm not sure if I will create other problems by using a folder like this system.
Many of my images are scanned family photos dating back to 1880, kind of organization per year seems to be a good choice for me. I use keywords to group events in the year (1983, 1983 b, etc.). I'll create smart collections using keywords for the display, I don't need a folder structure based on events.
Otherwise, I could use the import options 'Copy' or 'Move' and let the LR to organize files. I don't know how the default LR organization works (in "import session or date?). I suspect that it is not simply place them in a single folder.
I appreciate all the thoughts about the proposed organization. I prefer to learn from mistakes of others rather than mine! It is quite possible that the good answer to my question is "it does not matter."
Thanks David
In my opinion, the only thing that works reliably is a simple year-> Date structure. Another thing is just a waste of time and doesn't complicate your life. It is the structure that Lightroom does by default when importing. It is simply:
2015
2015-01-01
2015 01-02
etc.
This greatly simplifies organization because it is always consistent and allows you to easily backup or move folders to external hard drives if your a resident fills up too.
It is unnecessary to have initial and final records. You only need the originals. Any edited image, you need is exported a lot faster since Lightroom when you need so you can make the size and format you need, when you need and it is much easier to find the desired image in Lightroom quickly to scroll through the folders in the Finder Explorer / in any case. The key is really well-organized metadata as dj says. If you the keyword you can find something quickly. Finding accurate and such dates is also trivial using the filter bar.
That said, Lightroom doesn't really care how you organize your originals so do what best suits you.
-
Try to run a SQL statement through the window of OEM 12 c run SQL. Statement fails
All,
I have a 11g database. When it is initially installed, I installed it in $ORACLE_BASE = / orabin/app/oracle/product and $ORACLE_HOME = $ORACLE_BASE/11gDB_R2. This is the version 11.2.0.1 to give birth to 11.2.0.3.
Recently, I installed 11.2.0.4 in $ORACLE_BASE/11.2.0.4. Then, I upgraded my database at 11.2.0.4. Everything works fine.
All my scripts on the linux host logon changed to point my environment at $ORACLE_BASE/11.2.0.4 House and my $PATH when I connect to the linux host is: /orabin/app/oracle/product/11.2.0.4/bin:/orabin/app/oracle/product/11.2.0.4/OPatch:/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/oracle/bin
On my OEM Console, the database appears as 11.2.0.4 and me can manage very well.
However, when I try to use the window of the OEM Console to execute SQL to execute any type of SQL statement, it fails.
The failure error is:
Could not launch/orabin/app/oracle/product/11gDB_R2/bin/sqlplus-s/nolog: no such file or directory
It would be a mistake since the 11gDB_R2 directory tree (the 11.2.0.3 software) has been removed from the host, now that the database is set to level and working as 11.2.0.4.
I wonder if somewhere in the OEM software, there is always a pointer to the old ORACLE_HOME? I can't find anything in the .bashrc or other shell scripts that are executed when a Shell session on the host computer which were still the reference to the old directory of 11gDB_R2 so I'm a bit puzzled.
I have 8 guests, and all have been improved in the same way at 11.2.0.4. For some databases, the OEM window run SQL is executing the SQL code.
Someone has some ideas on this?
Go to the Configuration of the analysis of the database (when you set the password) and update of the Oracle home. Also do this for all targets listener on this host as well.
-
FDM generated SQL statement in the log file?
Hello everyone, hopefully a simple question:When you perform an import using FDM, I know that behind the scenes of a SQL SELECT statement statement composed and performed on the database server. My question: the actual SQL statement is retained in a newspaper somewhere (so that we can see it?) In our case, it's an Oracle DB server and we use the ERPI adapter; not sure if it's relevant. We would like to enter this SQL statement and use it as a starting point for other things.
Thanks in advance for anything you can offer.
The statement SQL is not written in the journal of the adapter. The only things that are registered are what show in the file card log if you enable loggin to the adapter source ERPi in action 'Get Data'.
-
pl/sql code for the problem
Hi all
Can someone please tell me how to write pl/sql code to the below question:
I have two tables has temp and temp b both have the code and the reading of time columns. I want if temp one more time temp b for a particularcode of reading then reading time of tempb must obtain updates of reading time (reading time to temp b should get updated ony if the temp one reading is largest temp b and code exist in the tables). If the code as code1 which exist in temp one but doesnot exist in temp b so that records should get inserted into table b temp.
For Ex. Temp a code1, 10:00; Code1, 11:00; B temp is code1, and code 2.10 AM:code 2.9 AM 09:00; then once the program run the tempb should have code1, 11:00; Code2, 10:00
Thanks in advance.Hello
You needn't PL/SQL for this; a MERGE statement will do.
If you want to do it in PL/SQL, always to use MERGE:BEGIN MERGE INTO tempb dst USING ( SELECT code , MAX (reading_time) AS reading_time FROM tempa GROUP BY code ) src ON (src.code = dst.code) WHEN MATCHED THEN UPDATE SET dst.reading_time = src.reading_time WHERE dst.reading_time < src.reading_time WHEN NOT MATCHED THEN INSERT (dst.code, dst.reading_time) VALUES (src.code, src.reading_time) ; END; /
-
SQL statement causes the database to hang
Guys,
a DBA told me that there is something wrong with this SQL statement and causes a blockage of database...
Please check.
SELECT field1 FROM table1 WHERE Field1 LIKE ' %% ' AND field2 = '123456' ORDER BY Field2 ASC
Tell me, what is the problem with statement above. The LIKE operator is?
Thanks for the help!Are not specifically related to your question, but having a clause such as ' where Field2 ='123456 "and then you place your order on Field2 is not really going to do much for you, all values will be identical!
Carl
-
PL/SQL function for the addition of "days."
I created a function that, at a date and a number, adds many days to the date. The problem is that there are parameters to include Saturday, Sunday or Monday as these days. Here is an example of the call
DAYSBETWEEN('01-Aug-11',5,0,0,0) will give 5 calendar days since August 1, 2011 (that you would not exclude Saturday, Sunday or Monday)
DAYSBETWEEN (August 1, 11 ', 5, 1,1,0) would give you 5 working days since August 1, 2011
DAYSBETWEEN('01-Aug-11',5,0,1,1) would give you 5 days of August 1, 2011 spring break Sunday and Monday.
My current role is:
This works for a small set of values for the date, but when there is a bigger set of dates, it takes hours to complete because of the time loop and multiple or statements.create or replace FUNCTION DAYSBETWEEN( DAYIN IN DATE , ADDNUM IN NUMBER , EXSAT IN NUMBER , EXSUN IN NUMBER , EXMON IN NUMBER ) RETURN DATE IS dtestart DATE; intcount NUMBER; holidays NUMBER; BEGIN dtestart := DAYIN; intcount :=1; WHILE intcount <= ADDNUM LOOP dtestart := dtestart + 1; IF NOT((EXSAT = 1 AND TO_CHAR(dtestart, 'd')= 7) OR (EXSUN=1 AND TO_CHAR(dtestart, 'd')= 1) OR (EXMON=1 AND TO_CHAR(dtestart, 'd')= 2)) THEN intcount := intcount + 1; END IF; END LOOP; RETURN dtestart; END DAYSBETWEEN;
Y at - it another game of logic, I could use to improve this query, using possibly not the while loop / or statements?Hi again:
This is the query, reformatted in the form of a function, exectuing the same thing I did in the above query:
SQL> CREATE OR REPLACE FUNCTION daysbetween 2 ( 3 dayin IN DATE , 4 addnum IN NUMBER , 5 exsat IN NUMBER , 6 exsun IN NUMBER , 7 exmon IN NUMBER ) 8 9 RETURN DATE 10 11 IS 12 13 dtestart DATE; 14 intcount NUMBER; 15 holidays NUMBER; 16 17 BEGIN 18 19 WITH all_dates AS 20 ( 21 SELECT LEVEL AS days_to_add 22 , dayin 23 , dayin + LEVEL AS new_dt 24 , addnum 25 , exsat 26 , exsun 27 , exmon 28 FROM dual 29 CONNECT BY LEVEL <= addnum * 2 30 ) 31 , exclusions AS 32 ( 33 SELECT ROW_NUMBER() OVER ( ORDER BY new_dt) ordering 34 , addnum 35 , new_dt 36 , TO_CHAR ( new_dt, 'DY' ) 37 FROM all_dates 38 WHERE 1=1 39 AND TO_CHAR ( new_dt, 'DY' ) != DECODE ( exsat, 1, 'SAT', 'XXX') 40 AND TO_CHAR ( new_dt, 'DY' ) != DECODE ( exsun, 1, 'SUN', 'XXX') 41 AND TO_CHAR ( new_dt, 'DY' ) != DECODE ( exmon, 1, 'MON', 'XXX') 42 ) 43 SELECT MAX( new_dt ) 44 INTO dtestart 45 FROM exclusions 46 WHERE ordering <= addnum; 47 48 RETURN dtestart; 49 50 END daysbetween; 51 / Function created. SQL> SELECT daysbetween ( DATE '2011-08-01', 150, 1, 0, 1) FROM DUAL; DAYSBETWE --------- 26-FEB-12 1 row selected.
The only variable not factored is holiday, but I saw that you were for them in your LOOP function either.
Due to the nature and variability holiday, it is better to have a table with the listed holidays, and those who could be elminated of charges together in the same 'exculsions' query where I used the TO_CHAR and DECODE to exclude the Fri, sat and Sun.
-
Hide results SQL - State of the button, see the
Hello
I use APEX 4.0 with Toad for Oracle 10.5. My problem is that I need to hide the delete button based on the results of the SQL statement. When the point: P43_DEPARTMENT_ID value is entered and there is for any field below, the data will appear along the line.
But when no data appears that there is still a blank line for the fields. That will make the hidden Delete button. I don't know how to remove this row of the grid with my results of the select statement above. The State still thinks there is a line and a value (s) appear statement.SELECT (SELECT distinct department_id FROM tbl_department WHERE department_id = :P43_DEPARTMENT_ID AND department_id IN (SELECT SUBSTR (division_id, 0, 5) FROM tbl_division)) AS DIVISION, (SELECT distinct department_id FROM tbl_department WHERE department_id = :P43_DEPARTMENT_ID AND department_id IN (SELECT SUBSTR (fk_division_id, 0, 5) FROM tbl_grant)) AS GRANTS, (SELECT distinct department_id FROM tbl_department WHERE department_id = :P43_DEPARTMENT_ID AND department_id IN (SELECT SUBSTR (fk_division_id, 0, 5) FROM tbl_allotment)) AS ALLOTMENT, (SELECT distinct department_id FROM tbl_department WHERE department_id = :P43_DEPARTMENT_ID AND department_id IN (SELECT department_id FROM tbl_department_temp)) AS DEPARTMENT_TEMP, (SELECT distinct department_id FROM tbl_department WHERE department_id = :P43_DEPARTMENT_ID AND department_id IN (SELECT SUBSTR (division_id, 0, 5) FROM tbl_division_temp)) AS DIVISION_TEMP, (SELECT distinct department_id FROM tbl_department WHERE department_id = :P43_DEPARTMENT_ID AND department_id IN (SELECT SUBSTR (fk_division_id, 0, 5) FROM tbl_grant_temp)) AS GRANT_TEMP, (SELECT distinct department_id FROM tbl_department WHERE department_id = :P43_DEPARTMENT_ID AND department_id IN (SELECT SUBSTR (fk_division_id, 0, 5) FROM tbl_allotment_temp)) AS ALLOTMENT_TEMP FROM DUAL
DIVISION OF | GRANTS | ALLOTMENT | DEPARTMENT_TEMP | DIVISION_TEMP | GRANT_TEMP | ALLOTMENT_TEMP
________|_______ |___________|__________________|_____________ |____________|_________________
Can someone help me with my select statement or provide me with advice on how to remove this blank line when there is no data? I can't create a view and then add a WHERE IS NOT NULL clause because of the variable binding: P43_DEPARTMENT_ID.Do not know if I just got it, but what about:
SELECT SELECT (separate department_id
OF tbl_department
WHERE department_id =: P43_DEPARTMENT_ID
AND department_id IN (SELECT SUBSTR (division_id, 0, 5)
OF tbl_division))
THE DIVISION,
SELECT (separate department_id
OF tbl_department
WHERE department_id =: P43_DEPARTMENT_ID
AND department_id IN (SELECT SUBSTR (fk_division_id, 0, 5)
OF tbl_grant))
FORM OF GRANTS,
SELECT (separate department_id
OF tbl_department
WHERE department_id =: P43_DEPARTMENT_ID
AND department_id IN (SELECT SUBSTR (fk_division_id, 0, 5)
OF tbl_allotment))
AS ASSIGNMENT,.
SELECT (separate department_id
OF tbl_department
WHERE department_id =: P43_DEPARTMENT_ID
AND department_id IN (SELECT department_id
OF tbl_department_temp))
AS DEPARTMENT_TEMP,
SELECT (separate department_id
OF tbl_department
WHERE department_id =: P43_DEPARTMENT_ID
AND department_id IN (SELECT SUBSTR (division_id, 0, 5)
OF tbl_division_temp))
AS DIVISION_TEMP,
SELECT (separate department_id
OF tbl_department
WHERE department_id =: P43_DEPARTMENT_ID
AND department_id IN (SELECT SUBSTR (fk_division_id, 0, 5)
OF tbl_grant_temp))
AS GRANT_TEMP,
SELECT (separate department_id
OF tbl_department
WHERE department_id =: P43_DEPARTMENT_ID
AND department_id IN (SELECT SUBSTR (fk_division_id, 0, 5)
OF tbl_allotment_temp))
AS ALLOTMENT_TEMP
OF THE DOUBLE
LESS
SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL from doubleThis should ensure you don't receive a "no data found" when all the columns return null.
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
-
SSD is MX100 Crucial @256 GB with 1 TB on Athlon X 4 760 K PC HARD drive.
-
I no longer get my bubble that shows me that my friend type a text for me
iPhone 9.1.2 5sno longer get my bubble when my friends and I are texting, it allows me to see that she is typing.
-
Why support forums do not appear on the site of location of Western Europe
Hello Motorola, After looking around, on your website, there is no support forum is on the location of Western Europe Why is it so? Motorola is afraid to go to manny questions about products out there?
-
Help needed with two new HHD to RAID 1 PERC 6 / i integrated controller
We have a client that has an out of warranty PowerEdge T610. On the Dell OpenManage Server Admin, I can see that he can see my 1 RAID PERC 6 / i integrated controller. On one of the controllers, we have a RAID 5 that has 4 discs dedicated to a data s
-
Custom Manager does not scroll
I have a custom handler that I can't scroll. class TextMenuManager extends Manager{TextMenuManager(){Super(Manager.VERTICAL_SCROLL |) Manager.VERTICAL_SCROLLBAR); I have replace getPreferredHeight, getPreferredWidth and sublayout. protected void subl