SQL Query Question campaign
I have a table that has at least 40 values that I need to use as variables in CCA. My question is. If I write the query as follows:SELECT AS $Var1 of the value1, value2 AS $Var2, ETC... I do for 40 fields. Would it work if I just do a query where I
SELECT * FROM DBNAME WHERE CALLER = "$ANI."
and then simply use the column as variables names?
If you need 40 variables in your campaign to act on and use in logic, then you must list and assign all 40 as your first example.
Tags: Oracle
Similar Questions
-
SQL query question, how to improve it?
Hello everyone, I want to create a query with result in the following output. Each first-person Department starts with the letter A and goes to the top like this:
Name Department
A Person1 3
B Person2 3
C channels3 3
D Individu4 3
Person10 E 3
A 10 Person6
Person7 10 B
Person8 C 10
An Individu4 13
B Person9 13
It must be a SQL query, unfortunately no PL/SQL
I was able to create this query, but its lack. Department_id will be a variable, a person can choose a Department or several departments, so the request varies in size.
Select department_id, chr (64 + rownum)
from (select name, department_id
employees
where department_id = 3
order of id_but, naam
)
Union
Select department_id, chr (64 + rownum)
from (select name, department_id
employees
where department_id = 10
order of id_but, naam
)
Union
Select department_id, chr (64 + rownum)
from (select name, department_id
employees
where department_id = 13
order of id_but, naam
)
order of id_but, naam
The employees table has the following columns:
ID, name, department_id
Can someone help me with this query? Perhaps with the With clause?Hello
You can use the analytic ROW_NUMBER function instead of ROWNUM. Like all analytical functions, ROW_NUMBER can do a calculation separated for each unique value in the PARTITION BY clause:
select chr ( 64 + ROW_NUMBER () OVER ( PARTITION BY department_id ORDER BY id_but , naam ) ) AS r_num , name , department_id from employees where department_id IN (3, 10, 13) order by id_but , naam ;
If you do this in SQL * Plus, you can save for the departemnts user input (if it is a list separated by commas as ' 3, 10, 13', or a single value as "99") in a substitution variable (let's call it deptartment_id_list) and use the following WHERE clause:
where department_id IN (&department_id_list)
-
I have a table named Test, data inserted as below
col1 Val There 3 x 1 z 2 We write a query to output below:
col1 Val x 1 There 2 z 3 Please suggest the best way to reach above result.
It is not clear what you're trying to do, but you can use something like:
Select col1,
ROW_NUMBER() (any order of col1) val
of the test
/
For example:
with the trial as)
Select 'x' col1, 3 val union double all the
Select 'y', 2 double Union all
Select 'z', 1 double
)
Select col1,
ROW_NUMBER() (any order of col1) val
of the test
/
C VAL
- ----------
x 1
y 2
z 3SQL >
SY.
-
SQL Query Question of multiple criteria
Hi all
I currently have a query that provides me with a count for a criterion (C), but I also want to include the number of criteria (A) and (E) within the same query if possible. Here's what I have:
SELECT B.MDA_LEV3_DEPT_NAME AS "TEU Area", AS COUNT (Z.MDA_EPAF_STATUS) PROJECT
PS_MDA_EPAF_RQST Z, PS_MDA_EMPLOYEES B, PS_MDA_EPAF_WFXREF T
WHERE MDA_EPAF_STATUS = 'C '.
AND T.ORIGINATORID = Z.USERID
AND Z.USERID = B.EMPLID
AND Z.TRANSACTION_NBR = T.TRANSACTION_NBR
B.MDA_LEV3_DEPT_NAME GROUP
ORDER BY B.MDA_LEV3_DEPT_NAME;
Which produces:
Area of EVP Project Manager Office of VP University Affairs Sr 5 Cancer medicine 30 Cancer medicine - research 49 Cancer Prev & Pop science 3 Cancer Prev & science-Res Pop 1 Diagnostic Imaging 2 Information services 16 Internal medicine 5 Pathology/laboratory medicine 2 Pathology/laboratory medicine - Resch 1 Pediatrics 13 Provost and EVP departments 1 Radio-Oncology 26 Radio-Oncology - search 2 Regulatory Affairs 1 Surgery 4 Vice Provost research clinical 1 Vice Provost Science 42 But I want to understand (A) approved County and (E) which is pending County so it would look like:
Area of EVP Project Manager County approved County pending Office of VP University Affairs Sr 5 Cancer medicine 30 Cancer medicine - research 49 Cancer Prev & Pop science 3 Cancer Prev & science-Res Pop 1 Diagnostic Imaging 2 Information services 16 Internal medicine 5 Pathology/laboratory medicine 2 Pathology/laboratory medicine - Resch 1 Pediatrics 13 Provost and EVP departments 1 Radio-Oncology 26 Radio-Oncology - search 2 Regulatory Affairs 1 Surgery 4 Vice Provost research clinical 1 Vice Provost Science 42 Maybe (guessing)
SELECT B.MDA_LEV3_DEPT_NAME AS 'TEU Area. "
PROJECT COUNT(CASE Z.MDA_EPAF_STATUS WHEN 'C' THEN 1 END) AS,
COUNT(CASE Z.MDA_EPAF_STATUS WHEN 'A' THEN 1 END) APPROVED,
AS COUNT(CASE Z.MDA_EPAF_STATUS WHEN 'P' THEN 1 END) PENDING
OF PS_MDA_EPAF_RQST Z.
B PS_MDA_EMPLOYEES,
PS_MDA_EPAF_WFXREF T
WHERE MDA_EPAF_STATUS ('C', 'A', 'P')
AND T.ORIGINATORID = Z.USERID
AND Z.USERID = B.EMPLID
AND Z.TRANSACTION_NBR = T.TRANSACTION_NBR
B.MDA_LEV3_DEPT_NAME GROUP
ORDER BY B.MDA_LEV3_DEPT_NAME
Concerning
Etbin
-
SQL query and question CFOUTPUT
Hello
I am trying to compare two tables in a database. I need a few fields in a table of output, to compare a field between the two tables. Users choose the tables. I've written a SQL query that does what I need:
< cfquery name = "getitems" datasource = "snapshot" >
Select #endtable # .field9 #endtable # .field12, #endtable # .field4, #endtable # .field13, #endtable # .field2, #endtable # .field3, #starttable # .field3
of #endtable #, #starttable #.
"where #endtable # .field5 =' #form.field5 #"
and #starttable # .field2 = #endtable # .field2
< / cfquery >Problem is on the output. You can see that I am selecting field3 in two tables. I want also to two output field3 values.
< cfoutput query = "getitems" >
#field3 #.
< / cfoutput >
This gives me the value that was chosen as #endtable # .field3.
How can I exit the other - .field3 of # #starttable?
As mentioned, the table names are variable being passed in the query... Thank you!
Peter
How can I exit the other - .field3 of # #starttable?
Use an alias to give different names fields IE table.column AS unnom. Otherwise, cfquery do not know what field do you mean when you say "field3".
Select #endtable # .field9, #endtable # .field12,.
Be careful when using this type of sql. According to the source of your variables, this can pose a risk of sql injection.
-
Question to convert oracle sql query
Hi friends,
I have a sql query, as follows,
I want to convert this to oracle. I tried to convert this in someways. But I get errors only. Please someone help me solve this problem.Select Name From SysObjects Where XType = 'U' And Name = @Name
Thank you
RAMViews of the Oracle dictionary more come in DBA_, ALL_ USER_ flavors. You probably don't have privileges to view DBA_OBJECTS, in which case try object or USER_OBJECTS.
Of after what I read, you may need something like
SELECT * FROM all_objects WHERE owner <> 'SYS' AND object_type = 'TABLE'
BTW, a sure way to liquidate Oracle professionals is to use "SQL" to designate another DBMS product, not Structured Query Language. As you may have noticed, we have SQL here as well.
-
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'.
-
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".
-
SQl query to find out time between the different lines of transactions
(See both images from an attachment to get the clear picture of the data and understand the question correctly.)
I have a set of data like this in one of my paintings. (This is a simple representation of the original data.)
Reference table1.jpg
Id | Type | Value | Start_date | End_date
----------------------------------------------------------------------------------------------------------------------
ZTR0098 | ALLOW | 0 | 1 JUN | 2 JUN |
ZTR0098 | ADTAX | 0 | 1 JUN | 2 JUN |
ZTR0098 | MXTAX | 0 | 1 JUN | 9 JUN |
ZTR0098 | ALLOW | 4. 3 JUN | 15 JUN |
ZTR0098 | ADTAX | 44.00 | 3 JUN | 17-JUNE |
ZTR0098 | MXTAX | 2. 10 JUN | 17-JUNE |
ZTR0098 | ALLOW | 5. 16-JUNE | 20 JUN |
ZTR0098 | ADTAX | 55,34 | 18 JUN | 22 JUN |
ZTR0098 | MXTAX | 1. 18 JUN | 25 JUN |
ZTR0098 | MXTAX | 6. 26 JUN | 31 AUG |
ZTR0098 | ADTAX | 20.09. 23 JUN | 23 JUL |
ZTR0098 | ALLOW | 8. 21 JUN | 31 AUG |
ZTR0098 | ADTAX | 45. 24 JUL | 31 AUG |
each line has a type and a rasthaus id to it. ID belongs to other parent tables. the value of each type is given, and the validity of each value is followed by a field start_date and end_date.
All values start from 1 - JUN and expires on 31 - AUG. Now my requirement is to obtain a report that gives three columns for three different types (ALLOW, ADTAX and MXTAX) with combination of unique values in the effective time interval. Let me put the result below.
Reference table2.jpg
Id | ALLOW | ADTAX | MXTAX | Start_date | End_date
--------------------------------------------------------------------------------------------------------------------------------------------------
ZTR0098 | 0 | 0 | 0 | 1 JUN | 2 JUN |
ZTR0098 | 4. 44.00 | 0 | 3 JUN | 9 JUN |
ZTR0098 | 4. 44.00 | 2. 10 JUN | 15 JUN |
ZTR0098 | 5. 44.00 | 2. 16-JUNE | 17-JUNE |
ZTR0098 | 5. 55,34 | 1. 18 JUN | 20 JUN |
ZTR0098 | 8. 55,34 | 1. 21 JUN | 22 JUN |
ZTR0098 | 8. 20.09. 1. 23 JUN | 25 JUN |
ZTR0098 | 8. 20.09. 6. 26 JUN | 23 JUL |
ZTR0098 | 8. 45. 6. 23 JUL | 31 AUG |
As you can see there are no duplicate rows for a combination of (ALLOW, ADTAX and MXTAX) with their respective dates in force. resulting in the above table. the first step is to convert lines to the column which is pretty obvious to do that by grouping on start_date and end_date colum, but the real deal is the time interval during which the combination of the values (ALLOW, ADTAX, and MXTAX) has remained constant.
I wrote under query using Group by.
Select
ID,
NVL (max (decode (type, "ALLOW", value)), 0) as ALLOW
NVL (max (decode (type, 'ADTAX', value)), 0) as ADTAX
NVL (max (decode (type, 'MXTAX', value)), 0) as MXTAX
Start_date,
End_date
from my_table
Group of start_date, end_date, id
start_date, end_date
the results it gives are like this:
Reference table3.jpg
Id | ALLOW | ADTAX | MXTAX | Start_date | End_date
------------------------------------------------------------------------------------------------------------------------------------------------
ZTR0098 | 0 | 0 | 0 | 1 JUN | 2 JUN |
ZTR0098 | 0 | 0 | 2. 1 JUN | 9 JUN |
ZTR0098 | 4. 0 | 0 | 3 JUN | 15 JUN |
ZTR0098 | 0 | 44.00 | 0 | 3 JUN | 17-JUNE |
ZTR0098 | 0 | 0 | 2. 10 JUN | 17-JUNE |
ZTR0098 | 5. 0 | 0 | 16-JUNE | 20 JUN |
ZTR0098 | 0 | 55,34 | 0 | 18 JUN | 22 JUN |
. .
. .
like wise
but I'm not able to determine the time intervals by using the SQL query.
with
Table1 as
(select the id 'ZTR0098', 'ALLOW' type, 0 val, to_date('1-JUN','dd-MON') start_date, end_date Union to_date('2-JUN','dd-MON') double all the)
Select 'ZTR0098', 'ADTAX', 0, to_date('1-JUN','dd-MON'), to_date('2-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'MXTAX', 0, to_date('1-JUN','dd-MON'), to_date('9-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'ALLOW', 4, to_date('3-JUN','dd-MON'), to_date('15-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'ADTAX', 44.00, to_date('3-JUN','dd-MON'), to_date('17-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'MXTAX', 2, to_date('10-JUN','dd-MON'), to_date('17-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'ALLOW', 5, to_date('16-JUN','dd-MON'), to_date('20-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'ADTAX', 55.34, to_date('18-JUN','dd-MON'), to_date('22-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'MXTAX', 1, to_date('18-JUN','dd-MON'), to_date('25-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'MXTAX', 6, to_date('26-JUN','dd-MON'), to_date('31-AUG','dd-MON') of all the double union
Select 'ZTR0098', 'ADTAX', 20.09, to_date('23-JUN','dd-MON'), to_date('23-JUL','dd-MON') of all the double union
Select 'ZTR0098', 'ALLOW', 8, to_date('21-JUN','dd-MON'), to_date('31-AUG','dd-MON') of all the double union
Select 'ZTR0098', 'ADTAX', 45, to_date('24-JUL','dd-MON'), to_date('31-AUG','dd-MON') of the double
),
days like
(select level - 1 dte + to_date('1-JUN','dd-MON')
of the double
connect by level<= to_date('31-aug','dd-mon')="" -="" to_date('1-jun','dd-mon')="" +="">=>
)
Select id, allow, adtax, mxtax, min (dte) start_date, max (dte) end_date
(select ID, dte, max (allow) allow, max (adtax) adtax, max (mxtax) mxtax,
ROW_NUMBER() over (order by dte) row_number() - courses (partition by order max (allow), max (adtax), max (mxtax) by dte) gr
go (select id, dte,
-case when type = 'ALLOW' and dte between start_date and end_date then end val 0 otherwise allow.
-case when type = "ADTAX" and dte between start_date and end_date then val 0 otherwise end adtax.
-case when type = "MXTAX" and dte between start_date and end_date then val 0 otherwise end mxtax
Table 1 t,
days d
where d.dte between t.start_date and t.end_date
)
Group by id, dte
)
Group by id, gr, allow, adtax, mxtax
order by id, gr
ID ALLOW ADTAX MXTAX START_DATE END_DATE ZTR0098 0 0 0 01/06/2015 02/06/2015 ZTR0098 4 44 0 03/06/2015 09/06/2015 ZTR0098 4 44 2 10/06/2015 15/06/2015 ZTR0098 5 44 2 16/06/2015 17/06/2015 ZTR0098 5 55,34 1 18/06/2015 20/06/2015 ZTR0098 8 55,34 1 21/06/2015 22/06/2015 ZTR0098 8 20.09 1 23/06/2015 25/06/2015 ZTR0098 8 20.09 6 26/06/2015 23/07/2015 ZTR0098 8 45 6 24/07/2015 31/08/2015 Concerning
Etbin
-
Hi all
I'm trying to find a solution to this problem
SELECT b.person,
tbl1.program_code,
TO_CHAR (to_date (tbl1.start_date, 'YYYYMMDD'), ' MM/DD/YYYY'),
TO_CHAR (to_date (tbl1.end_date, 'YYYYMMDD'), ' MM/DD/YYYY'),
TBL2.program_code,
TO_CHAR (to_date (TBL2.start_date, 'YYYYMMDD'), ' MM/DD/YYYY')
Person_table p,
(SELECT e.person,
e.program_code,
e.start_date,
e.end_date,
OF e program_table,.
a_program_table has,
WHERE the e.end_date BETWEEN: first_day_year AND: last_day_year
AND a.system_date > to_date (: last_run_date, 'YYYYMMDD')) tbl1.
(SELECT e.person,
e.program_code,
e.start_date,
e.end_date,
OF e program_table,.
a_program_table has,
WHERE the e.start_date BETWEEN: first_day_year AND: last_day_year
AND a.system_date > to_date (: last_run_date, 'YYYYMMDD')) tbl2
WHERE = tbl1.person p.person
AND tbl1.person = tbl2.person
AND to_date (tbl1.end_date, 'YYYYMMDD') < to_date (tbl2.start_date, 'YYYYMMDD')
ORDER BY tbl2.start_date asc, asc tbl1.end_date;
The tables look like this
Program_table
PERSON PROGRAM_CODE START_DATE END_DATE
------ ------------ ---------- ---------
20150115 20150101 17 A1
20150125 20150116 13 A1
20150210 20150126 3 A1
20150220 20150211 16 A1
22991231 20150221 13 A1
A_program_table
PERSON PROGRAM_CODE START_DATE END_DATE SYSTEM_DATE
------ ------------ ---------- --------- -----------
17 20150101 20150115 20150101 A1
13 20150116 20150125 20150116 A1
3 20150126 20150210 20150126 A1
16 20150211 20150220 20150211 A1
13 20150221 22001231 20150221 A1
OUTPUT_RESULT
PERSON PROGRAM_CODE START_DATE END_DATE PROGRAM_CODE START_DATE
------ ------------ ---------- -------- ------------ ----------
A1 3 26/01/2015 10/02/2015 13 21/02/2015 -the unwanted span
A1 3 26/01/2015 10/02/2015 16 02/11/2015
16/02/11/2015-02/20/2015 A1 13 21/02/2015
As you can see here, I'm recording a person of conversion from one program to the other, given that the query has been run since last month. The results I'm capture is for the month of February.
I wanted the transition of the program 3-16 and 16-13, but not from 3 to 13. I need to eliminate the transition from 3 to 13. The reason why is this makes its appearance is due to the line
AND to_date (tbl1.end_date, 'YYYYMMDD') < to_date (tbl2.start_date, 'YYYYMMDD').
I use this because I want the result spans compared dynamically.
I'm looking for change of this request (for example: we can have 10 entries on the table for a month, but have only 9 transitions listed in the final - either).
Note: I would like to have a single query while as noted above, no procedure or query.
Thanks in advance
Hello
Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) of all the tables involved, so that people who want to help you can recreate the problem and test their ideas.
Also post the exact results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: Re: 2. How can I ask a question on the forums?
You said that this problem was "creation of the pl/sql query", but you have probably not all PL/SQL; just SQL.
2886750 wrote:
...
AND to_date (tbl1.end_date, 'YYYYMMDD')< to_date="" (tbl2.start_date,="">
Do not store information on dates in the string columns. Use the DATE columns. Then you won't need TO_DATE in conditions like this.
You do a join to match each row in each previous row for the same person. If I understand the problem, you don't want to compare with each previous line, you only want to compare with the last front row. That sound like a job for the analytic LAG function.
-
Clarification of the SQL query in 2 day + Guide APEX
I worked through the Oracle Database Express Edition 2 day + Application Express Developer's Guide, and try to decipher the SQL query in Chapter 4 (building your app).
The code is:
SELECT d.DEPARTMENT_ID,
d.DEPARTMENT_NAME,
(select count (*) from oehr_employees where department_id = d.department_id)
"Number of employees", he said.
substr (e.first_name, 1, 1) |'. ' || Select 'Name Manager',
c.COUNTRY_NAME 'place '.
OEHR_DEPARTMENTS d,
E OEHR_EMPLOYEES
OEHR_LOCATIONS l,
C OEHR_COUNTRIES
WHERE d.LOCATION_ID = l.LOCATION_ID
AND l.COUNTRY_ID = c.COUNTRY_ID
AND e.department_id = d.DEPARTMENT_ID
AND d.manager_id = e.employee_id
AND instr (superior (d.department_name), superior (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0)
I don't know exactly what is happening in the last line. I think I understand what the different functions but I'm not clear on the use of the: P2_REPORT_SEARCH string.
What does this string? This code simply checking that d.department_name isn't NA?
I have SQL experience but am not very familiar with the Oracle PL/SQL implementation. Can someone please give me a brief breakdown that check is doing in the context of the overall query? The application seems to work even if the conditional statement is not included.
Thank you.
2899145 wrote:
Thanks for the reply. I apologize if the information I added was incomplete. The code came from the day 2 + Application Express (version 4.2) Developer Guide.
In the section 'your own Application of 4 Buuilding' https://docs.oracle.com/cd/E37097_01/doc.42/e35122/build_app.htm#TDPAX04000 , they describe the creation of a report
page that includes the "manager_id" and 'location_id '. The SQL query, I pasted above extracted from the data in other tables to substitute the real 'name of the Manager' and 'rent '.
for the corresponding ID values. It makes sense, and the part of the SQL query that explicitly doing this makes sense.
However, given that the document is a guide for the development of the APEX, I guess the command:
AND instr (upper (d.department_name), upper (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0
done something valuable, and I do not recognize what is exactly the value.
From a practical point of view why would I need to include this conditional statement? Which only added to the application?
Looking at the guide in question, it is clear that the
AND instr(upper(d.department_name),upper(nvl(:P2_REPORT_SEARCH,d.department_name)))>0
the line is completely unnecessary in the context of this tutorial, and it can be removed. The search in the tutorial app page is implemented by using a report filter interactive rather than a P2_REPORT_SEARCH element, which does not seem to exist at all. (It's a quirk of the APEX that bind variable references to non-existent items are replaced with NULL silently rather than exceptions). I thought that perhaps it would be legacy code a version of the tutorial prior to the introduction of interactive reports at the APEX 3.1, but I can't find explicit instructions to create such an element of filter in the 3.0 tutorial. I guess it must have been automatically generated by the application wizard when you create a standard report page.
If you do not want to see the effect he would have (as described in the post above), leave it in the source report, add a text element of P2_REPORT_SEARCH, and a button "submit" on page 2 and experimenting to find different values of the element and clicking on the submit button...
-
SQL query client fetch that has all the products
Hi all
I need a SQL query to retrieve the output as shown
Table: ACCOUNT_SUMMARY
prod_id Cust_id
101 AAA
BBB 101
101. THE CCC
102 AAA
103 AAA
102. THE CCC
: Table
Prod_id Prod_desc
101 Home_loan
Vehicle loan 102
Loan education 103
Expected results:
Cust_id Prod_desc
AAA Home_loan
AAA auto loan
Educational ready AAA
Sorry, could not understand your question clearly.
Do you want this:
WITH account_summary AS (SELECT 101 prod_id,'AAA' cust_id FROM dual UNION ALL SELECT 101,'BBB' FROM dual UNION ALL SELECT 101,'CCC' FROM dual UNION ALL SELECT 102,'AAA' FROM dual UNION ALL SELECT 103,'AAA' FROM dual UNION ALL SELECT 102,'CCC' FROM dual) ,Product AS (SELECT 101 prod_id,'Home_loan' prod_desc FROM dual UNION ALL SELECT 102,'Vehicle loan' FROM dual UNION ALL SELECT 103,'Educational Loan' FROM dual ) , acc_count AS (SELECT prod_id, cust_id ,count(*) OVER (PARTITION BY cust_id) cnt FROM account_summary ) SELECT A.prod_id,P.prod_desc FROM acc_count A, product P WHERE A.prod_id = P.prod_id AND cnt = (SELECT count(*) FROM product) ORDER BY A.prod_id
-
What is the best way to optimize a SQL query: call a function or doing a join?
Hi, I want to know what is the best way to optimize a SQL query, call a function inside the SELECT statement, or make a simple join?
It depends on. Could be a. Could be the other. Could be no difference. You would need to compare with your tables in your environment with your settings.
If you put a gun to my head, I was given no other information and required that I answered the question, I would tend to wait that the join would be more effective. In general, if you can do something in pure SQL, it will be more effective than if you call PL/SQL.
Justin
-
Hello
I want to run and store the results of a dynamic sql query in a strored procedure.
I get the following variables of the user running: v_column_names, v_table_name, v_col, v_value
The query will be like:
v_query: = 'SELECT'. v_column_names | ' A ' | v_table_name | ' WHERE ' | v_col |' = ' | v_value;
for example v_column_names: = 'ACCOUNT_NUM, SYSTEM_ID, ENTITY_ID ';
v_table_name: = 'ACCOUNT '.
v_col: = 'COUNTRY_CODE ';
v_value: = "USA";
Here is what I tried
DECLARE
v_column_names VARCHAR (200): = 'ENTITY_ID, SYSTEM_ID, ACCOUNT_NUM;
v_table_name VARCHAR (200): = 'ACCOUNT '.
v_col VARCHAR (200): = 'COUNTRY_CODE ';
v_value VARCHAR (200): = "'USA"';
TYPE column_record () IS RENDERING
VARCHAR2 (200) C1: = null;
C2 VARCHAR2 (200): = null;
C3 VARCHAR2 (200): = null
);
TYPE st_table IS TABLE OF column_record INDEX DIRECTORY.
pk_table st_table;
NUMBER of v1: = 1;
BEGIN
v_select: = 'SELECT'. v_column_names | ' A ' | v_table_name | ' WHERE ' | v_col |' = ' | v_value;
EXECUTE IMMEDIATE v_select COLLECT LOOSE pk_table.
I'm IN 1.pk_table.count LOOP
DBMS_OUTPUT. Put_line (pk_table (v1). (C1);
DBMS_OUTPUT. Put_line (pk_table (v1). (C2);
DBMS_OUTPUT. Put_line (pk_table (v1). (C3);
v1: = v1 + 1;
END LOOP;
END;
The number of column names in v_column_names is dynamic, so I need a way to store the results and then manipulate them.
I look forward to your reply.
EDIT: The real question:
1. in the settings I have pass the table name and the value of the primary key of the row I want to delete.
2. He then checks if this line is referenced anywhere, removes the reference, and then deletes the current line. This can go, until all the rows that are referenced are removed.
The above code, I have provided a small part of the largest of stored procedure.
Thank you all, I found the tips very helpful. I found a solution to my problem:
It generates all removal requests to remove a specific line. Not what I wanted, but this does not solve my problem.
The reason why is that I discovered that we do not use the ON DELETE CASCADE that we don't remove a record accidentally, I know we have an option to restore, but it is just in case something goes wrong.
-
Hello
I need to write an efficient query because the query about 4 checks to be made on the lines before you return one row. Here's a sample script in query to create the table:
CREATE TABLE "myschema". "" Complaint. "
(
"Compalint_ID" NUMBER (20.0).
"ReplyTime' NUMBER,-it would be in a few minutes
"CREATION_TIME' TIMESTAMP (6).
NUMBER OF 'STATUS ',.
"TYPE" NUMBER
"CH_PKRTBL_Complaint_ID" ("Compalint_ID") PRIMARY KEY CONSTRAINT
USING INDEX PCTFREE, INITRANS 10 2 MAXTRANS 255 CALCULATES STATISTICS
STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 DEFAULT USER_TABLES)
TABLESPACE 'myspace' ENABLE
) PCTFREE, PCTUSED, INITRANS 40 10 1 MAXTRANS 255 NOCOMPRESS SLAUGHTER
STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 DEFAULT USER_TABLES)
TABLESPACE "myspace";
CREATE UNIQUE INDEX "myschema". "" CH_PKRTBL_Complaint_ID "WE"myschema ". "" Complaint "("Compalint_ID")
PCTFREE, INITRANS 10 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 DEFAULT USER_TABLES)
TABLESPACE "myspace";
ALTER TABLE 'myschema. ' ' KEY PRIMARY complaint ' ADD CONSTRAINT 'CH_PKRTBL_TKTID' ('Compalint_ID')
USING INDEX PCTFREE, INITRANS 10 2 MAXTRANS 255 CALCULATES STATISTICS
STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 DEFAULT USER_TABLES)
TABLESPACE 'myspace' ENABLE;
I want to write an efficient pl/sql-sql query with the least time to return a row based on four following priorities/controls in the order specified below:
1 return any line that contains a TYPE = 11
2. If no line found for 1 check then
calculate a difference in time for all of the lines as: time_difference (CREATION_TIME - ReplyTime)
and back to the line that has more big differene in - ve (it is the line which expired first)
3. If now the found line to check then the 2
rank next where STATUS = 22
4. If no line found to check then the 3
calculate a difference in time for all of the lines as: time_difference (CREATION_TIME - ReplyTime)
and back to the line that has a smaller difference in + ve (it is the line that will expire then)
Kindly help me in this task.
Thank you.@1
I have the suggestion of Daniel while avoiding reserved words and now I see an error in copy/paste complaint_ casetypestatus when 22 then 22 end check3@2
Bilal already you made in the right direction, anyway: as many others pointed out that you can not combine functions of the group the way which you intend to so using functions analytical has been the only issue keeping all lines and the calculation of the required amounts and charges in the query internal to combine in the outer query.
complaint_type case when 11 11 then end keeps only the 11 complaint_type all other complaint_type null values
Max (case complaint_type when 11 11 then complete) on check1_max (order by NULL rows between unbounded preceding and following unbounded), calculates the global maximum of the expression (in all the rows of the table)@3
I used systimestamp - (creation_time + reply_time / 60/24) just to produce a positive or negative number as your time_difference (CREATION_TIME - ReplyTime) somehow confused me (timestamp less number gives timestamp if positive or negative is not an appropriate question) so the above expression as used so far is something you know how (re) set. Other required clarification/explanation at this stage.@4
If the fraction of the second precision is not necessary using the date data type should be sufficient (environmental CAR you cannot rule out dealing with the events with the same timestamp) and what is the thrown error using systimestampConcerning
Etbin
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
-
I just got a new HP with Windows 7 computer. I use a HP Officejet 4500 printer. When I try to print from Firefox it brings up a window FAX as I am trying to send a fax. This happens regardless of how I try to print. Go to file then print or the butto
-
BlackBerry Smartphones Blackberry Internet Service msg to confirm the password?
Hi, I have not received emails from my hotmail email account since a few days and yesterday I got a message from BIS saying "Confirm password on your BB to continue to send and receive e-mail messages". I tried to go to the BIS to my BB as they said
-
Windows7 change my settings without being told to the.
I am running Windows7 64-bit on an HP laptop. The laptop is less than a year and I've only had problems with it. The first time it happened that I scanned. But it happened more than three times now. I was on Firefox and all of a sudden the screen wen
-
Hello. I have a problem. don't know what happened but now whenever I change a tool is dropdown menu appears. It's really annoying. How can I solve this problem? (single click, simply change tool. long or double waiting for menu drop-down)
-
VMFS partition table corruption? Need help to retrieve data
My House ESXi 5.1 was installed on HP Microserver G7. Hypervisor on USB-flash, datastore on Adaptec 3405.After some problems of power electro Microserver is will not start and I have chosen to build the new server on Microserver Gen8. I moved Adaptec