Question - create a field in a SQL query with the status not nullable
I want to create a field that is not nullable char (2) length
If I do CREATE TEMPORARY TABLE X
SELECT
"AH" AS CDTYPE
or
SELECT
CAST ('AH' AS CHAR (2)) CDTYPE
Or
CAST (NVL(' ','AH') AS CHAR (2)) CDTYPE
The field is always created as a nullable field of Char (2)
Without creating a special field type, how can I dow it
You cannot set the projections have NOT null SQL, you can only put your query clauses so that NULL values are filtered out or by default set to another value results.
NO NULL only applies to the columns of the table (or PL/SQL parameters/variables).
Tags: Database
Similar Questions
-
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,
-
Report of update SQL query with line selector. Update process.
I have a report of update SQL query with the selectors in line.
How to identify line selector in a process update on the page.
I want to update some columns with a value of an area of selection on the page.
With the help of the base:
UPDATE table_name
SET Column1 = value
WHERE some_column = some_value
I would need to do:
UPDATE table_name
SET column1 =: P1_select
WHERE [line selector] =?
Now sure how to identify [line selector] and/or validate it is checked.
Thank you
BobIdentify the name of the checkbox of the source of the page element, it should be of the fxx format (f01, f02... f50).
Suppose that we f01.for i in 1 .. apex_application.g_f01.count loop UPDATE CONTRACTS SET SIP_LOAD_FLAG = :P16_STATUS where
= apex_application.g_f01(i); --i'th checked record' primary key end loop; -
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'.
-
Write a SQL query with lines in columns
All the
I need help in writing a SQL query with lines in columns, let give u an example...
drop table activity;
CREATE TABLE 'ACTIVITY '.
(
"PROJECT_WID" NUMBER (22.0) NOT NULL,
VARCHAR2 (150 CHAR) "PROJECT_NO."
VARCHAR2 (800 CHAR) 'NAME '.
);
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1683691, '10007', 12-121');
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1684994, '10008', 12-122');
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1686296, '10009', 12-123');
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (2225222, '9040', 12-124');
drop table lonet;
CREATE TABLE 'LONET.
(
VARCHAR2 (150 CHAR) "NAME."
NUMBER OF THE "ROOT."
VARCHAR2 (150 CHAR) "ENTRYVALUE".
);
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1683691, "LDE");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1683691, 'LME');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1683691, 'ICE');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1683691, 'IKE');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1686291, "QTY");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1686291, 'MAX');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1684994, "MTE");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1684994, 'MAC');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMT', 1684994, 'NICE');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMR', 1684994, 'RAY');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1686296, "CAQ");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("PAP", 1686296, "QAQ");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("VANESSA", 1686296, "THEW");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("ANDR", 1686296, "REYL");
commit;
Link: activity.project_wid = lonet.root
look like output
Project_wid Project_no NAME GAC NAM BAG RAC 1683691 10007 12-121 LDE LME LCE LKE 1684994 10008 12-122 MTE null null MAC 1686296 10009 12-123 null null CAQ QAQ 2225222 9040 12-124 null null null null two problems, in that I am running
1. I dono how simply we can convert rows to columns
2. for root = 1683691, there are double NAM and RAC in lonet table... ideally these data should not be there, but since its here, we can take a MAX so that it returns a value
3. There are undesirables who should be ignored
Once again my thought process is that we join the activity and 4 alias table lonet.
ask for your help in this
Thank you
Hello
This is called pivoting.
Here's a way to do it:
WITH relevant_data AS
(
SELECT a.project_wid, a.project_no, b.SID
, l.name AS lonet_name, l.entryvalue
Activity one
LEFT OUTER JOIN lonet l.root = a.project_wid l
)
SELECT *.
OF relevant_data
PIVOT (MAX (entryvalue)
FOR lonet_name IN ("GAC" IN the gac
"NAM" AS nam
'BAG' IN the bag
"RAC" AS cars
)
)
ORDER BY project_wid
;
Output:
PROJECT_WID PROJECT_NO GAC NAM BAG RAC NAME
----------- ---------- ---------- ---------- ---------- ---------- ----------
1683691 12 - 10007 121 LDE LME LCE LKE
1684994 MAC MTE 10008 12-122
1686296 12 - 10009 123 QAC QAQ
2225222 9040 12 - 124
To learn more about swivel, see the FAQ in the Forum: Re: 4. How can I convert rows to columns?
Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!
-
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
-
SQL Query - store the result for optimization?
Good day experts,
I'm looking for advice on a report. I did a lot of analytical functions to get the basic data that I have to do my report and its takes about 50 min for SQL finish. Now, with these data, I need to create 3 different reports and I can't use the SQL even since there are a lot of aggregation (example would be product group in one case and by customer in 2nd). For each of these different group garages I need another report.
So how to create 3 reports of 1 SQL query without running the query 3 times?
First thing that comes to mind is to store the result set in a fictitious table, and then query the table since I get the basic data are about 300 lines and then perform different garages group.
Best regards
Igor
So how to create 3 reports of 1 SQL query without running the query 3 times?
You already know the obvious answer - store data 'somewhere '.
If any 'somewhere' depends on your needs and you have not provided ALL the.
MV - if the query is always the same, you might use a MV and make a complete refresh when you want that new data. The data are permanent and can be queried by other sessions, but the query that accesses the data is frozen in the definition of MV.
GTT (global temporary table) - If a NEW charge of data AND three reports will be ALWAYS executed by a single session and then data are no longer necessary so a TWG may work. The application that loads the TWG can be different for each race, but the data won't be available for a single session and ONLY for the duration of this session. So if something goes wrong and the session ends the data are missing.
First thing that comes to mind is to store the result set in a fictitious table, and then query the table since I get the basic data are about 300 lines and then perform different garages group.
Which is commonly called a "table of REPORT-READY." Those that are useful when data must be permanent and available for multiple sessions/users. Generally, there is a batch (for example the package procedure) that periodically refreshes / updates the data during a window of failure. Or the table can have a column (for example AS_OF) that allows it to contain multiple data sets and the update process let alone the existing data and creates a new set of data.
If your database is about 300 lines you can consider a table report and even use it to contain multiple data sets. Then, the reports can be written to query the data by using a value AS_OF that wraps and returns the appropriate data. You don't need a window of failure since the oldest data are still available (but can be removed when you no longer need.
If you need a set of data, you can use a partitioned table work (with only one partition) to collect the new set of data, then a SWAP PARTITION to 'swap' in the new data. Only, this "Exchange" takes a fraction of a second and avoids a window of failure. Once the swap done no matter what user query will get new data.
-
More than 1 SQL query with checkbox and error invalid number report
Hi all
I have two SQL query reports that each has an apex_item.checkbox and two processes for each report. A report/process works very well. It gives me an error of invalid number.
In addition, another query SQL (editable report) gives me the following error when using the Multi line process, delete.
ORA-06502: PL/SQL: digital or value error: character number conversion
error ORA-06502: PL/SQL: digital or value error: character number conversion
errorOk When I got a report from SQL query (with box and a process) and the query SQL (editable report) everything worked. It stopped working when I added another SQL query report (with box and a process).
A SQL query has the following in my query: apex_item.checkbox(3,email_id,'UNCHECKED') ""
The other SQL query has the following: apex_item.checkbox(2,b.file_id,'UNCHECKED') ""
Any help will be greatly appreciated,
Sylvia
Hi Reema,
I've recreated the region and now it works!
Thank you for this, looking at
Sylvia
-
What happened to the image field when you create a field of type of image for the Web application?
The answer is that the point of the IMAGE has been changed to the MEDIA.
Sorry, Ian, what research for this discussion, I got no results. All good and thanks for the carillon. Hope everything goes well.
Mouma
-
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 -
How can I create a query with the data control to the web service?
I need to create a query with the order of web service data, WSDL, it is query operation, there is a message of parameter with possible query criteria and a return message contains the results. I googled but can't find anything on the query with the web service. I can't find a criterion "named" to the data control of web service as normal data control. Blog of Shay, I saw the topics on the update with the data of web service command. How can I create a query with the data control to the web service? Thank you.Hello
This might help
* 054. Search form using control data WS ADF and complex of entry types *.
http://www.Oracle.com/technetwork/developer-tools/ADF/learnmore/index-101235.html
-
Select the query with the level line list where the clause
Hi all
I am creating a tabular presentation based on a SQL query that has a list of selection based on a query with a where clause clause that refers to a column in the original SQL query.
The situation is, I have a table that stores the client_id, source_id, and build_id, lets call it client_source. I have a second table, build_source, containing source_id and build_id, one to many relations between the two (1 source_id could have build_id 1-7).
Using a tabular presentation, I want to select the correspondent build_id to use in client_source, but the selection list should contain only the build_id for this particular source_id of lines.
Here is an example of the SQL source of tabular presentation;
Select
s.ROWID,
s.CLIENT_ID,
s.SOURCE_ID,
APEX_ITEM. SELECT_LIST_FROM_QUERY (1, s.BUILD_ID,)
"Select display b.build_id, b.build_id return.
b build_source where b.source_id = s.SOURCE_ID ') lst
of s client_source
what I want to achieve, it's as source_id "BOLD" match fields. When the query is built this way, I get an error of "invalid identifier" Oracle on s.SOURCE_ID during execution.
Is there some special tags to be used to refer to the external column? I must be missing something because this looks like a pretty mundane problem.
I am running on 4.1.0.00.32, on an Oracle 10 g release 10.2.0.4.0 Server Express request.
I look forward to useful responses!
See you soon,.
Jason
Published by: 1005131 on May 9, 2013 19:02Your selection by query list receives a static SQL. That SQL can't "see" the value of your s.source_id.
But it would work like this:
where b.source_id = ' | s.SOURCE_ID)You would be the value for the SQL concatenation. It is not ideal, but it will work.
Jorge
-
Exit SQL - compare with the files under unix
Dear Experts,
I'm putting in place an alert mechanism for the RAC load balancing.
I'm running a SQL to see what services RAC instances are currently underway and need to compare this result with a text file on the unix server. If my SQL query shows the services that are running on different instances of that text file, I need to send a warning. For example, SQL result shows * 'db1_obj_lock' runs on 2nd instance * where as text shows file must be run on the 1st instance, I need this to be reported.
I am developing a shell script to do this and need help with your entries. I understand that it's more issue of UNIX, but thought SQL experts might be able to help as they have treated these scenarios. Appreciate your help.
SELECT INST_ID,NAME from gv$active_services where name in ('db1_obj_lock','db1_app_ro1','db1_app_ro2') order by name / INST_ID NAME ---------- ---------------------------------------------------------------- 2 db1_obj_lock 5 db1_app_ro1 6 db1_app_ro1 6 db1_app_ro2 5 db1_app_ro2 srv1:/tmp# cat services.txt (This shows service names and instances they are running on) db1_jdbc 4 db1_obj_lock 1 db1_app_ro1 5 db1_app_ro1 6 db1_app_ro2 5 db1_app_ro2 6 db1_rpt 1 db1_rpt 2 db1_rpt 3 db1_rpt 4 . . . etc
ORA, DBA wrote:
I think I do something wrong during the creation of the external table:Please see below create table statement and my select * stmt. Select * null values returns INST_ID select, when I select INST_ID select db1_serv_external, all I get is null values. Is there a clause that miss me in create stmt this column values correctly from external table file OS maps? Appreciate your help
SQL> create table db1_serv_external 2 (name char(18), inst_id number(2)) 3 4 ORGANIZATION EXTERNAL 5 (TYPE ORACLE_LOADER 6 DEFAULT DIRECTORY db1_serv_ext 7 ACCESS PARAMETERS 8 (RECORDS DELIMITED BY NEWLINE 9 FIELDS (name char(18), 10 inst_id integer(2))) 11 LOCATION('db1_svc.lst')); Table created. SQL> select * from db1_serv_external; NAME INST_ID ------------------ ---------- db1_jdbc 4 db1_jdbc 1 db1_jdbc 2 db1_jdbc 3 db1_obj_lock 1
db1_obj_lock 1
123456789012
It seems that the longer 'NAME' is only 11 characters; No 18 -
SQL query for the region of the tree
Hello
I was wondering if someone is able to help me work on a SQL query, to format the data in the table required in a part of the tree... I've never used a tree and I'm fighting to get the right data (if possible).
The data in the table looks like this:
I want to put it in a tree, using level 1 level6 with a final layout that would look like this:
As you can see, the data are formatted in level6 down in the tree, but are filled in the table from level 1. Not all of the columns will be filled, so level2 for anyone 4 (France) is the equivalent of level in the tree like level6 to person 1 (Spain).
This is Apex 4.2.5
Oracle 11.2.0.3.0
Sample data:
CREATE TABLE employees ( employee VARCHAR2(100), level1 VARCHAR2(100), level2 VARCHAR2(100), level3 VARCHAR2(100), level4 VARCHAR2(100), level5 VARCHAR2(100), level6 VARCHAR2(100) ); INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person1','Team One','Recruitment','Human Resources','Fictituous Company','Murcia','Spain'); INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person2','Team Four','Testing','IT','Big Corporate','Hanover','Germany'); INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person3','Big Corporate','Hanover','Germany', null, null, null); INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person4','Brittany','France', null, null, null, null); INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person5','Team Three','Testing','IT','Big Corporate','Hanover','Germany'); INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person6','Public Relations','Government Agency','Brittany','France', null, null);
Added example given.
Hello
Apex-user wrote:
Thanks Frank, this is a good example, I can work with that! Your assumptions are correct.
A question I came, however, is that I have a data segment that comes across poorly formatted so to speak... where only the lower levels (1-2, etc.) have been filled from the bottom up.
An example of this data would be:
- INSERT INTO employees (employee, level 1, 2, level3, level4, level5, level6) VALUES ('Person7', 'One Team', 'Test', null, null, null, null);
As you can see that if you rerun the select, the test team is now duplicated, both at the level of the root in the tree as it should.
You are not sure if the sql can be adjusted to account for this, or if it's too hard?
It is obviously a question of data and I am trying to solve this separately (extracted data from another system out of my control).
Thank you!
Sorry, I'm confused.
You say that my assumptions were correct. What includes supported that "If test ' occurs under 'IT' in a row, then the extent of the 'Testing' occurs, it must be under"IT "? Right after you say that assumptions are correct, you give an example where 'Testing' occurs under 'IT' to a single line, but it is not less 'IT' to another line and where is 'One Team' under 'Testing' in a line, but is 'One Team' under 'Recruitment' in another row.
When a situation like this occurs, how you cope? Whenever you have a problem, please post the exact results you want from the given sample data, and an explanation of how you get these results. If you don't know about what would be the ideal results, or if you are flexible on the exact results, then at least give an example and explain your reasons.
Maybe you want to change the got_parent of subquery like this:
WITH unpivoted_data AS
(
SELECT *.
Employees
UNPIVOT (node_name
FOR lvl (level1 AS 1
level2 AS 2
level3 AS 3
level4 AS 4
level5 AS 5
level6 AS-6
)
)
)
got_parent AS
(
SELECT c.node_name
MIN (p.node_name) AS a parent
Of unpivoted_data c
LEFT OUTER JOIN unpivoted_data p ON p.employee = c.employee
AND p.lvl = c.lvl + 1
GROUP BY c.node_name
)
SELECT LPAD (' ' ')
2 * (LEVEL - 1)
) || Node_name AS entity
OF got_parent
START WITH parent IS NULL
Parent = node_name PRIOR CONNECTION
;
In this way, if 'Test' is current 'IT' in one line, but not under what in another line, whether under would consider the 'IT' request and not to be a root. If 'One Team' sudden 'Testing' in a line, but under "Recruitment" in another line, it will be (arbitrarily) consider it under "recruitment".
-
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.
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
-
The elements are duplicated in the left pane of the library.
When I go to "chrome://browser/content/places/places.xul" items in the left pane seems a copy as in the picture I have attached. Is it possible to fix this before creating a new profile?
-
Hello I have a little problem, I bought a cable for pc - tv, but my laptop is to 60 hertz and my tv works on 50-hertz... How can I do to downgrade from 60 to 50 Hz? (because if I don't, the picture on the tv don't appear in color...)
-
Structure matter and DAQmx selecting not good input channel
I'm trying to implement three modes with the structure of cases observed in the attatched file. Each mode has 1 set of differential analog input and then channel thus input signals an analog NRSE. For some reason any I am unable to get the three mode
-
has tried all possible configurations... 2 new cables and still nothing... past the fax hardware test, test socket connection wall, telephone connected to the appropriate port on the tests fax then fails with the help of correct type of phone cord te
-
difference between hubs and switches
What is the difference between hubs & switches?