[help needed] Several insert - SQL statement
Hello
This is my table:
{code}
create table test
(
Identification number,
DS varchar (6).
start_date date
);
{code}
There is data in the table.
{code}
Insert test values (1, 'DS1982', TO_DATE ('01.03.2014 ',' DD.)) MM YYYY'));
Insert test values (2, 'DS1982', TO_DATE ('01.04.2014 ',' DD.)) MM YYYY'));
Insert test values (3, 'DS1982', TO_DATE ('01.05.2014 ',' DD.)) MM YYYY'));
Insert test values (4, 'DS1982', TO_DATE ('01.06.2014 ',' DD.)) MM YYYY'));
Insert test values (1, 'DS1999', TO_DATE ('11.04.2014 ',' DD.)) MM YYYY'));
Insert test values (2, 'DS1999', TO_DATE ('11.05.2014 ',' DD.)) MM YYYY'));
Insert test values (3, 'DS1999', TO_DATE ('11.06.2014 ',' DD.)) MM YYYY'));
Insert test values (4, 'DS1999', TO_DATE ('11.07.2014 ',' DD.)) MM YYYY'));
Insert test values (1, 'DS0009', TO_DATE ('21.01.2014 ',' DD.)) MM YYYY'));
Insert test values (2, 'DS0009', TO_DATE ('21.02.2014 ',' DD.)) MM YYYY'));
Insert test values (3, 'DS0009', TO_DATE ('21.03.2014 ',' DD.)) MM YYYY'));
{code}
I have to query all records from the table that has:
Max (start_date) whitin ID and DS culoms.
So, I have to insert in the record in the table for each DS to condition:
Each record will be inserted with incremented id whithin DS
each record inserted must be "newer" than previous 1 month.
Integration goes up to to_char (sysdate, mm) = to_char (start_date, 'mm').
Resoult for DS1982 has so (records to insert):
Insert test values (5, 'DS1982', TO_DATE ('01.07.2014 ',' DD.)) MM YYYY'));
Insert test values (6, 'DS1982', TO_DATE ('01.08.2014 ',' DD.)) MM YYYY'));
Insert test values (7, 'DS1982', TO_DATE ('01.09.2014 ',' DD.)) MM YYYY'));
Insert test values (8, 'DS1982', TO_DATE ('01.10.2014 ',' DD.)) MM YYYY'));
Insert test values (9, 'DS1982', TO_DATE ('01.11.2014 ',' DD.)) MM YYYY'));
Insert test values (10, 'DS1982', TO_DATE ('01.12.2014 ',' DD.)) MM YYYY'));
Insert test values (11, 'DS1982', TO_DATE ('01.01.2015 ',' DD.)) MM YYYY'));
Insert test values (12, 'DS1982', TO_DATE ('01.02.2015 ',' DD.)) MM YYYY'));
Insert test values (13, 'DS1982', TO_DATE ('01.03.2015 ',' DD.)) MM YYYY'));
Insert test values (14, 'DS1982', TO_DATE ('01.04.2015 ',' DD.)) MM YYYY'));
all together for DS1982
Insert test values (1, 'DS1982', TO_DATE ('01.03.2014 ',' DD.)) MM YYYY'));
Insert test values (2, 'DS1982', TO_DATE ('01.04.2014 ',' DD.)) MM YYYY'));
Insert test values (3, 'DS1982', TO_DATE ('01.05.2014 ',' DD.)) MM YYYY'));
Insert test values (4, 'DS1982', TO_DATE ('01.06.2014 ',' DD.)) MM YYYY'));
Insert test values (5, 'DS1982', TO_DATE ('01.07.2014 ',' DD.)) MM YYYY'));
Insert test values (6, 'DS1982', TO_DATE ('01.08.2014 ',' DD.)) MM YYYY'));
Insert test values (7, 'DS1982', TO_DATE ('01.09.2014 ',' DD.)) MM YYYY'));
Insert test values (8, 'DS1982', TO_DATE ('01.10.2014 ',' DD.)) MM YYYY'));
Insert test values (9, 'DS1982', TO_DATE ('01.11.2014 ',' DD.)) MM YYYY'));
Insert test values (10, 'DS1982', TO_DATE ('01.12.2014 ',' DD.)) MM YYYY'));
Insert test values (11, 'DS1982', TO_DATE ('01.01.2015 ',' DD.)) MM YYYY'));
Insert test values (12, 'DS1982', TO_DATE ('01.02.2015 ',' DD.)) MM YYYY'));
Insert test values (13, 'DS1982', TO_DATE ('01.03.2015 ',' DD.)) MM YYYY'));
Insert test values (14, 'DS1982', TO_DATE ('01.04.2015 ',' DD.)) MM YYYY'));
I hope someone can help me with this problem!
Thank you!
This...
SELECT the id + id LEVEL,
DS,
Start_date ADD_MONTHS (start_date, Level)
Of
(SELECT ds,
Max (ID) id,
Date_début Max (start_date)
OF the test
GROUP BY ds)
CONNECT BY LEVEL<=>=>
AND PREREQUISITES ds = ds
AND PRIOR DBMS_RANDOM. VALUE IS NOT NULL.
Thank you
Ann
Tags: Database
Similar Questions
-
create a dynamic help based on a sql statement
Hello
A few years ago, I asked the same question, but I had no adequate answer to my problem:
I have to build a text of dynamic help for items diaplayed (bubble help or better pop-up window). When I go to a header element there is a? Displays and when I click on the left mouse button it will be a constant display text. Now, I have a table with explanation (build on documentation in the table) for each column on each page. If I want to start an SQL statement when I click the button and the text should be displayed in the pop-up window.
An example everywhere or can someone help me otherways?
Concerning
Siegwin
fixed for you, the changes are:
- added onclick = "getItemHelpText('#CURRENT_ITEM_NAME#'); call to your model of 'Optional with Help' for all items using this model will have the same call in.
- adding the global page, page 0,
- moved JavaScript "getItemHelpText" on page 0 to become a global function, so you can use it anywhere in the application
- added item globle P0_DYNAMIC_HELP_TEXT page 0
- update your application process to set the value of P0_DYNAMIC_HELP_TEXT on the convening of AJAX, you must fix the help text.
- help text changed to P41_ENAME in & P0_DYNAMIC_HELP_TEXT.
That's all I think, tested worked.
good luck with the rest...
-
HELP: Need to code SQL to bulk move
I use Oracle 11.2, there are two tables tb_base, tb_hist as follows:
tb_base (number (5) id, varchar2 (16) tag, the timestamp pavers (6));
tb_hist (id number (5), histTs timestamp (6), timestamp (6) the cobblestones, tag varchar2 (16));
tb_base 1, "beard", 20/12/2012
1, 'bbb', 08/12/2012
1, "ccc", 12/30/2012
2, 'aaa', 11/29/2012
2, 'vvv', 28/11/2012
All I need is to move the record iteration with the same id from tb_base to tb_hist as a result:
tb_base 1, "ccc", 12/30/2012
2, 'aaa', 12/29/2012
tb_hist 1, "beard", 20/12/2012, 20/12/2012
1, "bbb", 2012/12/08, 08/12/2012
2, "vvv", 2012/11/28, 28/11/2012
Any suggestion on the SQL to perform this task?
Thank youCopy the historical records of TB_HIST:
INSERT INTO tb_hist (id ,histts ,setts ,tag) SELECT id, setts, setts, tag FROM tb_base a WHERE EXISTS (SELECT 1 FROM (SELECT id, MAX(setts) OVER (PARTITION BY id) max_setts FROM tb_base) b WHERE b.id = a.id AND b.max_setts != a.setts)
Remove the historical records of TB_BASE:
DELETE tb_base a WHERE EXISTS (SELECT 1 FROM (SELECT id, MAX(setts) OVER (PARTITION BY id) max_setts FROM tb_base) b WHERE b.id = a.id AND b.max_setts != a.setts)
-
[Help needed] Several errors in X 40 with ADF security with or without custom login page
OTN greetings community, I'm sorry to bother you again, but I need help again once, links to the relevant files (pastebin and imgur) are on the bottom of the post in the meantime ill try to explain my situation.
I use version 11.1.1.7.0 for JDeveloper with (I assume) updates all of the current side.
In my efforts to learn more about ADF, I had finished the Apps to build with ADF I guide I produce a 'simple' application to manage contacts, companies and their places of activity.
With all my functions done and tested semi (small scale) I went ahead and and tried implement security.
So, with the help of Andrejus Baranovskis Entry of Blog (have been using his blog as a source of information, has contributed to many situations, especially related bean) and fireboxtraining (Part1 and Part2) youtube videos, I have 2 pages, a Login Page (a dispatcher Panel 1 facet has only text showing the user names and passwords connection and the 2nd input text facet 2 related to the bean requesting the user name and Word 3rd password a button that calls the doLogin method) and an error page displays just the text.
So after you have enabled security, create 2 users, create 2 roles of the company, creating application roles 2 and associating all 2 grants of right one to each role app giving privilege to see on the pages I want, I developed (my goal is that in the homepage, using a mixer according to user's role would display a region that all data can be changed or another that all data is read-only but I don't that have not yet implemented).
So I went on the test page and unfortunately I hit the 1st wall would not display the login page (seemed to be always be update a blank page in firefox) so I checked if the pages are in the anonymous role and they were. So, as I saw in the video I deleted the page definition files in the Databindings.cpx file and I am past the 1st obstacle has shown the login page. So I typed the username and passwords and I hit my second wall (error 404 - Not found), I saw the code, debugged it and found that he wouldn't be able to hang or something like that (forgive me for my brutal inexperience) then I disabled the security and reactivated with pages of default form, and when it prompted me to type the user name and password I had hit my 3rd and last wall (error 401 - no allowed) which we I didn't wait, I went in the jazn-"Data.xml" and looked if the grants/permissions/roles were ok, in my inexperience, I don't find any problem, so beat I come here to seek support.
Code:
Error logs:
OnDeploymentScreenshots:
Sorry for the long post and to put the code in another site (not wanted to put this post more than it already is).
Thank you very much for your time and your support.
Hello
Article http://www.oracle.com/technetwork/issue-archive/2012/12-jan/o12adf-1364748.html
comes with a sample download, run and explore.
http://www.Oracle.com/technetwork/issue-archive/2012/12-Jan/o12adf-524995.zip
It includes all your use cases. So I suggest that start here
Note that following the code has experienced problems with recent versions of the IDE instead of a side server before we recommend (and will amend accordingly our documentation) to use a redirect on the facesContext--> externalContext instead (I'm typing through while it's not his apparent
recommended and more)
' Private Sub sendForward (HttpServletRequest, HttpServletResponse response, forwardUrl String query) {}
FacesContext ctx = FacesContext.getCurrentInstance ();
RequestDispatcher dispatcher = request.getRequestDispatcher (forwardUrl);
try {}
Dispatcher.Forward (request, response);
} catch (ServletException to) {}
reportUnexpectedLoginError ("ServletException", is);
} catch (IOException ie) {}
reportUnexpectedLoginError ("IOException", IE);
}
ctx.responseComplete ();
}
Frank
-
Help needed on complex sql resolution
Hi all
I have a table such as indicated and wanted to insert these records in both tables and get the number of each type...
I asssume we can get the account once the algorithm sucssefully inserts the date in the tables.CREATE TABLE RETURN_DEV ( RCODE VARCHAR2(4 BYTE), RNUMBER VARCHAR2(16 BYTE), RDESC VARCHAR2(40 BYTE), RDATE_TIME VARCHAR2(16 BYTE), RQUANTITY VARCHAR2(20 BYTE) ) Insert into RETURN_DEV (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY) Values ('0987', '919341035404586', 'POS:00003:RETR', '20100112112324', '1'); Insert into RETURN_DEV (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY) Values ('0910', '929341035404586', 'POS:00003:REMR', '20100102112324', '1'); Insert into RETURN_DEV (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY) Values ('0914', '939341035404586', 'POS:00003:REMR', '20100111112324', '1'); Insert into RETURN_DEV (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY) Values ('0997', '357991027440360', 'POS:00003: WEXC', '20100102112324', '1'); Insert into RETURN_DEV (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY) Values ('0997', '347991027440360', 'POS:00003: WEXC', '20100102112324', '1'); Insert into RETURN_DEV (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY) Values ('0987', '949341035404586', 'POS:00003:SAXP', '20100512112324', '1'); Insert into RETURN_DEV (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY) Values ('0956', '949341035404586', 'POS:00003:RETR', '20100212112324', '1'); Insert into RETURN_DEV (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY) Values ('0968', '949341035404586', 'POS:00003:SAXP', '20100312112324', '1'); Insert into RETURN_DEV (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY) Values ('0967', '997991027440360', 'POS:00003: USXP', '20060102112324', '-1'); Insert into RETURN_DEV (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY) Values ('0967', '997991027440360', 'POS:00003: USXP', '20070102112324', '1'); Insert into RETURN_DEV (RCODE, RNUMBER, RDESC, RDATE_TIME, RQUANTITY) Values ('0967', '997991027440360', 'POS:00003: USXP', '20080102112324', '-1'); COMMIT; Now my Algorithm go like this step 1: Load 'RET' type into Retail_Table and Count 'RET' type If the RCODE is not in [0910, 0914, 0997] and the RDESC begins with "POS:00003" and RQUANTITY =+1 load these as 'RET' type Step2: Load 'REM' type type into Retail_Table and Count 'REM' type If the RCODE is in [0910, 0914] and RQUANTITY = +1, load these as 'REM' type Step3: Load 'WEX' type into Retail_Table and Count 'WEX' type If the RCODE = 0997 and RQUANTITY = +1, load these as 'WEX' type For me main problem starts here.... Step4: Load'RET' INTO type and 'RETXP' into retail_exceptions, and update the count of 'RET' Type and count 'RETXP' type If the RCODE is not in [0910, 0914, 0997] and the RDESC begins with "POS:00003" and if there is more than one record fitting that criteria in the file for the RNUMBER and the newest record chronologically (RDATE_TIME) has RQUANTITY = +1, then load the latest record as Retail Returns and load all other records into retail_exceptions table. Step5: Load Retail Returns Exceptions as 'RETXP', update the count of Retail Returns and add the count of exceptions If the RCODE is not in [0910, 0914, 0997] and the RDESC begins with "POS:00003" and if there is more than one record fitting that criteria for this RNUMBER and the newest record chronologically (RDATE_TIME) has RQUANTITY = -1, then load all records into to the Retail exceptions table
Thanks in advance...Both the table has the same structure as shown.. CREATE TABLE Retail_Table ( RCODE VARCHAR2(4 BYTE), RNUMBER VARCHAR2(16 BYTE), RDESC VARCHAR2(40 BYTE), RDATE_TIME VARCHAR2(16 BYTE), RTYPE VARCHAR2(20 BYTE) ) CREATE TABLE Retail_Table_Exceptions ( RCODE VARCHAR2(4 BYTE), RNUMBER VARCHAR2(16 BYTE), RDESC VARCHAR2(40 BYTE), RDATE_TIME VARCHAR2(16 BYTE), RTYPE VARCHAR2(20 BYTE) )
Published by: Rede on October 19, 2010 16:20Hello
Sorry, I don't understand still.
Rede says:
Thanks Frank.I thought to explain clearly, but it became huge, then I'll be more clear and precise...I expect the output as shown below
Output Sample data of Retail Table.... RDESC RQUANTITY RNUMBER TRANSACTION_TYPE POS:00003: USXP -1 997991027440360 RET POS:00003: WEXC 1 347991027440360 WEX POS:00003: WEXC 1 357991027440360 WEX POS:00003:REMR 1 929341035404586 REM POS:00003:REMR 1 939341035404586 REM out put sample data of Retail_Exception Table RDESC RQUANTITY RNUMBER TRANSACTION_TYPE POS:00003: USXP -1 997991027440360 RETXP POS:00003: USXP 1 997991027440360 RETXP POS:00003:RETR 1 949341035404586 RETXP POS:00003:SAXP 1 949341035404586 RETXP
CREATE orders TABLE for the retail and retail_exception do not have a rquantity column. If they have this column?
Are the other columns (rcode and rdate_time) of retail and retail_exception supposed to be NULL at this point?What does each line in these tables?
Why there are 9 rows in both tables combined, instead of 11?What i want is individaul counts of all trasaction types.If we can get the counts at time of DML querry it will be good. But i want to keep them in a local variable thats the reason i want to do it in a seperate sql querry. as shown below Transaction_Type Count RETXP 4 WEX 2 RET 2
Please explain how you get these results.
Why is the number 2 when transaction_type = "RET"? Why not 1?
Why don't you want a line to transaction_type = "REM"?These are all numeric values only. since i am getting these values from a external table i kept them as Varchar's. But i will change them accordingly.
What i am trying to do is i grouping the items on the different conditions given below 1. When RCODE In ('0997') And Rquantity = '1' Then 'WEX' 2. When RCODE In ('0910', '0914') And Rquantity = '1' Then 'REM' 3. When RCODE Not In ('0997', '0910', '0914') And RDesc Like 'POS:00003%' And Count ( * ) Over (Partition By RNUMBER) = 1 Then 'RET' its easy till above...but if the third condition has more than 1 record and if the top most record has 4. Rquantity = '-1' then categorise all the records 'RETXP' of that type ( that satisfies the third condition) else if top most record 5. Rquantity = '1' then first record should be categorised as 'RET' and the remaining of that type as 'RETXP'. top most is the record that is sorted by date for a given RNumber.
What is the "first record"? Is it the same as the 'highest '?
Please give specific examples of how you get the desired results of the sample data that you posted.
For example, how do you get the output line:
RDESC RQUANTITY RNUMBER TRANSACTION_TYPE --------------- --------- --------------- ---------------- POS:00003: USXP -1 997991027440360 RET
This line of output appears to be the 'top most' line for rnumber = '997991027440360':
RCODE RNUMBER RDESC RDATE_TIME RQUANTITY ----- ---------------- ------------------ ---------------- --------- 0967 997991027440360 POS:00003: USXP 20060102112324 -1 0967 997991027440360 POS:00003: USXP 20070102112324 1 0967 997991027440360 POS:00003: USXP 20080102112324 -1
Rule 4 does not apply to this rnumber? Isn't the line with rdate_time = '20060102112324' the line ' top more? It is not rquantity = '-1'?
You can do the simple CASE expression (and probably faster) some of the functions of calculation only once, in a subquery, like this:
WITH got_analytics AS ( SELECT rd.* , COUNT (*) OVER ( PARTITION BY rnumber) AS rnumber_cnt , FIRST_VALUE (rquantity) OVER ( PARTITION BY rnumber ORDER BY rdate_time ) AS top_rquantity , ROW_NUMBER () OVER ( PARTITION BY rnumber ORDER BY rdate_time ) AS seq_number FROM return_dev rd ) SELECT rdesc , rquantity , rnumber , CASE WHEN rcode IN ('0997') AND rquantity = '1' THEN 'WEX' WHEN rcode IN ('0910', '0914') AND rquantity = '1' THEN 'REM' WHEN rcode IN ('0997', '0910', '0914') AND rdesc NOT LIKE 'POS:00003%' THEN NULL WHEN rnumber_cnt = 1 THEN 'RET' WHEN top_rquantity = '-1' THEN 'RETXP' WHEN top_rquantity != '1' THEN NULL WHEN seq_number = 1 THEN 'RET' ELSE 'RETXP' END AS transaction_type FROM got_analytics ;
I know that's not what you want, but I think that it is a step in the right direction.
-
Help with the insert statement
Hello
I was wondering if someone could help write me a sql statement.
Here is my table:
Here are the instructions for correct insertion. This time, I posted 2 examples with 2 numbers different otherwise.CREATE TABLE "TEMP_INVOICE" ("INVOICE" VARCHAR2(100 BYTE), "DATE_OF_DOCUMENT" DATE, "DATE_OF_PAY_DAY" DATE, "D" NUMBER, "K" NUMBER );
I want to do is make an insert allows you to table another call is MADE:insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k) values (1000,to_date('01.02.2012','dd.mm.yyyy'),to_date('01.03.2012','dd.mm.yyyy'),5000,0); insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k) values (1000,to_date('01.04.2012','dd.mm.yyyy'),'','',1000); insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k) values (1000,to_date('01.05.2012','dd.mm.yyyy'),'','',3000); insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k) values (1000,to_date('01.06.2012','dd.mm.yyyy'),'','',1000); insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k) values (2000,to_date('01.07.2012','dd.mm.yyyy'),to_date('01.09.2012','dd.mm.yyyy'),8000,0); insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k) values (2000,to_date('01.10.2012','dd.mm.yyyy'),'','',5000); insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k) values (2000,to_date('01.11.2012','dd.mm.yyyy'),'','',2000); insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k) values (2000,to_date('01.12.2012','dd.mm.yyyy'),'','',1000);
Statements in the INVOICE table should be like this:CREATE TABLE "INVOICE" ("INVOICE" VARCHAR2(100 BYTE), "DATE_OF_DOCUMENT" DATE, "DATE_OF_PAY_DAY" DATE, "DATE_OF_PAYMENT_REC" DATE, "VALUE" NUMBER, "VALUE_DEDUCT" NUMBER, "DATE_FROM" DATE, "DATE_TO" DATE );
........ The Bill... date_of_document... date_of_pay_day... date_of_payment_rec... value... value_deduct... Date_from... Date_to
1...... 1000...............1.1.2012.................1.3.2012................NULL............................ 5000... NULL... 1.3.2012...1.4.2012
2...... 1000...............1.4.2012.................NULL..................... 1.4.2012...1000... 4000... 2.4.2012... 1.5.2012
3...... 1000...............1.5.2012.................NULL..................... 1.5.2012...3000... 1000... 2.5.2012... 1.6.2012
4...... 1000...............1.6.2012.................NULL..................... 1.6.2012...1000
Can someone help me with the sql statement that would insert data from table to table Bill temp_invoice as in the example?
Thank you!
PS
I would try to explain.
(1) the first statement that is to be inserted is original imply that at which is different DATE_OF_PAY_DAY to NULL.
To this inserted negative of the original imply, we must add date_from that is exatly the same date_of_pay_day and date_to which is exactly the same as the date of the first payment. Payment which came first!
(2) we have now in the second insert statement. It will be the first payment of lease with date_of_document and date_pf_payment_rec, which is the same as date_fo_document. Value field will be populated with the amount of payment received and value_deduct field will be the value of the original imply - value of the first payment. Date is date_of_document + 1 and date_to is the date of the next payment.
(3) Insert us the next installment. Date_od_payment_rec is the same as date_of_document... value is the amount of the second payment and value_deduct's previous value_deduct which was of 4000 - value of this second payment. date_from date_of_payment_rec + 1 and date_to is the date of the next payment
So we continue this same pattern until we reached the final payment when we finish insert with the statement:
Date of the document (date of the last payment received) and even for date_of_payment_rec and field value with the amount of the payment receieved. The rest (value_deduct, date_from, date_to) is null.
I really hope you understand what I'm trying to do here.
If you have any other questions please.
Published by: user13071990 on November 22, 2012 04:16
Published by: user13071990 on November 22, 2012 04:16Hello
user13071990 wrote:
... Here are the instructions for correct insertion. This time, I posted 2 examples with 2 numbers different otherwise.Ok!
Be sure to post the results you want new data.You probably need to add "PARTITION BY the Bill" to all analytical clauses in my solution:
INSERT INTO invoice ( invoice, date_of_document, date_of_pay_day, date_of_payment_rec , value, value_deduct, date_from, date_to ) SELECT invoice , date_of_document , date_of_pay_day , CASE WHEN k > 0 THEN date_of_document END AS date_of_payment_rec , NVL (d, k) AS value , NVL2 ( date_of_pay_day , NULL , SUM (d) OVER ( PARTITION BY invoice ORDER BY date_of_document ) - SUM (k) OVER ( PARTITION BY invoice ORDER BY date_of_document ) ) AS value_deduct , NVL ( date_of_pay_day , date_of_document + 1 ) AS date_from , LEAD (date_of_document) OVER ( PARTITION BY invoice ORDER BY date_of_document ) AS date_to FROM temp_invoice ;
Because I'm not an English speaker nativ, that I just posted what it should look like after the insert is successful.
OK, so you can't explain as you want, but you still need to explain.
... @Frank Kulash: you are very close, but still not quite what I'm looking for.
Point out where my solution is the production of incorrect results, and explain (as you can) how to get good results in these places.
-
Need help with the insert statement
Hello
I have a question on how to write a SQL statement.
This is the table of "base":
and it comes to resoult in the target table. SQL statement must take care of the insert in a base of the target table table (example below is already provided with test data).CREATE TABLE TEMP_TBL ( id_nr NUMBER, DATE_DOK DATE, DATE_DUE DATE, DATE_DOK_PAY DATE, DEB NUMBER, KRD NUMBER ); insert into temp_tbl (ID_NR,DATE_DOK,DATE_DUE,DATE_DOK_PAY,DEB,KRD)values('1',TO_DATE('11.01.2011','DD.MM.YYYY'),TO_DATE('25.02.2011','DD.MM.YYYY'),NULL,'423,24','0'); insert into temp_tbl(ID_NR,DATE_DOK,DATE_DUE,DATE_DOK_PAY,DEB,KRD)values('2',TO_DATE('16.12.2011','DD.MM.YYYY'),TO_DATE('13.06.2011','DD.MM.YYYY'),NULL,'91270,15','0'); insert into temp_tbl(ID_NR,DATE_DOK,DATE_DUE,DATE_DOK_PAY,DEB,KRD)values('3',TO_DATE('27.09.2011','DD.MM.YYYY'),TO_DATE('27.09.2011','DD.MM.YYYY'),NULL,'0','2000');
If someone could give me a helping hand how write correct insert statement I would be really gratefull.create table table_sod ( id_nr number ,date_from date ,date_to date ,deb_krd number ); One thing to note here : values in column deb_krd under insert 1 and 4 must be summarized in insert 4. insert into table_sod (id_nr,date_from,date_to,deb_krd) values('1',null,to_date('25.02.2011','dd.mm.yyyy'),'423,24'); insert into table_sod(id_nr,date_from,date_to,deb_krd) values('2',to_date('26.02.2011','dd.mm.yyyy'),to_date('13.06.2011','dd.mm.yyyy'),'423,24'); insert into table_sod(id_nr,date_from,date_to,deb_krd)values('3',null,to_date('13.06.2011','dd.mm.yyyy'),'91270,15'); insert into table_sod(id_nr,date_from,date_to,deb_krd)values('4',to_date('14.06.2011','dd.mm.yyyy')to_date('27.09.2011','dd.mm.yyyy'),'91693,39'); insert into table_sod(id_nr,date_from,date_to,deb_krd)values('5',null,to_date('27.09.2011','dd.mm.yyyy'),'2000');
Thank you for your time!I came here with my own assumptions with this
SQL> select rownum id_nr 2 , date_from 3 , date_to 4 , case when date_from is null then deb 5 else sum(case when date_from is not null then deb else 0end) over(order by id_nr, no) 6 end deb_krd 7 from ( 8 select id_nr 9 , case when lg_dt is null or ld_dt = date_due then null else lg_dt+1 end date_from 10 , ld_dt date_to 11 , case when deb = 0 then krd else deb end deb 12 , no 13 from ( 14 select t1.* 15 , lead(t1.date_due) over(order by t1.id_nr, t2.no) ld_dt 16 , lag(t1.date_due) over(order by t1.id_nr, t2.no) lg_dt 17 , t2.no 18 from temp_tbl t1 19 cross 20 join (select 1 no from dual union all select 2 no from dual) t2 21 order by id_nr, no 22 ) 23 where ld_dt is not null 24 ) 25 / ID_NR DATE_FROM DATE_TO DEB_KRD ---------- --------- --------- ---------- 1 25-FEB-11 42324 2 26-FEB-11 13-JUN-11 42324 3 13-JUN-11 9127015 4 14-JUN-11 27-SEP-11 9169339 5 27-SEP-11 2000
-
I need help in the sql statement
Hi all
im working in the hr schema
I need sql statement to answer my question
I need information to all employees
where average wage = average wage department 50
Sorry I can't speak English very well
I thank allThere is no need to do so in the two motions. All you need is:
select * from ( select e.*, avg(case department_id when 50 then salary end) over() dept_50_avg_sal from hr.employees e ) where salary <= dept_50_avg_sal / EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL ----------- -------------------- ------------------------- ------------------------- -------------------- --------- ---------- ---------- -------------- ---------- ------------- --------------- 198 Donald OConnell DOCONNEL 650.507.9833 21-JUN-07 SH_CLERK 2600 124 50 3475.55556 199 Douglas Grant DGRANT 650.507.9844 13-JAN-08 SH_CLERK 2600 124 50 3475.55556 115 Alexander Khoo AKHOO 515.127.4562 18-MAY-03 PU_CLERK 3100 114 30 3475.55556 116 Shelli Baida SBAIDA 515.127.4563 24-DEC-05 PU_CLERK 2900 114 30 3475.55556 117 Sigal Tobias STOBIAS 515.127.4564 24-JUL-05 PU_CLERK 2800 114 30 3475.55556 118 Guy Himuro GHIMURO 515.127.4565 15-NOV-06 PU_CLERK 2600 114 30 3475.55556 119 Karen Colmenares KCOLMENA 515.127.4566 10-AUG-07 PU_CLERK 2500 114 30 3475.55556 125 Julia Nayer JNAYER 650.124.1214 16-JUL-05 ST_CLERK 3200 120 50 3475.55556 126 Irene Mikkilineni IMIKKILI 650.124.1224 28-SEP-06 ST_CLERK 2700 120 50 3475.55556 127 James Landry JLANDRY 650.124.1334 14-JAN-07 ST_CLERK 2400 120 50 3475.55556 128 Steven Markle SMARKLE 650.124.1434 08-MAR-08 ST_CLERK 2200 120 50 3475.55556 EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL ----------- -------------------- ------------------------- ------------------------- -------------------- --------- ---------- ---------- -------------- ---------- ------------- --------------- 129 Laura Bissot LBISSOT 650.124.5234 20-AUG-05 ST_CLERK 3300 121 50 3475.55556 130 Mozhe Atkinson MATKINSO 650.124.6234 30-OCT-05 ST_CLERK 2800 121 50 3475.55556 131 James Marlow JAMRLOW 650.124.7234 16-FEB-05 ST_CLERK 2500 121 50 3475.55556 132 TJ Olson TJOLSON 650.124.8234 10-APR-07 ST_CLERK 2100 121 50 3475.55556 133 Jason Mallin JMALLIN 650.127.1934 14-JUN-04 ST_CLERK 3300 122 50 3475.55556 134 Michael Rogers MROGERS 650.127.1834 26-AUG-06 ST_CLERK 2900 122 50 3475.55556 135 Ki Gee KGEE 650.127.1734 12-DEC-07 ST_CLERK 2400 122 50 3475.55556 136 Hazel Philtanker HPHILTAN 650.127.1634 06-FEB-08 ST_CLERK 2200 122 50 3475.55556 138 Stephen Stiles SSTILES 650.121.2034 26-OCT-05 ST_CLERK 3200 123 50 3475.55556 139 John Seo JSEO 650.121.2019 12-FEB-06 ST_CLERK 2700 123 50 3475.55556 140 Joshua Patel JPATEL 650.121.1834 06-APR-06 ST_CLERK 2500 123 50 3475.55556 EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL ----------- -------------------- ------------------------- ------------------------- -------------------- --------- ---------- ---------- -------------- ---------- ------------- --------------- 142 Curtis Davies CDAVIES 650.121.2994 29-JAN-05 ST_CLERK 3100 124 50 3475.55556 143 Randall Matos RMATOS 650.121.2874 15-MAR-06 ST_CLERK 2600 124 50 3475.55556 144 Peter Vargas PVARGAS 650.121.2004 09-JUL-06 ST_CLERK 2500 124 50 3475.55556 180 Winston Taylor WTAYLOR 650.507.9876 24-JAN-06 SH_CLERK 3200 120 50 3475.55556 181 Jean Fleaur JFLEAUR 650.507.9877 23-FEB-06 SH_CLERK 3100 120 50 3475.55556 182 Martha Sullivan MSULLIVA 650.507.9878 21-JUN-07 SH_CLERK 2500 120 50 3475.55556 183 Girard Geoni GGEONI 650.507.9879 03-FEB-08 SH_CLERK 2800 120 50 3475.55556 186 Julia Dellinger JDELLING 650.509.3876 24-JUN-06 SH_CLERK 3400 121 50 3475.55556 187 Anthony Cabrio ACABRIO 650.509.4876 07-FEB-07 SH_CLERK 3000 121 50 3475.55556 190 Timothy Gates TGATES 650.505.3876 11-JUL-06 SH_CLERK 2900 122 50 3475.55556 191 Randall Perkins RPERKINS 650.505.4876 19-DEC-07 SH_CLERK 2500 122 50 3475.55556 EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL ----------- -------------------- ------------------------- ------------------------- -------------------- --------- ---------- ---------- -------------- ---------- ------------- --------------- 194 Samuel McCain SMCCAIN 650.501.3876 01-JUL-06 SH_CLERK 3200 123 50 3475.55556 195 Vance Jones VJONES 650.501.4876 17-MAR-07 SH_CLERK 2800 123 50 3475.55556 196 Alana Walsh AWALSH 650.507.9811 24-APR-06 SH_CLERK 3100 124 50 3475.55556 197 Kevin Feeney KFEENEY 650.507.9822 23-MAY-06 SH_CLERK 3000 124 50 3475.55556 37 rows selected. SQL>
SY.
-
Need help to resolve the error - below the SQL statement to execute cannot be
Below is my CO as, which creates a callable statement.
try {}
OAApplicationModule oaapplicationmodule = (webBean) pageContext.getApplicationModule;
OADBTransactionImpl t = (OADBTransactionImpl) oaapplicationmodule.getOADBTransaction ();
OracleCallableStatement proc = (OracleCallableStatement) t.createCallableStatement (lquery,-1);
proc. Execute();
t.Commit ();
}
catch (SQLException sqlexception)
{
throw OAException.wrapperException (sqlexception);
}
After the execution of the page, get the below error... (Please find below stack error)
I have referred the development guide but did not get something useful.
Please give me clues about the same.
Raghu cordially
-- Error Stack ---------------------------------------------------------
Error page
Details of the exception.
oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: Houston-27123: SQL error in the preparation of the call statement. Statement: null
at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:888)
at oracle.apps.fnd.framework.webui.OAPageErrorHandler.prepareException(OAPageErrorHandler.java:1145)
at oracle.apps.fnd.framework.webui.OAPageErrorHandler.processErrors(OAPageErrorHandler.java:1408)
at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest(OAPageBean.java:2637)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1659)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:497)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:418)
in OA. jspService(OA.jsp:40)
at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:317)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:727)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:259)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:106)
to EDU.oswego.cs.dl.util.concurrent.PooledExecutor$ Worker.run (PooledExecutor.java:803)
at java.lang.Thread.run(Thread.java:534)
# # 0 in detail
java.sql.SQLException: the SQL statement to execute cannot be empty or null
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.driver.OracleConnection.privatePrepareCall(OracleConnection.java:1138)
at oracle.jdbc.driver.OracleConnection.prepareCall(OracleConnection.java:1054)
at oracle.jbo.server.DBTransactionImpl.createCallableStatement(DBTransactionImpl.java:3033)
at cisco.oracle.apps.xxchr.element.server.webui.XXCHRElementSetSearchCO.processFormRequest(XXCHRElementSetSearchCO.java:343)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:799)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363)
at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processFormRequest(OAPageLayoutHelper.java:1118)
at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processFormRequest(OAPageLayoutBean.java:1579)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:995)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:961)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:816)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363)
at oracle.apps.fnd.framework.webui.beans.form.OAFormBean.processFormRequest(OAFormBean.java:395)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:995)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:961)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:816)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363)
at oracle.apps.fnd.framework.webui.beans.OABodyBean.processFormRequest(OABodyBean.java:363)
at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest(OAPageBean.java:2633)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1659)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:497)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:418)
in OA. jspService(OA.jsp:40)
at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:317)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:727)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:259)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:106)
to EDU.oswego.cs.dl.util.concurrent.PooledExecutor$ Worker.run (PooledExecutor.java:803)
at java.lang.Thread.run(Thread.java:534)
java.sql.SQLException: the SQL statement to execute cannot be empty or null
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.driver.OracleConnection.privatePrepareCall(OracleConnection.java:1138)
at oracle.jdbc.driver.OracleConnection.prepareCall(OracleConnection.java:1054)
at oracle.jbo.server.DBTransactionImpl.createCallableStatement(DBTransactionImpl.java:3033)
at cisco.oracle.apps.xxchr.element.server.webui.XXCHRElementSetSearchCO.processFormRequest(XXCHRElementSetSearchCO.java:343)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:799)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363)
at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processFormRequest(OAPageLayoutHelper.java:1118)
at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processFormRequest(OAPageLayoutBean.java:1579)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:995)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:961)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:816)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363)
at oracle.apps.fnd.framework.webui.beans.form.OAFormBean.processFormRequest(OAFormBean.java:395)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:995)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(OAWebBeanHelper.java:961)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(OAWebBeanHelper.java:816)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(OAWebBeanContainerHelper.java:363)
at oracle.apps.fnd.framework.webui.beans.OABodyBean.processFormRequest(OABodyBean.java:363)
at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest(OAPageBean.java:2633)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1659)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:497)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:418)
in OA. jspService(OA.jsp:40)
at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:317)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:727)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:259)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:106)
to EDU.oswego.cs.dl.util.concurrent.PooledExecutor$ Worker.run (PooledExecutor.java:803)
at java.lang.Thread.run(Thread.java:534)
Published by: Rambeau on Oct 14, 2010 02:58check the code stuck by me again
Connection Conn = pageContext.getApplicationModule (webBean) .getOADBTransaction () .getJdbcConnection ();
Connection conn = oaapplicationmodule.getOADBTransaction().getJdbcConnection(); //Right one
Thank you
-Anil -
Sql statement variable gives several values
Hello
I have a variable that has sql statement and it gives several values and I want to use this variable in one of the filter of interface condition to filter the data in the source table (which has millions of records).
some could let me know the best method to achieve this scenario.
Appreciate your help.You are right. Yesterday, I don't think in this case where the data could be from a different server. But I completely forgot today.
Ok. Here you can find how to use sys_connect_by_pathhttp://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:907278700346567560
Be careful with the size because I think that there is a limit to what can contain the variable ODI.
After you have assessed the variable is how it could be used in the filter
ITEM_TYPE_ID IN (#var_csv_id_list)
-
Help with a SQL statement...
Hello...
I have tried to find a way to write a SQL statement and may not seem to produce something that works. What I need is a set of results that returns each month that a given task is in an open State. The only columns that I have in my work table with are TASK_NM, OPEN_DT and CLOSED_DT.
So if I have a line containing the following: TASK_NM = 'task one', OPEN_DT = April 18, 10 ' and CLOSED_DT = 14 October 10 '... I would like to see as a result set that looks like:
TASK_NM YEAR JAN FEB MAR APR MAY JUNE JULY AUG SEP OCT NOV DEC
the task of a 2010 0 0 0 1 1 1 1 1 1 1 0 0
Is it still possible?
Thanks in advance,
David.
Published by: user13027968 on March 10, 2011 14:19
Published by: user13027968 on March 10, 2011 15:13Hello
Welcome to the Forum!
Whenever you have a question. Please post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data.
For example, the sample data may be:CREATE TABLE table_x ( task_nm VARCHAR2 (10) , open_dt DATE , closed_dt DATE ); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('task a', DATE '2010-04-18', DATE '2010-10-14'); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('foo', DATE '2010-10-31', DATE '2011-01-01'); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('foo', DATE '2010-12-01', DATE '2011-02-21'); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('foo', DATE '2011-04-01', DATE '2011-04-30'); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('bar', DATE '2010-01-01', DATE '2010-01-01');
From this data, you may want these results:
TASK_NM YEAR JAN FEB MAR APR MAY JUN JUL AUG SEP OVT NOV DEC ---------- ----- --- --- --- --- --- --- --- --- --- --- --- --- bar 2010 1 0 0 0 0 0 0 0 0 0 0 0 foo 2010 0 0 0 0 0 0 0 0 0 1 1 1 foo 2011 1 1 0 1 0 0 0 0 0 0 0 0 task a 2010 0 0 0 1 1 1 1 1 1 1 0 0
I'm not sure eactly how you plan to use it. Are there lines that overlap for the name of the task? You always want the same number of columns? What version of Oracle are you using?
I think you want something like this:WITH got_month_cnt AS ( SELECT task_nm , TRUNC (open_dt, 'MONTH') AS first_month , 1 + MONTHS_BETWEEN ( TRUNC (closed_dt, 'MONTH') , TRUNC (open_dt, 'MONTH') ) AS month_cnt FROM table_x -- WHERE ... -- If you want any filtering, put it here ) , cntr AS ( SELECT LEVEL AS n FROM ( SELECT MAX (month_cnt) AS max_month_cnt FROM got_month_cnt ) CONNECT BY LEVEL <= max_month_cnt ) , all_months AS ( SELECT m.task_nm , ADD_MONTHS ( m.first_month , c.n - 1 ) AS open_month FROM got_month_cnt m JOIN cntr c ON c.n <= m.month_cnt ) SELECT task_nm , EXTRACT (YEAR FROM open_month) AS year , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Jan' THEN 1 ELSE 0 END) AS jan , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Feb' THEN 1 ELSE 0 END) AS feb , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Mar' THEN 1 ELSE 0 END) AS mar , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Apr' THEN 1 ELSE 0 END) AS apr , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'May' THEN 1 ELSE 0 END) AS may , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Jun' THEN 1 ELSE 0 END) AS jun , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Jul' THEN 1 ELSE 0 END) AS jul , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Aug' THEN 1 ELSE 0 END) AS aug , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Sep' THEN 1 ELSE 0 END) AS sep , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Oct' THEN 1 ELSE 0 END) AS ovt , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Nov' THEN 1 ELSE 0 END) AS nov , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Dec' THEN 1 ELSE 0 END) AS dec FROM all_months GROUP BY task_nm , EXTRACT (YEAR FROM open_month) ORDER BY task_nm , year ;
This will work in Orfacle 9 (and), but from Oracle 11, you could simplify it a little bit by using SELECT... Function PIVOT.
Published by: Frank Kulash, March 10, 2011 16:51
-
Dear Experts,
I need a clarification. Is it possible to use the fn - bea: function execute sql (Oracle Service Bus) to perform an insert operation in a database with the data extracted from the message of the Organization (i.e. $body/Info/username)? If it is possible which is the right syntax?
Any suggestion is appreciated.
Kind regards
Mike
Published by: ITDeveloper on November 19, 2009 2.55
Published by: ITDeveloper on November 19, 2009 3.01Hi Mike,.
Please refer to my post for the same question to the fn - bea: sql performance with 'Insert INTO' the sql statement
Thank you best regards &,.
Vivek
-
With the help of a number variable in a SQL statement
Hello
I am trying to use a variable in a sql statement, and I ran into problems when the variable is a number. The following line of code works if the variable is a string, but not if it is a number.
"SELECT PAGE 1 UUT_STATUS OF UNIT_UUT_RESULT WHERE UnitID = '" + Locals.LocalUnitID + "' ORDER BY DESC START_DATE_TIME.
Is there a difference in the use of single and double quotes and the sign for numbers variables +?
Thank you
Stuart
Jervin is almost correct in the post above.
While it is correct that numbers in SQL are not enclosed in single quotes ('), we still need the entire expression to a string. If Locals.LocalUnitID is stored as a number to TestStand, you will need to cast to a string so that the string concatination works properly.
I believe that the correct form is as follows:
"SELECT PAGE 1 UUT_STATUS OF UNIT_UUT_RESULT WHERE UnitID ="+ Str (Locals.LocalUnitID) + 'ORDER BY DESC START_DATE_TIME'
-
Need help! Working with SQL databases
Hi all
I am currently working on an application that interacts with a SQL database, and it seems to have hit a roadblock.
I have a multi-column list box on my front which is filled with the data extracted from the database. By choosing one of the lines in the list box, another opens showing another set of data retrieved by a generated SQL query. At the moment I only select one line at a time to see it has the data, but I want to expand such that I can select mutiple rows in the list both box and see all their relevant data.
With only one selection, I can switch the index value of the selection of a function table of Index with the database as another entry and build my SQL statement.
But with multiple choices, I guess I have to build a table on the index values and use them as reference to build the SQL statement. And I don't know how exactly to do that.
Here is the code that I currently work for a single selection in the drop-down list.
Any help is appreciated. See you soon.
tdog says:
Hi all
I am currently working on an application that interacts with a SQL database, and it seems to have hit a roadblock.
I have a multi-column list box on my front which is filled with the data extracted from the database. By choosing one of the lines in the list box, another opens showing another set of data retrieved by a generated SQL query. At the moment I only select one line at a time to see it has the data, but I want to expand such that I can select mutiple rows in the list both box and see all their relevant data.
With only one selection, I can switch the index value of the selection of a function table of Index with the database as another entry and build my SQL statement.
But with multiple choices, I guess I have to build a table on the index values and use them as reference to build the SQL statement. And I don't know how exactly to do that.
Here is the code that I currently work for a single selection in the drop-down list.
Any help is appreciated. See you soon.
Regarding the table of construction:
I can see Hat multicolumn listbox you have multiselection enabled and is limited to one or zero element selected at a time. To allow multiselction; Done just right click your multi-column listbox and change your selection to support multiple selected items. The NewVal to the structure of the event should change to a single index number in a 1 d of the numbers indexed table. No coding required. Then just to retrieve all items (since you know the index) and create the quiry. Quiry part, I'm not really (long time no see SQL), but it looks like a loop for to create the chain should do the trick?
-
BlackBerry 10 need help to quickly insert a lot of inserts/Word sub to the many BB features
Hello. Please help if you know ways to do this.
I need a way to insert a large number of inserts of many devices of BB quickly on BB OS 10.
I use dozens of BB Phone for my business, and I use hundreds of AutoText to meet my clients. Also it is not possible to manually insert/Enter AutoText one by one in every phone.In blackberry OS 6, I just restore the data and choose AutoText to insert my automatic backup to new phone. But on BB OS 10, it says legacy files are not supported.
I also try to do a backup on BB 10 phone to copy inserts, but when restoring to another phone (for copy insertions), it must be in the same ID of BB.
What is another way to help me to insert these inserts to other phones other than by using the manual method (input a)?Thank you
None that I know. There is no party 3rd backup/restore of insertion is.
Maybe you are looking for
-
Pavillion Mini 300-019: upgrading RAM MINI 300-019
I want to upgrade the RAM in the Mini 300-019, I just bought, but did not have in my possession at the moment. It comes with 4 GB in total. I'm looking to get at least 2 X 4 GB modules (8 GB total), but perhaps also the modules of 2 X 8 GB (16 GB tot
-
Satellite L50 - B suddenly does not recognize USB devices
Suddenly my laptop does not recognize any USB. The USB key or external hard drive works on other computers, but not on my laptop.Only cards SD-are recognized. I tried to remove the usb portals on the Control Panel, but after I restarted my computer a
-
Need some drivers for my Satellite A100
Dear all, Could someone help me? I bought my laptop (Satellite A100, PSAA9) with XP 2007 April.Yet I have installed the Microsoft Windows Vista Ultimate 32-bit OS (with SP1) Vista has found a lot of drivers for my laptop, but someone is missing.For e
-
Record streaming audio / Windows 7
My Dell is not equipped with the function of "stereo mix". I tried everything, search driver for graphic software its right click-> recorders-> do a right click on an empty space-> checking both "show disabled devices" and "show disconnected devices.
-
Windows 7 using the Vista license
Can I put a Vista system to Windows 7 using the Vista license without buying the upgrade license?