Query to calculate value and produce new rows
QUARTER CUSTOMER PRODUCT RETAIL_SALES_AMT WHOLESALE_AMT
01/01/2006 ABC VACCUM CLEANER 454234.00 65633456.00
04/01/2006 ABC VACCUM CLEANER 324562.00 45333234.00
07/01/2006 ABC VACCUM CLEANER NULL 67845423.00
10/01/2006 ABC VACCUM CLEANER NULL 67453453.00
01/01/2007 ABC VACCUM CLEANER NULL 56754633.00
04/01/2007 ABC VACCUM CLEANER NULL 45423434.00
Hi guys,
It is a situation where i have to produce some new rows with projected RETAIL_SALES_AMT based on the last quarter's
RETAIL_SALES_AMOUNT and next quarte'rs WHOLESALE_AMT. As you can see from the sample data for a specific customer,
product i have retail_sales_amt populated only upto 04/01/2006 but WHOLE_SALE amt for the same product and customer
are there upto 04/01/2007.
I have to produce a PROJECTED RETAIL_SALES_AMT and it should be inserted as a new row with a flag to identify
a projected row. Here in this case i have to produce a new row for 07/01/2006,10/01/2006 & 01/01/2007 projecting
the RETAIL_SALES_AMT. The formulae for calculation is as under:
projected retail_sales_amt for 07/01/2006=.345+( (07/01/2006 whole_sales - 04/01/2006 whole_sales)/(04/01/2006 whole_sale)))
*04/01/2006 RETAIL_SALES_AMT and going forward for subsequent quarters.
Is there any way i can use a query to produce these new rows by calculating the RETAIL_SALES_AMT on the fly or any
procedural way to do it.
Please help as it looks a bit complicated logic.
Regards
Edited by: user626688 on Oct 27, 2009 11:26 AM
Edited by: user626688 on Oct 27, 2009 11:26 AM
Edited by: user626688 on Oct 27, 2009 11:27 AM
Edited by: user626688 on Oct 27, 2009 11:28 AM
Edited by: user626688 on Oct 27, 2009 11:31 AM
Edited by: user626688 on Oct 27, 2009 11:32 AM
I'm not sure if this is exactly what you want but this shows you the possibilities:
WITH sales_table AS
SELECT TO_DATE('01/01/2006','MM/DD/YYYY') AS QUARTER, 'ABC' AS CUSTOMER, 'VACUUM CLEANER' AS PRODUCT, 454234 AS RETAIL_SALES_AMT, 65633456 AS WHOLESALE_AMT FROM DUAL UNION ALL
SELECT TO_DATE('04/01/2006','MM/DD/YYYY') AS QUARTER, 'ABC' AS CUSTOMER, 'VACUUM CLEANER' AS PRODUCT, 324562 AS RETAIL_SALES_AMT, 45333234 AS WHOLESALE_AMT FROM DUAL UNION ALL
SELECT TO_DATE('07/01/2006','MM/DD/YYYY') AS QUARTER, 'ABC' AS CUSTOMER, 'VACUUM CLEANER' AS PRODUCT, NULL AS RETAIL_SALES_AMT, 67845423 AS WHOLESALE_AMT FROM DUAL UNION ALL
SELECT TO_DATE('10/01/2006','MM/DD/YYYY') AS QUARTER, 'ABC' AS CUSTOMER, 'VACUUM CLEANER' AS PRODUCT, NULL AS RETAIL_SALES_AMT, 67453453 AS WHOLESALE_AMT FROM DUAL UNION ALL
SELECT TO_DATE('01/01/2007','MM/DD/YYYY') AS QUARTER, 'ABC' AS CUSTOMER, 'VACUUM CLEANER' AS PRODUCT, NULL AS RETAIL_SALES_AMT, 56754633 AS WHOLESALE_AMT FROM DUAL UNION ALL
SELECT TO_DATE('04/01/2007','MM/DD/YYYY') AS QUARTER, 'ABC' AS CUSTOMER, 'VACUUM CLEANER' AS PRODUCT, NULL AS RETAIL_SALES_AMT, 45423434 AS WHOLESALE_AMT FROM DUAL
SELECT QUARTER
, CUSTOMER
, PRODUCT
, RETAIL_SALES_AMT
, WHOLESALE_AMT
, PROJECTED_FLG
FROM SALES_TABLE
MODEL
DIMENSION BY
QUARTER
, CUSTOMER
, PRODUCT
MEASURES
RETAIL_SALES_AMT
, WHOLESALE_AMT
, 'F' AS PROJECTED_FLG
RULES
PROJECTED_FLG[ANY,ANY,ANY] = (CASE
WHEN RETAIL_SALES_AMT[cv(),cv(),cv()] IS NULL AND RETAIL_SALES_AMT[cv(),cv(),cv()] IS PRESENT
THEN 'T'
ELSE 'F'
END)
, RETAIL_SALES_AMT[ANY,ANY,ANY] = (CASE
WHEN RETAIL_SALES_AMT[cv(),cv(),cv()] IS NULL AND RETAIL_SALES_AMT[cv(),cv(),cv()] IS PRESENT
THEN RETAIL_SALES_AMT[ADD_MONTHS(cv(),-3),cv(),cv()]*(.345 + ((WHOLESALE_AMT[cv(),cv(),cv()] - WHOLESALE_AMT[ADD_MONTHS(cv(),-3),cv(),cv()])/WHOLESALE_AMT[ADD_MONTHS(cv(),-3),cv(),cv()]))
ELSE
RETAIL_SALES_AMT[cv(),cv(),cv()]
END)
ORDER BY 1, 2, 3Results:
QUARTER CUS PRODUCT RETAIL_SALES_AMT WHOLESALE_AMT P
01/01/2006 00:00:00 ABC VACUUM CLEANER 454234 65633456 F
04/01/2006 00:00:00 ABC VACUUM CLEANER 324562 45333234 F
07/01/2006 00:00:00 ABC VACUUM CLEANER 273149.267 67845423 T
10/01/2006 00:00:00 ABC VACUUM CLEANER 92658.4052 67453453 T
01/01/2007 00:00:00 ABC VACUUM CLEANER 17270.5619 56754633 T
04/01/2007 00:00:00 ABC VACUUM CLEANER 2510.23463 45423434 TEdited by: Centinul on Oct 27, 2009 3:00 PM
Similar Messages
-
How can I Add and save new row in data table?
Hello All,
I want to add new row in the jsf page with data and save it.
I have data table with rows from database..
<h:form id="test">
<h:dataTable id="hh" value="#{MyBean.dataList}" var="list">
<h:column>
<h:outputText value="#{list.name}"/>
</h:column>
<h:column>
<h:outputText value="#{list.lastName}"/>
</h:column>
<h:column>
<h:outputText value="#{list.phone}"/>
</h:column>
</h:dataTable>
<h:commandButton id="sd" action="#{MyBean.addNewRow" value="Add Row" />
<h:commandButton id="save" action="#{MyBean.updateList" value="Save Data />
</h:form>
{code}
i understand action with save to database, but still I could not find right way to add new row from jsf page.....
I want add new row, add new name, lastname, and save it....
Edited by: armen on Feb 20, 2009 12:39 AMThanks, but your example consist from too many parts and I could not join all components for understatnding all proccess.
-
Get Old Value and the new value based on the date
Hi
I have a table called roster created below with following insert statements.
CREATE TABLE ROSTER
ROSTER_EMPLOYEE_DEF_ID NUMBER,
EMPLOYEE_ID NUMBER,
DEFINITION_REGION_CODE NUMBER,
DEFINITION_DISTRICT_CODE NUMBER,
DEFINITION_TERRITORY_CODE NUMBER,
START_DATE DATE,
END_DATE DATE
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(1,299,222,333,444,'1-JUN-2011','30-JUN-2011')
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(2,299,223,334,445,'1-JUL-2011','20-JUL-2011')
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(3,299,224,335,446,'1-AUG-2011','30-AUG-2011')
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(4,300,500,400,300,'1-JUN-2011','20-JUN-2011')
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(5,300,501,401,301,'1-JUL-2011','20-JUL-2011')
In the above table we have columns like
EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE
The result i am looking from the above table is based on the EMPLOYEE_ID OF START_DATE AND END_DATE
I need to get OLD_DEFINITION_REGION_CODE and the NEW_DEFINITION_CODE
Similarly OLD_DEFINITION_REGION_CODE and the NEW_DEFINITION_REGION_CODE
and OLD_DEFINITION_TERRITORY_CODE and the NEW_DEFINITION_TERRITORY_CODE
I need to get one row of data for each employee saying old value and new value
for employee 299 there are 3 records it must give the new record which is the latest date i.e start date 1-aug-2011 and end date 30-aug-2011 old record will be
start date 1-jul-2011 and 20-jul-2011
For the above table data i need to get the data as below
EMPLOYEE_ID OLD_DEFINITION_REGION_CODE NEW_DEFINITION_CODE OLD_DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE START_DATE END_DATE
299 223 224 334 335 20-JUL-11 30-AUG-11
300 500 501 400 401 20-JUN-11 20-JUL-11
Please suggest me to get the above result based on the data. Please let me know if my posts are not clear
Thanks
SudhirSELECT EMPLOYEE_ID,
OLD_DEFINITION_REGION_CODE,
NEW_DEFINITION_REGION_CODE,
OLD_DEFINITION_DISTRICT_CODE,
NEW_DEFINITION_DISTRICT_CODE,
OLD_DEFINITION_TERRITORY_CODE,
NEW_DEFINITION_TERRITORY_CODE,
START_DATE,
END_DATE
FROM (
SELECT EMPLOYEE_ID,
ROW_NUMBER() OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE DESC) RN,
LAG(DEFINITION_REGION_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_REGION_CODE,
DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE,
LAG(DEFINITION_DISTRICT_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_DISTRICT_CODE,
DEFINITION_DISTRICT_CODE NEW_DEFINITION_DISTRICT_CODE,
LAG(DEFINITION_TERRITORY_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_TERRITORY_CODE,
DEFINITION_TERRITORY_CODE NEW_DEFINITION_TERRITORY_CODE,
LAG(END_DATE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) START_DATE,
END_DATE
FROM ROSTER
WHERE RN = 1
EMPLOYEE_ID OLD_DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE OLD_DEFINITION_DISTRICT_CODE NEW_DEFINITION_DISTRICT_CODE OLD_DEFINITION_TERRITORY_CODE NEW_DEFINITION_TERRITORY_CODE START_DAT END_DATE
299 223 224 334 335 445 446 20-JUL-11 30-AUG-11
300 500 501 400 401 300 301 20-JUN-11 20-JUL-11
SQL> SY. -
What do I need to do to default some values when a new row is created in a tabular form?
Hello all -
I have a tabular form which requires a few columns to be entered by the user when s/he creates a new row, but other fields in the column can just default to certain values. How do I set those default values so that the user doesn't have to be bothered with entering any data except those that MUST be entered?
An example:
Form1
REGION COUNTRY CITY
APAC JAPAN TOKYO
APAC AUSTRALIA SIDNEY
APAC KOREA SEOUL
REGION is nearly always APAC, so I want to default to that. The user can still adjust it if necessary, but I want to set it for the user, just to save having to enter a value. When the user clicks the the Add Row button, I want to load that value right away and leave the next two fields blank so the user can enter whatever they want.
Thanks!
JohnHi,
Go edit that column.
Under Tabular Form Attributes you can find options to set default value
Regards,
Jari -
Min and Max and insert new rows
Hello,
I am really a beginner in Excel (2007). I am not sure if this is the correct forum, anyway.
I have grouped some rows in a sheet (rows 1, 2 and 3, columns A and B, table below), some of the columns have numeric values in that group and I have a row (inside that group) that shows the maximum and minimum values (row 1):
A B
+ 1 43 12 <- MAX and MIN values for row 2 and 3 columns A and B
+ 2 34 12
+ 3 43 34
I am using MAX and MIN functions: A1 = MAX($A2:$A$3), B1 = MIN($B$2:$B$3)
The problem comes when I want to insert more rows after row 3, the formula keeps wrapping to A$2:$A$3 therefore I need to readjust the formula to: MAX($A2:$A$4) manually (for MIN is the same).
A B
+ 1 43 12 <- Are the same, they should be
"98 and 10"
+ 2 34 12
+ 3 43 34
+ 4 98 10 <- New row, but the maximum and minimum continues to be the same, I want to extend the formula automatically to the 4 row when I insert the new row.
Question:
How can I extend the function of the MAX and MIN formula automatically when I insert new rows?
Please consider that I may insert rows at the beginning, in the middle or the end.
Thanks,
Enrique.
Kikeman Electric Systems EngineerHi Enrique,
Thanks for posting in MSDN.
Based on the description, you want to modify the formula for the A1 and B1 cell when you insert a new rows.
Yes, we can use Worksheet.Change to dermin the change of data on the worksheet then we can modify the formula as we wanted. Here is a sample for your reference:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("A1").Formula = "=MAX($A2:$A" & Me.UsedRange.Rows.Count & ")"
Me.Range("B1").Formula = "=MIN($B2:$B" & Me.UsedRange.Rows.Count & ")"
End Sub
You can more detail about Excel VBA developing from link below:
Getting Started with VBA in Excel 2010
Welcome to the Excel 2013 developer reference
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Split Oracle 11g Table Partition and Insert new rows
Hi,
I have a doubt that i would like to be clarified. I need to split a partition of a table with more than 800 Million records, but at the same time (during the split operation) i need to insert new records (not in the partition that is being splited). Is there any problem/risk doing this? Is the insert ETL process going to fail ?
Thanks in advance
Greetings.
Nuno
Edited by: user13512889 on 1/Set/2011 3:25Hi Enrique,
Thanks for posting in MSDN.
Based on the description, you want to modify the formula for the A1 and B1 cell when you insert a new rows.
Yes, we can use Worksheet.Change to dermin the change of data on the worksheet then we can modify the formula as we wanted. Here is a sample for your reference:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("A1").Formula = "=MAX($A2:$A" & Me.UsedRange.Rows.Count & ")"
Me.Range("B1").Formula = "=MIN($B2:$B" & Me.UsedRange.Rows.Count & ")"
End Sub
You can more detail about Excel VBA developing from link below:
Getting Started with VBA in Excel 2010
Welcome to the Excel 2013 developer reference
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Display value and percentage of row in pivot table w/o double counting...
Hello,
I am wondering how/if one can show a metric value and the row percentage it represents without double counting. So far, I have attempted to duplicate the metric value layer, move the duplicated layer in the measures section of the pivot table next to the original layer (i.e. I have the value twice in the measure section), and set the format of the duplicated layer to "show data as > percent > row".
This makes the trick in terms of the data I see in the table; however, the values displayed in the table are double counted in the chart. I guess this makes sense since I have duplicated the metric value.
Any thoughts on how I could tackle this issue differently?
Thanks,
JPYou can do all that in the Pivot Table... Go to the measure properties and Duplicate Layer...than Show as...
Dont need to duplicate the criteria...
Antonio
BExpert Brazil -
Retrieve data from a text file, incrementing the last value and save new value below
Hi
This was working initially. It is part of my LabView Project. I was trying to create a unique number that increments every time the adds the value to the list. It works on computer perfectly. But when I put this on a PDA, it seems to create a blank space when reading the contents of the text file after the last value, which means 0 + 1, which is not what I want.
Please run the testUniqueNoOnPDA.vi first and change the path to C:\uniqueNumber.txt and save the uniqueNumber.txt file to your C drive and see What I am trying to do. Click the Enter button to increment.
Why does the PDA create a blank space after the last value and a computer does not?
I was working perfectly all week and it is not working well now.
Help please, I think I'm missing something
Attachments:
uniqueNumber.txt 1 KB
testUniqueNoOnPDA.vi 33 KB
testUniqueNoOnPDA.lvproj 4 KBIt works perfectly, it was a hardware problem. It depends on what PDA I used.
-
Querying on a value and using that to pull other data in the same query
I am having some issues pulling the correct data in a query. There is a table that houses application decision data that has a certain decision code in it, WA, for a particular population of applicants. These applicants also may have other records in the same table with different decision codes. Some applicants do NOT have WA as a decision code at all. What I need to do is pull anyone whose maximum sequence number in the table is associated with the WA decision code, then list all other decision codes that are also associated with the same applicant. These do not necessarily need pivoted, so long as I can pull all the records for a person whose highest sequence number is associated with WA and all of the other decision codes for that applicant for the same term code and application number also appear as rows in the output.
I do not have the rights in Oracle to create tables, so please pardon if this code to make the table is incorrect or doesn't show up here as code. This is not the entire SARAPPD table framework, just the pertinent columns, along with some data to put in them.
DROP TABLE SARAPPD;
CREATE TABLE SARAPPD
(PIDM NUMBER(8),
TERM_CODE_ENTRY VARCHAR2(6 CHAR),
APDC_CODE VARCHAR2(2 CHAR),
APPL_NO NUMBER(2),
SEQ_NO NUMBER(2));
INSERT INTO SARAPPD VALUES (12345,'201280','WA',1,4);
INSERT INTO SARAPPD VALUES (12345,'201280','RE',1,3);
INSERT INTO SARAPPD VALUES (12345,'201280','AC',1,2);
INSERT INTO SARAPPD VALUES (23456,'201280','RE',1,2);
INSERT INTO SARAPPD VALUES (23456,'201280','WA',1,3);
INSERT INTO SARAPPD VALUES (23456,'201280','SC',1,1);
INSERT INTO SARAPPD VALUES (34567,'201280','AC',1,1);
INSERT INTO SARAPPD VALUES (45678,'201210','AC',2,1);
INSERT INTO SARAPPD VALUES (45678,'201280','AC',1,2);
INSERT INTO SARAPPD VALUES (45678,'201280','WA',1,3);
INSERT INTO SARAPPD VALUES (56789,'201210','SC',1,2);
INSERT INTO SARAPPD VALUES (56789,'201210','WA',1,3);
COMMIT;I have attempted to get the data with a query similar to the following:
WITH CURR_ADMIT AS
SELECT C.SEQ_NO "CURR_ADMIT_SEQ_NO",
C.PIDM "CURR_ADMIT_PIDM",
C.TERM_CODE_ENTRY "CURR_ADMIT_TERM",
C.APDC_CODE "CURR_ADMIT_APDC",
C.APPL_NO "CURR_ADMIT_APPNO"
FROM SARAPPD C
WHERE C.TERM_CODE_ENTRY IN ('201210','201280')
AND C.APDC_CODE='WA'
AND C.SEQ_NO=(select MAX(d.seq_no)
FROM sarappd d
WHERE d.pidm = C.pidm
AND d.term_code_entry = C._term_code_entry)
select sarappd.pidm,
sarappd.term_code_entry,
sarappd.apdc_code,
curr_admit.CURR_ADMIT_SEQ_NO,
sarappd.appl_no,
sarappd.seq_no
from sarappd,curr_admit
WHERE sarappd.pidm=curr_admit.PIDM
and sarappd.term_code_entry=curr_admit.TERM_CODE_ENTRY
AND sarappd.appl_no=curr_admit.APPL_NOIt pulls the people who have WA decision codes, but does not include any other records if there are other decision codes. I have gone into the user front end of the database and verified the information. What is in the output is correct, but it doesn't have other decision codes for that person for the same term and application number.
Thanks in advance for any assistance that you might be able to provide. I am doing the best I can to describe what I need.
Michelle Craig
Data Coordinator
Admissions Operations and Transfer Systems
Kent State UniversityHi, Michelle,
903509 wrote:
I do not have the rights in Oracle to create tables, so please pardon if this code to make the table is incorrect or doesn't show up here as code. This is not the entire SARAPPD table framework, just the pertinent columns, along with some data to put in them. You really ought to get the necessary privileges, in a schema that doesn't have the power to do much harm, in a development database. If you're expected to develop code, you need to be able to fabricate test data.
Until you get those privileges, you can post sample data in the form of a WITH clause, like this:
WITH sarappd AS
SELECT 12345 AS pidm, '201280' AS term_code_entry, 'WA' AS apdc_code , 1 AS appl_no, 4 AS seq_no FROM dual UNION ALL
SELECT 12345, '201280', 'RE', 1, 3 FROM dual UNION ALL
SELECT 12345, '201280', 'AC', 1, 2 FROM dual UNION ALL
... I have attempted to get the data with a query similar to the following:
WITH CURR_ADMIT AS
SELECT C.SEQ_NO "CURR_ADMIT_SEQ_NO",
C.PIDM "CURR_ADMIT_PIDM",
C.TERM_CODE_ENTRY "CURR_ADMIT_TERM",
C.APDC_CODE "CURR_ADMIT_APDC",
C.APPL_NO "CURR_ADMIT_APPNO"
FROM SARAPPD C
WHERE C.TERM_CODE_ENTRY IN ('201210','201280')
AND C.APDC_CODE='WA'
AND C.SEQ_NO=(select MAX(d.seq_no)
FROM sarappd d
WHERE d.pidm = C.pidm
AND d.term_code_entry = C._term_code_entry)
Are you sure this is what you're actually running? There are errors. such as referencing a column called termcode_entry (starting with an underscore) at the end of the fragment above. Make sure what you post is accurate.
Here's one way to do what you requested
WITH got_last_values AS
SELECT sarappd.* -- or list all the columns you want
, FIRST_VALUE (seq_no) OVER ( PARTITION BY pidm
ORDER BY seq_no DESC
) AS last_seq_no
, FIRST_VALUE (apdc_code) OVER ( PARTITION BY pidm
ORDER BY seq_no DESC
) AS last_apdc_code
FROM sarappd
WHERE term_code_entry IN ( '201210'
, '201280'
SELECT pidm
, term_code_entry
, apdc_code
, last_seq_no
, appl_no
, seq_no
FROM got_last_values
WHERE last_apdc_code = 'WA'
;Don't forget to post the results you want from the sample data given.
This is the output I get from the sample data you posted:
` PIDM TERM_C AP LAST_SEQ_NO APPL_NO SEQ_NO
23456 201280 WA 3 1 3
23456 201280 RE 3 1 2
23456 201280 SC 3 1 1
45678 201280 WA 3 1 3
45678 201280 AC 3 1 2
45678 201210 AC 3 2 1
56789 201210 WA 3 1 3
56789 201210 SC 3 1 2I assume that the combination (pidm, seq_no) is unique.
There's an analytic LAST_VALUE function as well as FIRST_VALUE. It's simpler (if less intuitive) to use FIRST_VALUE in this problem because of the default windowing in analytic functions that have an ORDER BY clause. -
I have a problem, The scenario is that when I click any folder that si in my JTable's first row, the table is update by removing all the rows and showing only the contents of my selected folder. Right now it's not removing the rows and instead throwing exceptions. The code is attached. The methods to look are upDateTabel(...) and clearTableData(....), after clearing all my rows then I proceed on adding my data to the Jtable and inserting rows but it's not being done. May be I have a problem in my DefaultTableModel class. Please see the code below what I am doing wrong and how should I do it. Any help is appreciated.
Thanks
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.*;
import javax.swing.border.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
public class SimpleTable extends JPanel{
/** Formats the date */
protected SimpleDateFormat formatter;
/** variable to hold the date and time in a raw form for the directory*/
protected long dateDirectory;
/** holds the readable form converted date for the directories*/
protected String dirDate;
/** holds the readable form converted date for the files*/
protected String fileDate;
/** variable to hold the date and time in a raw form for the file*/
protected long dateFile;
/** holds the length of the file in bytes */
protected long totalLen;
/** convert the length to the wrapper class */
protected Long longe;
/** Vector to hold the sub directories */
protected Vector subDir;
/** holds the name of the selected directory */
protected String dirNameHold;
/** converting vector to an Array and store the values in this */
protected File directoryArray[];
/** hashtable to store the key-value pair */
protected static Hashtable hashTable = new Hashtable();
/** refer to the TableModel that is the default*/
protected MyTableModel tableModel;
/** stores the path of the selected file */
protected static String fullPath;
/** stores the currently selected file */
protected static File selectedFilename;
/** stores the extension of the selected file */
protected static String extension;
protected int COLUMN_COUNT = 4;
protected Vector data = new Vector( 0, 1 );
protected final JTable table;
/** holds the names of the columns */
protected final String columnNames[] = {"Name", "Size", "Type", "Modified"};
public SimpleTable(File directoryArray[])
this.setLayout(new BorderLayout());
this.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
(SimpleTable.hashTable).clear();
formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm aaa");
for(int k = 0; k < directoryArray.length; k++)
if(directoryArray[k].isDirectory())
dateDirectory = directoryArray[k].lastModified();
dirDate = formatter.format(new java.util.Date(dateDirectory));
data.addElement( new MyObj( directoryArray[k].getName(), "", "File Folder", "" + dirDate ) );
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
else if(directoryArray[k].isFile())
dateDirectory = directoryArray[k].lastModified();
fileDate = formatter.format(new java.util.Date(dateDirectory));
totalLen = directoryArray[k].length();
longe = new Long(totalLen);
data.addElement( new MyObj( directoryArray[k].getName(), longe + " Bytes", "", "" + fileDate ) );
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
tableModel = new MyTableModel();
table = new JTable( tableModel );
table.getTableHeader().setReorderingAllowed(false);
table.setRowSelectionAllowed(false);
table.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
table.setShowHorizontalLines(false);
table.setShowVerticalLines(false);
table.addMouseListener(new MouseAdapter()
public void mouseReleased(MouseEvent e)
Object eventTarget = e.getSource();
if( eventTarget == table )
upDateTable(table);
table.tableChanged( new javax.swing.event.TableModelEvent(tableModel) ) ;
DefaultTableCellRenderer D_headerRenderer = (DefaultTableCellRenderer ) table.getTableHeader().getDefaultRenderer();
table.getColumnModel().getColumn(0).setHeaderRenderer(D_headerRenderer );
((DefaultTableCellRenderer)D_headerRenderer).setToolTipText("File and Folder in the Current Folder");
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this window.
this.add(scrollPane, BorderLayout.CENTER);
* Searches the Hashtable and returns the path of the folder or the value.
public File findPath(String value)
return (File)((SimpleTable.hashTable).get(value));
* This clears the previous data in the JTable
public void clearTableData(JTable table)
for(int row = 0; row < table.getRowCount() ; row++)
//for (int col = 0; col < table.getColumnCount() ; col++)
tableModel.deleteSelections( row );
tableModel.fireTableStructureChanged();
tableModel.fireTableRowsDeleted(0,table.getRowCount());
//table.getModel().fireTableChanged(new TableModelEvent(table.getModel()));
private void upDateTable(JTable table)
if((table.getSelectedColumn() == 0) && ((table.getColumnName(0)).equals(columnNames[0])))
dirNameHold =(String) table.getValueAt(table.getSelectedRow(),table.getSelectedColumn());
File argument = findPath(dirNameHold);
if(argument.isFile())
CMRDialog.fileNameTextField.setText(argument.getName());
try
fullPath = argument.getCanonicalPath();
selectedFilename = argument.getCanonicalFile();
CMRDialog.filtersComboBox.removeAllItems();
extension = fullPath.substring(fullPath.lastIndexOf('.'));
CMRDialog.filtersComboBox.addItem("( " + extension + " )" + " File");
catch(IOException e)
System.out.println("THE ERROR IS " + e);
return;
else if(argument.isDirectory())
String path = argument.getName();
//find the system dependent file separator
//String fileSeparator = System.getProperty("file.separator");
CMRDialog.driveComboBox.addItem(" " + path);
subDir = Search.subDirs(argument);
/**TBD:- needs a method to convert the vector to an array and return the array */
directoryArray = new File[subDir.size()];
int indexCount = 0;
/** TBD:- This is inefficient way of converting a vector to an array */
Iterator e = subDir.iterator();
while( e.hasNext() )
directoryArray[indexCount] = (File)e.next();
indexCount++;
/** now calls this method and clears the previous data */
clearTableData(table);
(SimpleTable.hashTable).clear();
//data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm aaa");
for(int k = 0; k < directoryArray.length; k++)
if(directoryArray[k].isDirectory())
dateDirectory = directoryArray[k].lastModified();
dirDate = formatter.format(new java.util.Date(dateDirectory));
data.addElement( new MyObj( directoryArray[k].getName(), "", "File Folder", "" + dirDate ) );
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
else if(directoryArray[k].isFile())
dateDirectory = directoryArray[k].lastModified();
fileDate = formatter.format(new java.util.Date(dateDirectory));
totalLen = directoryArray[k].length();
longe = new Long(totalLen);
data.addElement( new MyObj( directoryArray[k].getName(), longe + " Bytes", "", "" + fileDate ) );
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
// tableModel.fireTableDataChanged();
// tableModel.fireTableRowsInserted(0,1);
table.revalidate();
table.validate();
class MyTableModel extends DefaultTableModel
int totalRows;
int totalCols;
public MyTableModel()
super();
setColumnIdentifiers (columnNames);
this.totalRows = data.size();
this.totalCols = columnNames.length;
// this will return the row count of your table
public int getRowCount()
return totalRows;
// this return the column count of your table
public int getColumnCount()
return totalCols;
// this return the data for each cell in your table
public Object getValueAt(int row, int col)
MyObj obj = (MyObj)data.elementAt( row );
if( obj != null )
if( col == 0 ) return( obj.first );
else if( col == 1 ) return( obj.last );
else if( col == 2 ) return( obj.third );
else if( col == 3 ) return( obj.fourth );
else return( "" );
return "";
// if you want your table to be editable then return true
public boolean isCellEditable(int row, int col)
return false;
// if your table is editable edit the data vector here and
// call table.tableChanged(...)
public void setValueAt(Object value, int row, int col)
protected void deleteSelections (int rows)
try
removeRow(rows);
catch(ArrayIndexOutOfBoundsException e)
System.out.println("The error in the row index " + rows);
fireTableDataChanged() ;
class MyObj
String first;
String last;
String third;
String fourth;
public MyObj( String f, String l, String t, String fo )
this.first = f;
this.last = l;
this.third = t;
this.fourth = fo;
#####################################The following code works fine but it doesn't show me the new updated date in my JTable. I tried to print the values that I am getting and it does give the values on the prompt but doesn't show me on the JTable only first two are shown and the rest of the table is filled with the same values. I don't know what's going on and am tired of this TableModel thing so pla. take a time to give me some suggestions. Thanks
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.*;
import javax.swing.border.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
public class SimpleTable extends JPanel {
/** Formats the date */
protected SimpleDateFormat formatter;
/** two-dimensional array to hold the information for each column */
protected Object data[][];
/** variable to hold the date and time in a raw form for the directory*/
protected long dateDirectory;
/** holds the readable form converted date for the directories*/
protected String dirDate;
/** holds the readable form converted date for the files*/
protected String fileDate;
/** variable to hold the date and time in a raw form for the file*/
protected long dateFile;
/** holds the length of the file in bytes */
protected long totalLen;
/** convert the length to the wrapper class */
protected Long longe;
/** Vector to hold the sub directories */
protected Vector subDir;
/** holds the name of the selected directory */
protected String dirNameHold;
/** converting vector to an Array and store the values in this */
protected File directoryArray[];
/** hashtable to store the key-value pair */
protected static Hashtable hashTable = new Hashtable();
/** refer to the TableModel that is the default*/
protected DefaultTableModel model;
/** stores the path of the selected file */
protected static String fullPath;
/** stores the currently selected file */
protected static File selectedFilename;
/** stores the extension of the selected file */
protected static String extension;
protected Vector m = new Vector(0,1);
/** holds the names of the columns */
protected final String columnNames[] = {"Name", "Size", "Type", "Modified"};
public SimpleTable(File directoryArray[])
this.setLayout(new BorderLayout());
this.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
(SimpleTable.hashTable).clear();
data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm aaa");
for(int k = 0; k < directoryArray.length; k++)
if(directoryArray[k].isDirectory())
data[k][0] = directoryArray[k].getName();
data[k][2] = "File Folder";
dateDirectory = directoryArray[k].lastModified();
dirDate = formatter.format(new java.util.Date(dateDirectory));
data[k][3] = dirDate;
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
else if(directoryArray[k].isFile())
data[k][0] = directoryArray[k].getName();
totalLen = directoryArray[k].length();
longe = new Long(totalLen);
data[k][1] = longe + " Bytes";
dateFile = directoryArray[k].lastModified();
fileDate = formatter.format(new java.util.Date(dateFile));
data[k][3] = fileDate;
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
model = new DefaultTableModel();
model.addTableModelListener( new TableModelListener(){
public void tableChanged( javax.swing.event.TableModelEvent e )
System.out.println("************ I am inside the table changed method ********" );
final JTable table = new JTable(model);
table.getTableHeader().setReorderingAllowed(false);
table.setRowSelectionAllowed(false);
table.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
table.setShowHorizontalLines(false);
table.setShowVerticalLines(false);
table.addMouseListener(new MouseAdapter()
/* public void mousePressed(MouseEvent e)
//System.out.println("The clicked component is " + table.rowAtPoint(e.getPoint()) + "AND the number of clicks is " + e.getClickCount());
/* if(e.getClickCount() >= 2 &&
(table.getSelectedColumn() == 0) &&
((table.getColumnName(0)).equals(columnNames[0])))
//System.out.println("The clicked component is " + table.rowAtPoint(e.getPoint()) + "AND the number of clicks is " + e.getClickCount());
upDateTable(table);
public void mouseReleased(MouseEvent e)
//System.out.println("The clicked component is " + table.rowAtPoint(e.getPoint()) + "AND the number of clicks is " + e.getClickCount());
/* if(e.getClickCount() >= 2 &&
(table.getSelectedColumn() == 0) &&
((table.getColumnName(0)).equals(columnNames[0]))) */
//System.out.println("The clicked component is " + table.rowAtPoint(e.getPoint()) + "AND the number of clicks is " + e.getClickCount());
upDateTable(table);
/** set the columns */
for(int c = 0; c < columnNames.length; c++)
model.addColumn(columnNames[c]);
/** set the rows */
for(int r = 0; r < data.length; r++)
model.addRow(data[r]);
DefaultTableCellRenderer D_headerRenderer = (DefaultTableCellRenderer ) table.getTableHeader().getDefaultRenderer();
table.getColumnModel().getColumn(0).setHeaderRenderer(D_headerRenderer );
((DefaultTableCellRenderer)D_headerRenderer).setToolTipText("File and Folder in the Current Folder");
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this window.
this.add(scrollPane, BorderLayout.CENTER);
* Returns the number of columns
public int getColumnTotal()
return columnNames.length;
* Returns the number of rows
public int getRowTotal(Object directoryArray[])
return directoryArray.length;
private void upDateTable(JTable table)
if((table.getSelectedColumn() == 0) && ((table.getColumnName(0)).equals(columnNames[0])))
dirNameHold =(String) table.getValueAt(table.getSelectedRow(),table.getSelectedColumn());
File argument = findPath(dirNameHold);
if(argument.isFile())
CMRDialog.fileNameTextField.setText(argument.getName());
try
fullPath = argument.getCanonicalPath();
selectedFilename = argument.getCanonicalFile();
CMRDialog.filtersComboBox.removeAllItems();
extension = fullPath.substring(fullPath.lastIndexOf('.'));
CMRDialog.filtersComboBox.addItem("( " + extension + " )" + " File");
catch(IOException e)
System.out.println("THE ERROR IS " + e);
return;
else if(argument.isDirectory())
String path = argument.getName();
//find the system dependent file separator
//String fileSeparator = System.getProperty("file.separator");
CMRDialog.driveComboBox.addItem(" " + path);
subDir = Search.subDirs(argument);
/**TBD:- needs a method to convert the vector to an array and return the array */
directoryArray = new File[subDir.size()];
int indexCount = 0;
/** TBD:- This is inefficient way of converting a vector to an array */
Iterator e = subDir.iterator();
while( e.hasNext() )
directoryArray[indexCount] = (File)e.next();
indexCount++;
/** now calls this method and clears the previous data */
clearTableData(table);
(SimpleTable.hashTable).clear();
data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm aaa");
m.clear();
data = null;
data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
for(int k = 0; k < directoryArray.length; k++)
if(directoryArray[k].isDirectory())
System.out.println("Inside the if part");
data[k][0] = directoryArray[k].getName();
table.setValueAt(directoryArray[k].getName(),k,0);
//model.fireTableCellUpdated(k,0);
data[k][2] = "File Folder";
table.setValueAt("File Folder",k,2);
//model.fireTableCellUpdated(k,2);
dateDirectory = directoryArray[k].lastModified();
dirDate = formatter.format(new java.util.Date(dateDirectory));
data[k][3] = dirDate;
table.setValueAt(dirDate,k,3);
//model.fireTableCellUpdated(k,3);
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
m.add(data);
model.addRow(m);
model.fireTableDataChanged();
else if(directoryArray[k].isFile())
System.out.println("******* Inside the else part *******");
data[k][0] = directoryArray[k].getName();
System.out.println("The Name is == " + data[k][0]);
table.setValueAt(directoryArray[k].getName(),k,0);
System.out.println("The table cell value of the name is == " + table.getValueAt(k,0));
//model.fireTableCellUpdated(k,0);
totalLen = directoryArray[k].length();
longe = new Long(totalLen);
data[k][1] = longe + " Bytes";
System.out.println("The length == " + data[k][1]);
table.setValueAt(longe + " Bytes",k,1);
System.out.println("The table cell value of the length is == " + table.getValueAt(k,1));
//model.fireTableCellUpdated(k,0);
dateFile = directoryArray[k].lastModified();
fileDate = formatter.format(new java.util.Date(dateFile));
data[k][3] = fileDate;
System.out.println("The modified date == " + data[k][3]);
table.setValueAt(fileDate,k,3);
System.out.println("The table cell value of the name is == " + table.getValueAt(k,3));
//model.fireTableCellUpdated(k,0);
(SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]); }
m.add(data);
model.addRow(m);
model.fireTableDataChanged();
// model.fireTableDataChanged();
// model.fireTableRowsInserted(0,1);
table.revalidate();
table.validate();
else
* Searches the Hashtable and returns the path of the folder or the value.
public File findPath(String value)
return (File)((SimpleTable.hashTable).get(value));
* This clears the previous data in the JTable
public void clearTableData(JTable table)
for(int row = 0; row < table.getRowCount() ; row++)
for (int col = 0; col < table.getColumnCount() ; col++)
table.setValueAt(null, row , col);
model.fireTableStructureChanged();
### -
Query for a value result when no rows found
Kindly help me out when I use following query it return no record but I want 0 against this query how plz let me know
select b.accode,decode(sum(b.debit),null,0,sum(b.debit)) op_dr,
decode(sum(b.credit),null,0,sum(b.credit)) op_cr,
c.actitle
from v_mast a, v_det b, chart c
where a.v_type=b.v_type
and a.vouchno=b.vouchno
and b.accode=c.accode
and a.VOID='F'
and a.posted_by is not null
and a.v_date between '01-JAN-06' and '31-JAN-06'
and b.accode in (select accode from account where open='T')
and b.accode in (select accode from chart)
and a.v_type in ('RN','PV','CV','RV','JV')
and b.accode = '3050571'
group by b.accode,c.actitle
order by b.accode
Result is : No rows found but is there any possibilities that it will give me following result
Accode op_dr op_cr
3050571 0 0Why not respond to the earlier threads ?
Query
and
0 when no records found
Regards,
Rob.
Message was edited by:
Rob van Wijk
PS: Of course you could do a
<your query> union all select 3050571,0,0,null from dual
It answers the question, but I doubt that this is what you want. -
Update a column keeping old values and adding new one
I have to update a column...
Select * from test;
RULE_NBR TYPE_TEXT
30 AAX,AAR,AAV,AAB,AAK
40 BBD,WWN,AAF,AAB,AAK
now I have to add BBB,WWW where rule_nbr = 30 and CCC,TTT where rule_nbr = 40
so this update stmt will do...
UPDATE TEST
SET type_text = 'AAX,AAR,AAV,AAB,AAK,BBB,WWW'
WHERE rule_nbr = '30';
update test
set TYPE_TEXT = 'BBD,WWN,AAF,AAB,AAK,CCC,TTT'
where rule_nbr = '40';
Just wondering is there any other way to update the sameuser1692585 wrote:
I have to update a column...
Select * from test;
RULE_NBR TYPE_TEXT
30 AAX,AAR,AAV,AAB,AAK
40 BBD,WWN,AAF,AAB,AAK
now I have to add BBB,WWW where rule_nbr = 30 and CCC,TTT where rule_nbr = 40
so this update stmt will do...
UPDATE TEST
SET type_text = 'AAX,AAR,AAV,AAB,AAK,BBB,WWW'
WHERE rule_nbr = '30';
update test
set TYPE_TEXT = 'BBD,WWN,AAF,AAB,AAK,CCC,TTT'
where rule_nbr = '40';
Just wondering is there any other way to update the sameYou can do something liek below..But few questions - Why are you storing data like this..It is against normalization concept..You should store the RULE_TEXT values in multiple rows.That is how you should design your data model in an RDBMS
update test
set type_text = type_text||decode(rule_nbr,30,',BBB,WWW',40,',CCC,TTT')
where rule_nbr in (30,40);Edited by: jeneesh on Apr 25, 2013 2:28 PM -
Open excel sheet through program calculate value and fetch value in program
Hi experts,
My requirement is to open a excel sheet while i execute a report,There is some calculation that i need to do in excel sheet and want to fetch the calculated value back in to my program.
Is there any way of doing so ?
Regards,
KashyapHi Aditya ,
let me once more clarify with ur requirements .
User is uploading an excel sheet.
U doing validations on the records and getting the error in records.
Displaying the uploaded excel sheet to user to rectify the errors.
and then update the databse with the correct records.
So for the above
use WS_upload ,GUI_Upload FM for uploading the excel sheet in itab.
using this itab ,Dynamically add one more column for the errors.
Refer :Re: Could anyone tell me how can I add columns in a internal table dynamically?
Display records in an editable ALV grid.
BCALV_EDIT_01
BCALV_EDIT_02
BCALV_EDIT_03
BCALV_EDIT_04
BCALV_FULLSCREEN_GRID_EDIT
BCALV_GRID_EDIT
BCALV_TEST_GRID_EDIT_01
BCALV_TEST_GRID_EDITABLE
Also see this
http://www.sapdevelopment.co.uk/reporting/alv/alvscr.htm
then update the database
Regards
Renu
Edited by: Renu Gusain on May 8, 2009 8:40 AM -
How to changing char. values and create new lines in C_TH_DATA
Hi experts,
we need to distribute the cost of some sender costcenters to the corresponding receiver costcenters.
We have already created a DSO and maintained this with the sender and receiver costcenter. We use this lookup table later in the execute method of our created planning function type to take the sender costcenter and distribute this to the corresponding receiver costcenters.
I've already implemented an IP planning function based on planning function type for this process.
At the end when I debug the method I see that this works fine. I give you an example:
I have in my lookup table the following record:
sender costcenter receiver costcenter distribution percent
4711 4712 75
4711 4713 25
Based on those records in the lookup table I've to distribute the cost of sender costcenter to the receiver costcenters.
Just imagine I would get this record from c_th_data:
sender costcenter costelement value
4711 3000111 100
I have to have the following result after running the exit planning function:
costcenter costelement value
4711 3000111 100 -> without changing
4711 8000111 -100
4712 8000111 75
4713 8000111 25
When I debug the exit function I see in the execute method that c_th_data will be filled correctly. I see exactly the records that I want to see.
But once the function is finished I don't see this result. I also checked the conversation
Changing Char Value in IP C_TH_DATA
but I can't understand what happens after my coding yet.
Can anyone help me or give me an advice what could be the problem here?
Thank you all in advance for your support.
Kind regards,
AliHi Ali,
The planning function generates the records in delta mode. I am explaining the concept taking your example only:
Records in cube before running PF:
sender costcenter receiver costcenter distribution percent
4711 4712 75
4711 4713 25
sender costcenter costelement value
4711 3000111 100
4712 3000111 100
4713 3000111 100
The records that you need to generate from code(Previous ones need to be changed):
sender costcenter costelement value
4711 3000111 000
4712 3000111 175
4713 3000111 125
**Please note that you dont need to generate any corrections(delta records), you only need to generate the final values in the records and the PF will generate the delta's on its own. Also in this case you should see 3 Records Read, 0 Deleted, 3 Changed.
Please let me know if you need any more clarification,
Thanks,
Puneet -
How to copy existing row value into new row with a trigger. Same table
Oracle guru,
I am looking for a before or after trigger statement that will copy existing values inserted in the previous row into columns A & B. Then insert those values in a new row into column A & B if null? Same table. Hopefully my question is clear enough.
-Oracle 10g express
-I have an existing " before insert trigger" that insert id and timestamps when a new row is created.
-Table is composed of column like id,timestamps,A,B and more.
Thanks in advance
Pierre957911 wrote:
Oracle guru,
I am looking for a before or after trigger statement that will copy existing values inserted in the previous row into columns A & B. Then insert those values in a new row into column A & B if null? Same table. Hopefully my question is clear enough.
-Oracle 10g express
-I have an existing " before insert trigger" that insert id and timestamps when a new row is created.
-Table is composed of column like id,timestamps,A,B and more.
Thanks in advance
PierreI will call it a very Wrong design.
It is a wrong Table Design. You are duplicating the data in table and not complying with the Database Normalization rules.
How about Verifying if Column A & B are NULL before inserting and inserting another row and avoiding it in Triggers?
If you are bent to achieve this, below code might be helpful. However, I would never go with this approach. If you would care about explaining the reason for going ahead with such a data model, people could suggest better alternative that might conform with Normalization rules.
create or replace trigger trg_test_table
after insert on test_table
for each row
declare
pragma autonomous_transaction;
begin
if :new.col_a is null and :new.col_b is null then
insert into test_table
select 2, systimestamp, col_a, col_b
from test_table
where pk_col = (select max(pk_col) from test_table b where b.pk_col < :new.pk_col);
end if;
commit;
end trg_test_table;Read SQL and PL/SQL FAQ and post the mentioned details.
Do not forget to mention output from
select * from v$version;
Maybe you are looking for
-
The Difference between Extending a Wireless network and WDS?
I have an Extreme (n) and an Express (n). I want to make sure the signal is strong upstairs and share a printer (connected to the express) and use AirTunes. I also may add an external drive to the Extreme. What's the difference between Extending a Wi
-
Hi! I'm having trouble inserting an e-mail form in my web page.I copied the code from another page on my site,and tried to insert it in an apDiv so that I could move it around,but that didn't work.When I paste it anywhere between divs on the page,it
-
Problem in downloading the records
Hi All, I am facing one weired problem. I have 2594 records in my Z table but when i am taking the dump of the table, it is giving only 2375 records. Can anyone tell me why this is happening? Thanks Puneet
-
Time pair on Planned working hours 0
I want to generate time pair for days where planned working hours is 0. how can i do that do i have to write a rule to generate time pairs on day with hours 8 (fixed if it is a off day) because if anybody takes PL on off day and CL on off day then i
-
Our Procurement team has been working to renew our SAP BPC contract for going on a year. Our current contacts have been non-responsive, and we now have an incorrect invoice we need to have corrected based on an updated contract before we can submit