Big vs PL SQL query
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64biPL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
AMT for Linux: release 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
Hello! I try to outdo a PL/SQL complex (many IFs and some columns depends on other "calculated" columns) using SQL 'Great', and I am failure. My question is to what extent I should stop writing SQL and then mix it with PL/SQL? TX in advance.
Published by: indra budiantho on January 26, 2013 14:28
Indra budiantho wrote:
I try to outdo a PL/SQL complex (many IFs and some columns depends on other "calculated" columns) using SQL 'Great', and I am failure.
With the help of SQL does not mean a faster CASE statement, or a faster TO_CHAR(), PL/SQL.
So if you have 10 instructions BOX , which must be run once 1000, SQL and PL/SQL are just as fast.
So, why then do you prefer SQL?
Because for the statement SQL CASE , to assess data comes directly from the line being processed by that SQL.
Instead, one must use a SQL statement to retrieve the data for PL/SQL. The data travels all the way from this line, via the SQL, in memory of the PGA of PL/SQL. And only then PL/SQL can apply the CASE statement.
If performance differ not because the CASE statement is faster in one language than another, but because of the way that data gets the code in this CASE .
My question is to what extent I should stop writing SQL and then mix it with PL/SQL? TX in advance.
There is no rule set to be applied to answer this question. Also, keep in mind that SQL and PL/SQL can be mixed differently.
Create PL/SQL functions (for example business rule/translation) and call this function of SQL.
Pull the lines as is the SQL cursor in the memory of the PGA of PL/SQL and then Pat PL/SQL functions on these data from PGA (aka bulk collection).
Create a PL/SQL function, where the SQL engine provides (via a slider interface) lines of the pipeline in the pipeline, PL/SQL does little, then driven back a line of response to the SQL engine.
So it comes down to it depends..
Tags: Database
Similar Questions
-
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".
-
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
-
Using Variables in a system SQL query
Hello!
I m new on Oracle and SQL so I Don t know not big thing about it.
There is problem of customization:
Is it possible to use the System Variable % username % in a SQL query?
I tried... where table.shorttag = "% username %";
but it does not work.
Oracle is able to manage Systemvariables? Or y at - it another way to use the current Windows user in a SQL query.
It is very Important to use the current Windows user and not the Oracle user.
Thank you
MFGSELECT OSUSER FROM V$SESSION WHERE audsid = USERENV('sessionid')
URS
-
Œuvres SQL query to MS SQL Server 2008, but not when you use the database kit
I have this SQL query:
DECLARE TABLE (@DataTypeTable)
Name varchar (128).
TypeID INT)-Add comma delimeted type data in the temporary table names
INSERT INTO @DataTypeTable (name)
SELECT * from WhatWeShouldDoRead.func_Split (@DataTypeTrimmed, ',')SELECT the name OF @DataTypeTable
That takes a comma delimited by the string and returns the string as a table. It works correctly in Microsoft SQL Server Management Studio. When I run this as a stored procedure I return nothing. There are no errors, SQL or otherwise. I checked that I am connected to the correct database and the stored procedure is responsible without changing any error chain which is reported of this stored procedure (that code is not shown in the example above). Has anyone seen this problem before, or have experience with SQL/Labview interfaces to tell me what I am doing wrong?
Thanks in advance.
-
HI HI... I'm a student doing a project related to labview. My task is to create a vi, type a user name and password to continue the whole VI.
As I am a newbie to SQL query language, can anyone help me this?... This isn't like the VI with password lock
There is a connection of the user called button in my main façade... u by clicking on it, a pop-up window will come out asking you a user name and a password. If the user name and the password is correct, then you can proceed. The problem is that I'm stuck with database...
Help me pls!with respect,
Ray
Hello
You have two cases:
(1) connect to the database with string (link a string of connection information), and then type something like this:
Driver is SQL Native Client;. Server = IP. Add.re.SS; UID = username; PW = *** ; Database = MyDatabase (depends on your database)(2) use a UDL file (you can configure it to connect to your database, with specific format). Remember that the connection is successful with test button.
There is a UDL file that you can edit here: C:\Program NIUninstaller Instruments\LabVIEW 2010\examples\database\Labview.udl
Edit: The connection dropped, you can set the path to an mdb file, and I think you can give the path of your accdb file.
Kind regards
-
I am trying to execute the following SQl query, SELECT * failure WHERE ID = '123 ' AND RepairAction =' '; using the DB tools run Query.vi. This query never find record in my database. My database contains a record where the registered ID contains the value '123' and the RepairAction field is an empty string. If I remove the declaration 'AND RepairAction' ';' my query text, the record is found. I think my problem is that I do not use the correct syntax to describe and an empty string. I tried the following: "," ",""," "and NULL as empty and none of these work string arguments.
I was hoping someone might be able to tell me what the correct syntax is an empty string or if there is another approach that I take.
Thanks in advance for your help,
Jim
Jim,
Just to be sure, have you used 'is' instead of '=' in this command?
This makes all the difference in this command.
Cerati
-
Support of SQL query: what tasks are Sunday from 07:00 - 12:00
Hello tide Admins.
I need to do a SQL query that can give me a list of jobs that are running on a given (Sunday) day from 07:00 - 12:00. Our environment is not a maintenance window. Therefore, whenever there is application of patches or upgrades, it causes more work and risk of failure of the tide tasks. By moving jobs over the period from 07:00 - 12:00 Sunday, patch can be completed without disrupting the calendar.
Im not the best at the SQL script and can not get my script to work. any help would be great. Here's what I have so far. I get the error ' could not find identifier multi-player jobmst.jobmst_name. IM using Tidal 6.0.3 with SQL for DB Admeral table.
SELECT dbo.jobdtl.jobdtl_id, dbo.jobmst.jobmst_prntname, dbo.jobmst.jobmst_name
FROM dbo.jobdtl INNER JOIN
dbo.jobmst ON dbo.jobdtl.jobdtl_id = dbo.jobmst.jobdtl_id
WHERE (dbo.jobdtl.jobdtl_fromdt > 14 September 2016 06:00 ') AND (dbo.jobdtl.jobdtl_fromdt< '09/11/2016="" 012:00:00="">
GROUP OF dbo.jobdtl.jobdtl_id, dbo.jobmst.jobmst_prntname, dbo.jobmst.jobmst_name
Hi Jeff
The time window from the jobdtl returns only jobs that have an early start time and windows of time from beginning to the end, so there may be some tasks which are not time bound but have dependencies on other jobs, variables, etc.
Here are the 2 SQL queries against the table jobrun and jobmst:
-The list of jobs that took place last Sunday between 07:00 and 12:00
SELECT jobmst.jobmst_prntname, jobmst.jobmst_name, jobrun.jobrun_time FROM jobrun
JOIN jobmst on jobrun.jobmst_id = jobmst.jobmst_id
WHERE jobrun.jobrun_time > = 9/11/2016 07:00 ' and jobrun.jobrun_time<= '9/11/2016="" 12:00="">=>
ORDER BY jobrun.jobrun_time-For a list of jobs that are scheduled to run on Sunday to come between 07:00 and 12:00
SELECT jobmst.jobmst_prntname, jobmst.jobmst_name, jobrun.jobrun_esttime FROM jobrun
JOIN jobmst on jobrun.jobmst_id = jobmst.jobmst_id
WHERE jobrun.jobrun_esttime > = 9/18/2016 07:00 ' and jobrun.jobrun_esttime<= '9/18/2016="" 12:00="">=>
ORDER BY jobrun.jobrun_esttimeARO
The Derrick
-
How to get the value of a column in sql query?
Hi, anyone knows how to get the value of a column in sql query?
Here is my code, the value must be 1350079224397 in my PB, but I get 0
QString query ("SELECT version FROM db_version");
QVariant result = sda.execute (query);
QVariantMap versionMap = result.toList () such () .toMap ();
If (! versionMap.IsEmpty ())
{
qDebug()<"Version: "="">"Version:><>
}OK, I have the solution
QString query ("SELECT version as version FROM db_version");
-
Hi team,
I'm looking for a SQL query check data (ECC + CallVariable) due to a RESULT of SCRIPT EXECUTE when you ask an external VRU with a translation route to VRU with a 'run external Script '.
In my view, that the data are analyzed between the termination call detail + termination call Variable.
If you have already such a SQL query I would be very grateful to have.
Thanks and greetings
Nick
Omar,
respectfully, shorten the interval of a day might not be an option for a history report ;-)
I recommend to take a look at the following SQL query:
DECLARE @dateFrom DATETIME, @dateTo DATETIME
SET @dateFrom = ' 2014-01-24 00:00:00 '
SET @dateTo = ' 2014-01-25 00:00:00 '
SELECT
TCV. DateTime,
TCD. RecoveryKey,
TCD. RouterCallKeyDay,
TCD. RouterCallKey,
VME. EnterpriseName AS [ECVEnterpriseName],
TCV. ArrayIndex,
TCV. ECCValue
OF Termination_Call_Variable tcv
JOIN THE
(SELECT RouterCallKeyDay, RouterCallKey, RecoveryKey IN Termination_Call_Detail WHERE DateTime > @dateFrom AND DateTime)< @dateto)="">
THE tcv. TCDRecoveryKey = tcd. RecoveryKey
LEFT OUTER JOIN Expanded_Call_Variable VME ON tcv. ExpandedCallVariableID = VME. ExpandedCallVariableID
WHERE the tcv. DateTime > @dateFrom AND tcv. DateTime<>
With variables, you can set up your code (for example, you could write SET @dateFrom =? and let the calling application to fill in the DateTime for you).
In addition, join two large tables with all the lines, as you did (TCD - TCV) is never a good option.
Another aspect to consider: all the ECC is actually arrays (always), is not good to leave aside the index value (tcv. ArrayIndex).
G.
-
DA on updatable report items Sql query using the class
Request Express 4.2.5.00.08
10-11 g Oracle
I have a page, so it has a link/button when he clicks then modal region will appear. Modal region has a as a table (Type SQL Query (updateable report)). All work very well so far.
However, I've now added some complex things.
for example. My region is based on the query of SQL Type (editable report).
SELECT id, name of family, Traghetti, area, d_date, start_time, End_time, displacement, role of table where id =: P10_ID;
I can also add a new line of course.
My problem is, (point) Shift display based on the value of Start_Time point) and so I made sure the class for two items.
for example, Start_Time (' class = "st_tm" ') and Maj ('class to = "Shift_time" '). Start_Time is based on (LOV) and shift is off the point in the sql query, but change the Start_Time.
And now, I created the DA.
1. event: change
Selection type: jQuery Selector
jQuery Selector: .st_tm
Condition: No.
1. action: set value
Set type: Expression Javascript
The JavaScript Expression: $(this.triggeringElement) .val ();
The element affected: P10_X1 (it is a hidden item)
2. action: Plsql Code
Code: start to null; end;
Page items to submit: P10_X1
3. action: Plsql Code
Code: start
If: P10_X1 between '03' AND '11' then
: P10_X1: = 'EARLIES ';
elsif: P10_X1 then '12' and '18'
: P10_X1: = 'LATES ';
on the other
: P10_X1: = 'NIGHTS';
end if;
end;
Page items to submit: P10_X1
NOW another DA
Event: change
Article (s) P10_X1
Condition (in list)
value (HASTY, LATES, NIGHTS)
Action:
Set type: Expression Javascript
The JavaScript Expression: $(this.triggeringElement) .val ();
Affected item:
Selection type: jQuery Selector
jQuery Selector:. Shift_time
Well, I look forward all the above work well, but I'm having a problem.
If I have more than 1 lines on a modal region and if I change the Start_Time value for a row then MAJ (point) is changing but he effect on all lines.
I want, if I make the changes on the line line # 2 while only 2 # MAJ (point) must be not performed any other lines?
Help, please!
Kind regards
RI
I found the solution me thank you.
I removed all the DA mentioned above and created a new.
1. event: change
Selection type: jQuery Selector
jQuery Selector: .st_tm
Condition: No.
Scope of the event: dynamic and light on page load.
Action (Javascript code)
ROW_ID = $(this.triggeringElement).attr('id').substr (4);
If ($(this.triggeringElement). val() > = 03 &. val() $(this.triggeringElement))<= 11)="">=>
.Val ('EARLIES') $(«#f11_» + row_id);
}
ElseIf ($(this.triggeringElement). > 11 val() & $(this.triggeringElement). val())<= 18)="">=>
.Val ('LATES') $(«#f11_» + row_id);
}
ElseIf (. val() > $19 (this.triggeringElement)) {}
.Val ('NIGHTS') $(«#f11_» + row_id);
}
also created another DA because I have a disabled report items.
Event: before the page is sent.
$('_:_disabled').removeAttr ("disabled");
and finally created manual process of DML for tabular and everything works fine. (Insert, Update, and delete).
Kind regards.
-
SQL query to retrieve only numbers to a string variable
Dear all Experts,
I have a requirement in one of my projects where I need to extract only the numbers present in the variable.
for example:
BANK_ACCOUNT_NUMBER = 12345-67890';
BANK_ACCOUNT_NUMBER = 12345 67890';
BANK_ACCOUNT_NUMBER = "123.456.7890";
BANK_ACCOUNT_NUMBER = 123-A456BC7890D';
In all these cases, I need to retrieve only numbers such as BANK_ACCOUNT_NUMBER = 1234567890 and I am looking for SQL query only.
Please suggest me the query how to extract numeric values from varchar variable.
Thank you
Knockaert
select regexp_replace('123-A456BC7890D','[^0-9]') from dual;
See you soon,.
Manik.
-
Calculation of the time wall of a SQL query.
Hello
While trying to discover the time of running a SQL query (wall time) I read in one place that CPU_TIME/EXECUTIONS of v$ SQLAREA, is the precise runtime we can come close to.
I can't use "set timing on ' or 'DBMS_UTILITY. GET_TIME' that I need to extract the execution time of the story because the query will be drawn to an end, and I need to know how long it took to DB level and compare it with the end time before calculating the % of time used in the DB level total.
Maybe another way to track sessions and the user TKPORPOF but now I donot want to take the help of the ADMINISTRATOR at this initial stage.
Is CPU_TIME/EXECUTIONS of v$ SQLAREA where (SQL_TEXT) AS "SELECT... OF... %'; should be enough?
user2925917, yes as Brian already answered your understanding as posted above seems correct. Except in the case where there has been only a running query you will download an average time. The problem with averages is that one or two unusual executions that can skew the average, but in most cases the average will be probably fairly accurate.
- -
HTH - Mark D Powell.
-
How to do a validation based on the SQL query?
Hello
I have a requirement to perform a validation on a field (messageTextinput) in my page OAF.
When I click the button apply, the value in this field is validated based on a SQL query (for example, the value in the field NOT IN (value1 select from table1).)
Help, please.
Best regards
Joe
1. create a SQL query based VO, XXVO. For example:-SQL query is select xx_table;
2. Enter the "Apply" button click event in the controller and run the AM method passing the value entered by the user in the given field, for example:-value is VAL1
3. in the method of the AM, get a handle of the VO, the whereClause and run.
OAViewObjectImpl vo = findViewObject ("XXVO1"); XXVO1 is the name of the instance of the VO above, XXVO
vo.executeEmptyRowSet ();
vo.setWhereClause (null);
vo.setWhereClause ("value =" + VAL1 + "'");
vo.executeQuery ();
If (VO. GetRowCount() > 0)
A record is with the value of VAL1. Perform the required action
I hope this helps.
-
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'.
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
-
Outdoor walk and exercise ring
So I took two walks 15 minutes around the campus to work. I had my phone twice, so he knows that the distance was 0.7 miles each time. Yet, I only managed 17 minutes of exercise. How do I determine what counts exercise walking and what does not wo
-
Satellite P300D - 12L and PCI standard ISA bridge driver
Hello!!!I just installed win XP on Toshiba Satellite P300D - 12L with all the drivers, but I have a problem. In the Device Manager on the "other devices" the foud of windows 'network controller '. In my view, is the standard ISA bridge PCI (PNP ID VE
-
Why Logic Pro 9 to hang when I try to bounce, or "Save as"?
How can I solve the problem of logic 9 crashing whenever I try to bounce a project, or "save under"?
-
Noise DC value of the ini file values
Hello I am trying to build a generator of signals (sine, triangle, sawtooth, square random noise, DC). I managed to get the job of waveform using the signal generator of NOR built based on VI. but I want to add the DC case that I managed to do. but I
-
Spooler does not, file not found
I have the error message on the server print spooler does not. When I go and tell him to start, I get a second error message saying that the system cannot find the specified file. What should I do?