DUPLICATE A COLUMN IN A SAME TABLE ?
Do u know a way to duplicate a column in a same table without using the "INSERT INTO" function ?
Here is Answer Why we want to do this.
Today I face the problem.I want to change the name of the column with out loss of data.In oracle we don't have this facility. but through logic you can do it.
Suppose a table name Temp with Column names
Rollno ,Name,Amount
I want to change the column name Amount to NewAmount.
Follow the following steps.
1. Add new column with alter command
2. Update new Column with the above statement.
3. drop the old column.
null
Similar Messages
-
How to sum different column in the same table
Hi everyone
I would like to know how can I make the sum of different column in the same table using apex
exple:
TR_PROJ_BIL_TRIM.ENTPIDFISC as ENTPIDFISC,
TR_PROJ_BIL_TRIM.EXEANNEE as EXEANNEE,
TR_PROJ_BIL_TRIM.PROJBILTRIMT1PREV as PROJBILTRIMT1PREV,
TR_PROJ_BIL_TRIM.PROJBILTRIMT2PREV as PROJBILTRIMT2PREV,
trunc( TR_PROJ_BIL_TRIM.PROJBILTRIMT1PREV)+(TR_PROJ_BIL_TRIM.PROJBILTRIMT2PREV)
from TR_PROJ_BIL_TRIM TR_PROJ_BIL_TRIM
group by TR_PROJ_BIL_TRIM.ENTPIDFISC,TR_PROJ_BIL_TRIM.EXEANNEE
but while trying to run this script i get this error message:"ORA-00979: not a GROUP BY expression"
thanks for reading me and I hope to hear from you soonHi,
Your question do not have anything do with APEX.
It is pure SQL question and you will get better answer this kind questions from SQL and PL/SQL forum
You need have GROUP BY when you use aggregate functions like SUM.
I assume you like just add two columns.
Try
SELECT ENTPIDFISC
,EXEANNEE
,PROJBILTRIMT1PREV
,PROJBILTRIMT2PREV
,trunc(PROJBILTRIMT1PREV) + (PROJBILTRIMT2PREV)
FROM TR_PROJ_BIL_TRIM
Regards,
Jari -
Nsert/Update and Add Column at the same Table and at the "same" Time
Hello,
I want Insert/Update and Add Column at the same Table and at the "same" Time but in different sessions.
Example:
At first the "insert/update" statement:
Insert into TestTable (Testid,Value) values (1,5105);
After that the "add" statement:
Alter table TestTable add TestColumn number;
- sadly now I get the message: ORA-00054: resource busy and acquire with NOWAIT specified
"insert/update" statement:
Insert into TestTable (Testid,Value) values (2,1135);
After that the execute commit.
I don't know when the first session set the commit statement so I want that the DB the "Alter Table..." statement execute if it's possible.
If it's possible I want to save a repeat loop with the "Alter Table..." statemtent.
Thanks for ideasWell I want to walk in the rain without and umbrella and still stay dry, but it ain't gonna happen.
You can't run a DDL statement against a table with transactions pending. Session 2 has to wait until session commits or rollbacks (or until the session is killed). That's just the way it is.
This makes sense if you think about it. The data dictionary has to be consistent across all sessions. If session 2 was allowed to change the table structure whilst session 1 has a pending transaction then the database is in an inconsistent state. This is easier to see if you consider the reverse situation - the ALTER TABLE statement run by session 2 does a DROP COLUMN TESTID rather than adding a column: now what should happen to session 1's INSERT statement? You have retrospectively invalidated a statement that was perfectly legal when it was executed.
If it's possible I want to save a repeat loop with the "Alter Table..." statemtent.Fnord.
Cheers, APC -
Data of column datatype CLOB is moved to other columns of the same table
Hi all,
I have an issue with the tables having a CLOB datatype field.
When executing a simple query on a table with a column of type CLOB it returns error [POL-2403] value too large for column.
SQL> desc od_stock_nbcst_notes;
Name Null? Type
OD_STOCKID N NUMBER
NBC_SERVICETYPE N VARCHAR(40)
LANGUAGECODE N VARCHAR(8)
AU_USERIDINS Y NUMBER
INSERTDATE Y DATE
AU_USERIDUPD Y NUMBER
MODIFYDATE Y DATE
VERSION Y SMALLINT(4)
DBUSERINS Y VARCHAR(120)
DBUSERUPD Y VARCHAR(120)
TEXT Y CLOB(2000000000)
NBC_PROVIDERCODE N VARCHAR(40)
SQL> select * from od_stock_nbcst_notes;
[POL-2403] value too large for column
Checking deeply, some of the rows have got the data of the CLOB column moved in another column of the table.
When doing select length(nbc_providercode) the length is bigger than the datatype of the field (varchar(40)).
When doing substr(nbc_providercode,1,40) to see the content of the field, a portion of the Clob data is retrieved.
SQL> select max(length(nbc_providercode)) from od_stock_nbcst_notes;
MAX(LENGTH(NBC_PROVIDERCODE))
162
Choosing one random record, this is the stored information.
SQL> select length(nbc_providerCode), text from od_stock_nbcst_notes where length(nbc_providerCode)=52;
LENGTH(NBC_PROVIDERCODE) | TEXT
-------------------------+-----------
52 | poucos me
SQL> select nbc_providerCode from od_stock_nbcst_notes where length(nbc_providerCode)=52;
[POL-2403] value too large for column
SQL> select substr(nbc_providercode,1,40) from od_stock_nbcst_notes where length(nbc_providercode)=52 ;
SUBSTR(NBC_PROVIDERCODE
Aproveite e deixe o seu carro no parque
The content of the field is part of the content of the field text (datatype CLOB, containts an XML)!!!
The right content of the field must be 'MTS' (retrieved from Central DB).
The CLOB is being inserted into the Central DB, not into the Client ODB. Data is synchronized from CDB to ODB and the data is reaching the client in a wrong way.
The issue can be recreated all the time in the same DB, but between different users the "corrupted" records are different.
Any idea?939569 wrote:
Hello,
I am using Oracle 11.2, I would like to use SQL to update one column based on values of other rows at the same table. Here are the details:
create table TB_test (myId number(4), crtTs date, updTs date);
insert into tb_test(1, to_date('20110101', 'yyyymmdd'), null);
insert into tb_test(1, to_date('20110201', 'yyyymmdd'), null);
insert into tb_test(1, to_date('20110301', 'yyyymmdd'), null);
insert into tb_test(2, to_date('20110901', 'yyyymmdd'), null);
insert into tb_test(2, to_date('20110902', 'yyyymmdd'), null);
After running the SQL, I would like have the following result:
1, 20110101, 20110201
1, 20110201, 20110301
1, 20110301, null
2, 20110901, 20110902
2, 20110902, null
Thanks for your suggestion.How do I ask a question on the forums?
SQL and PL/SQL FAQ -
Two columns in the same table that are foreign keys to the same master key
i want to create a table let say X, which have two columns that are foreign key that reference the same column in the master table, so does this count as bad database design.
here is the full ddl for the two table, where in the second table there are two columns that represent the primary key and they are also two foreign keys to the same columns in the master table (items)
Desc item table;
Item_id
Item_name
Item_price
Item_quantitiy
Create table item_recommendation ( item_id varchar(20), recommended_item varchar(20),
CONSTRAINT recom_primary PRIMARY KEY (item_id, recommended_item),
CONSTRAINT F1 FOREIGN KEY (item_id) REFERENCES items(item_id), ),
CONSTRAINT F2 FOREIGN KEY (recommended_item) REFERENCES items(item_id)); -
Count Distinct based on another column in the same table
Hello,
My question in short: is is it possible to add a new column to a view which holds the DISTINCT COUNTS of values/domains of another column in the same view?
For example, in the below table the column "Distinct Count of Occurence" shows how many distinct values a person has in the Occurence column. So AAA has 1 and 2 therefore it is 2 distinct values etc.
My issues is that I can retrieve unique values bu Count (Select Occurence)but I can not add the new column that would add the records to the corresponding Persons in the above table.
Is there an easy way to achieve this on the DWH level or should it be done with MDX in the cube?
ThanksHi,
Below a solution to use the view by adding a column with window functioning, maybe this will help.
CREATE TABLE #TMP
PERSON VARCHAR(10),
OCCURENCE SMALLINT
--DROP TABLE #TMP
INSERT INTO #TMP(PERSON,OCCURENCE)
VALUES
('AAA','1'),
('AAA','2'),
('BBB','1'),
('BBB','1'),
('BBB','1'),
('CCC','1'),
('CCC','2'),
('CCC','3');
--TRUNCATE TABLE #TMP
WITH CTE
AS
SELECT PERSON
,OCCURENCE
,ROW_NUMBER() OVER(PARTITION BY PERSON ORDER BY OCCURENCE) AS RN
FROM #TMP
SELECT PERSON, MAX(RN) AS RN
FROM CTE
GROUP BY PERSON
Regards,
Reshma
Please Vote as Helpful if an answer is helpful and/or Please mark Proposed as Answer or Mark As Answer when question is answered -
Hello Good Evening,
Could you please help me here
how to write condition for self table year records, such 2012 name and acctno match with 2013 name and acctno then total, provided below,
create table #tab1 (MasterKey int, AcctNo varchar(12),name varchar(25), SumaofShares numeric, request_dat datetime )
--drop table #tab1
insert into #tab1 values (1000, 100,'Tom', 2500, '10/01/2012')
insert into #tab1 values (1001, 101,'Bat', 1550, '08/11/2012')
insert into #tab1 values (1002, 102,'Kit', 1600, '06/12/2012')
insert into #tab1 values (1003, 103,'Vat', 1750, '04/15/2012')
insert into #tab1 values (1010, 104,'Sim',200, '04/21/2013')
insert into #tab1 values (1011, 105,'Tim',500, '06/18/2013')
insert into #tab1 values (1012, 100,'Tom',800, '08/22/2013')
insert into #tab1 values (1013, 101,'Bat',550, '09/15/2013')
insert into #tab1 values (1014, 100,'Pet',200, '02/21/2013')
insert into #tab1 values (1015, 103,'Vat',150, '03/18/2013')
insert into #tab1 values (1016, 110,'Sun',800, '03/22/2013')
insert into #tab1 values (1017, 111,'Bet',550, '12/15/2013')
insert into #tab1 values (9999, 111,'AAA',110, '12/15/2014')
create table #tab2 (IssueKey int, totalOutstanding numeric, sharedBenefits varchar(1) )
--drop table #tab2
insert into #tab1 values (1000, 500, 'V')
insert into #tab1 values (1001, 150, 'U')
insert into #tab1 values (1002, 100, 'N')
insert into #tab1 values (1003, 170, 'U')
insert into #tab1 values (1010, 100, 'U')
insert into #tab1 values (1011, 200, 'K')
insert into #tab1 values (1012, 340, 'U')
insert into #tab1 values (1013, 560, 'N')
insert into #tab1 values (1014, 280, 'V')
insert into #tab1 values (1015, 150, 'V')
insert into #tab1 values (1016, 840, 'V')
insert into #tab1 values (1017, 530, 'N')
i would like to get 4 columns output
how to get sumofshares (#tab1) and TotalOutStanding(#tab2) summ up with these values please.,
MasterKey (#tab1) and IssueKey (#tab2) are like primary key and foreign key
so the request is
need to calculate, sumofshares (#tab1) and TotalOutStanding(#tab2) as below
1)ShareBenefist = U and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
then '2012 and 2013 accts UN Veriverted'
2)ShareBenefist = V and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
then '2012 and 2013 accts Veriverted'
3)ShareBenefist = N and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
then '2012 and 2013 accts NONVERT'
4)year( request_dat) =2102 and Name and Acctno not match with 2013 account name and acctno (#tab1)
then '2012 last year accounts'
5)year( request_dat) = 2013 and Name and Acctno not match with 2013 account name and acctno (#tab1)
then '2012 This year accounts'
for ex 1) the below accounts in #tab1 has both 2012 and 2013 and acctno same in both years and name is same in both years so it is condired as
insert into #tab1 values (1012, 100,'Tom',800, '08/22/2013')
for ex 2)
insert into #tab1 values (1013, 101,'Bat',550, '09/15/2013')
for ex 4) 2012 records there is not match acctno and name in 2013 recods
insert into #tab1 values (1002, 102,'Kit', 1600, '06/12/2012')
for ex 5) 2013 records there is no match of name and acct no with 2012 records
insert into #tab1 values (1010, 104,'Sim',200, '04/21/2013')
insert into #tab1 values (1014, 100,'Pet',200, '02/21/2013')
insert into #tab1 values (1016, 110,'Sun',800, '03/22/2013')
insert into #tab1 values (1017, 111,'Bet',550, '12/15/2013')
Expected Results (just for format)
AcctTypeDescription, SumofShares, OtotalutStand
'2012 and 2013 accts UN Veriverted',2700,234
'2012 and 2013 accts Veriverted' ,2890,234
'2012 and 2013 accts NONVERT' ,4533,325
'2012 last year accounts' ,2334,567
'2012 This year accounts' ,2222,877
Please
Thank youy in advance
asitaAs I understand it, your sample output was only to show the format, and did not pretend to be give the exact result given the sample data. This is pity, because means that I was not able to verify that my query below gives the desired result.
The exact relation between #tab1 and #tab2 is not clear to me. I'm making the assumption that a row in #tab1 may have zero or one row in #tab2, but not many.
My solution has two CTEs. The first simply joins the tables together and extracts the year. In the second CTE, I perform a self-join over the first CTE which I have divided in two by year. This is a full join, since an account may appear for only one of
the year. Note that it is instrumental to extract the year data in inner queries first.
The final query is just an aggregation over the categories.
create table #tab1 (MasterKey int, AcctNo varchar(12),name varchar(25), SumaofShares numeric, request_dat datetime )
--drop table #tab1
insert into #tab1 values (1000, 100,'Tom', 2500, '10/01/2012')
insert into #tab1 values (1001, 101,'Bat', 1550, '08/11/2012')
insert into #tab1 values (1002, 102,'Kit', 1600, '06/12/2012')
insert into #tab1 values (1003, 103,'Vat', 1750, '04/15/2012')
insert into #tab1 values (1010, 104,'Sim',200, '04/21/2013')
insert into #tab1 values (1011, 105,'Tim',500, '06/18/2013')
insert into #tab1 values (1012, 100,'Tom',800, '08/22/2013')
insert into #tab1 values (1013, 101,'Bat',550, '09/15/2013')
insert into #tab1 values (1014, 100,'Pet',200, '02/21/2013')
insert into #tab1 values (1015, 103,'Vat',150, '03/18/2013')
insert into #tab1 values (1016, 110,'Sun',800, '03/22/2013')
insert into #tab1 values (1017, 111,'Bet',550, '12/15/2013')
insert into #tab1 values (9999, 111,'AAA',110, '12/15/2014')
create table #tab2 (IssueKey int, totalOutstanding numeric, sharedBenefits varchar(1) )
--drop table #tab2
insert into #tab2 values (1000, 500, 'V')
insert into #tab2 values (1001, 150, 'U')
insert into #tab2 values (1002, 100, 'N')
insert into #tab2 values (1003, 170, 'U')
insert into #tab2 values (1010, 100, 'U')
insert into #tab2 values (1011, 200, 'K')
insert into #tab2 values (1012, 340, 'U')
insert into #tab2 values (1013, 560, 'N')
insert into #tab2 values (1014, 280, 'V')
insert into #tab2 values (1015, 150, 'V')
insert into #tab2 values (1016, 840, 'V')
insert into #tab2 values (1017, 530, 'N')
go
WITH joined AS (
SELECT a.MasterKey, a.AcctNo, a.name, a.SumaofShares,
year(a.request_dat) AS year, b.totalOutstanding, b.sharedBenefits
FROM #tab1 a
LEFT JOIN #tab2 b ON a.MasterKey = b.IssueKey
), categories (category, sumofshares, totaloutstanding) AS (
SELECT CASE WHEN A.MasterKey IS NOT NULL AND
B.MasterKey IS NOT NULL
THEN '2012 and 2013 accts ' +
CASE B.sharedBenefits
WHEN 'U' THEN 'UN Veriverted'
WHEN 'V' THEN 'Veriverted'
WHEN 'N' THEN 'NONVERTED'
ELSE ''
END
WHEN A.MasterKey IS NOT NULL THEN '2012 last year accounts'
WHEN B.MasterKey IS NOT NULL THEN '2013 this year accounts'
END,
coalesce(A.SumaofShares, 0) + coalesce(B.SumaofShares, 0),
coalesce(A.totalOutstanding, 0) + coalesce(B.totalOutstanding, 0)
FROM (SELECT * FROM joined WHERE year = 2012) AS A
FULL JOIN (SELECT * FROM joined WHERE year = 2013) AS B
ON A.AcctNo = B.AcctNo
AND A.name = B.name
SELECT category, SUM(sumofshares) AS sumofshares,
SUM(totaloutstanding) AS totaloutstanding
FROM categories
GROUP BY category
go
drop table #tab1, #tab2
Erland Sommarskog, SQL Server MVP, [email protected] -
How to replace the string of column value with other column value in same table
I have a temp table which contains
Id Name CTC Address Content
1 Ross $200 6th block Dear #Name your CTC is #CTC and your address is #address
2 Jhon $300 1oth cross Dear #Name your CTC is #CTC and your address is #address
Now i want to select content so that it should get replace with the respective columns and final output should come like this
Dear Ross your CTC is 200 and your address is 6th block
Dear Jhon your CTC is 300 and your address is 10th cross
Kindly suggestI think RSingh suggestion is ok ... what do you mean by another way? ...maybe something more generic?
maybe build a table whith the list of col you need to "replace" and dinamically build the replace query ...
declare @colList table(colName varchar(100))
insert into @colList
select 'name'
union all select 'ctc'
union all select 'address'
declare @cmd varchar(2000)
select @cmd='select '+ (select 'replace(' from @colList for xml path('') +' content '+
(select ',''#'+ colName +''', '+ colName +')' from @colList for xml path(''))
+' from YOURTABLENAME '
exec (@cmd)
or your request was different ? -
Calculation date deference between two rows in same column and in same table
mytable
accountno
tdate
1001
01/01/2014
1002
01/01/2014
1003
01/01/2014
1004
01/01/2014
1005
01/01/2014
1001
01/02/2014
1002
01/02/2014
1003
01/02/2014
1004
01/02/2014
1005
01/02/2014
1001
01/03/2014
1002
01/03/2014
1003
01/03/2014
1004
01/03/2014
1005
01/03/2014
1001
01/04/2014
1002
01/04/2014
1003
01/04/2014
1004
01/04/2014
1005
01/04/2014
This is my table. I want find out account wise date deference between first date to second date, second date to third date, third date to fourth date, fourth date to fifth date........... Could you please provide me the solution with any SQL, VB or MS access
query!In SQL 2012/2014:
SELECT accountno, tdate,
datediff(DAY, LAG(tdate) OVER (PARTITION BY accountno ORDER BY tdate), tdate)
FROM tbl
ORDER BY account, tdate
In SQL 2005/2008:
; WITH CTE AS (
SELECT accountno, tdate,
rowno = row_number OVER (PARTITION BY accountno ORDER BY tdate)
FROM tbl
SELECT a.accoounno, a.tdate, datediff(DAY, b.tdate, atdate)
FROM CTE A
LEFT JOIN CTE B ON b.accountno = a.accountno
AND b.rowno = a.rowno - 1
ORDER BY a.accountno, a.tdate
Erland Sommarskog, SQL Server MVP, [email protected] -
Copy from column to another column in same table
Hi,
Working on EBS Version : 11.5.10.2
Table Name : ASO_QUOTE_HEADERS_ALL
COLUMNS :
QUOTE_STATUS_ID NUMBER
ATTRIBUTE6 VARCHAR2(240 BYTE);
Need to copy from quote_status_id to attribute6 for that quote_header_id
example if quote_status_id = 10 then it should copy in attribute6 = 10 for quote_header_id = 69312
again if changed to quote_status_id = 10077 then it should replace with attribute6 = 10077
for quote_header_id = 69312
i wrote a procedure posted below:
CREATE OR REPLACE procedure SLC_STATUS_CAPTURE (p_quote_header_id IN number) is
BEGIN
UPDATE aso_quote_headers_all SET attribute6 = quote_status_id
WHERE quote_header_id = p_quote_header_id;
end SLC_STATUS_CAPTURE;
then calling this trigger through table level
BEGIN
SLC_STATUS_CAPTURE(:OLD.QUOTE_HEADER_ID);
END;
it is giving an error.
Please i need some help.
Thanks and Regards
VijayJohn Spencer wrote:
As others have mentioned, you cannot change column values in a statement level trigger. Also, you cannot
update the table that the trigger is firing on. If I understand correctly, you want to copy the value of
quote_status_id into attribute6 whenever a row is inserted or updated. If that is correct, then you only need a simple trigger like:
create trigger trigg
before insert or update of aso_quote_headers_all
for each row
begin
:new.attribute6 = :new.quote_status_id;
end;Thought why anybody would want to do this is beyond me - you already have the info
in your attribute6 column - what's the point in simply copying it to another column in
the same table?
Paul...
John -
Render a column based on other column value in the same table
JDev 11.1.1.6.0
This may be a silly question but I am stuck
I need to conditionally render a column say A. Condition is like if the value in the other column B of same table is equal to F. I should render column A only when this condition is satisfied. I have tried the following code:
<af:column sortProperty="PhoneNumber1"
sortable="false"
headerText="#{bindings.A.hints.PhoneNumber1.label}"
id="c146"
rendered="#{row.PhoneNumber1ResponseFlag eq 'F'}">
<af:outputText value="#{row.PhoneNumber1}"
id="ot130"/>
</af:column>
<af:column sortProperty="PhoneNumber1ResponseFlag"
sortable="false"
headerText="#{bindings.B.hints.PhoneNumber1ResponseFlag.label}"
id="c80" rendered="true">
<af:outputText value="#{row.PhoneNumber1ResponseFlag}"
id="ot129"/>
</af:column>
The data shown in the table for column PhoneNumber1ResponseFlag is F. Still my condition is not working.Timo was saying that it is not possible to render the column in some situations and not in anothers, you will always have to render the column.
The best way to do this is instead of showing a column with the text ' ', show something meaningfull to the user. This is a DataWarehouse advice to you and may be usefull since you're using ADF in a area that uses DataWarehouse..
So the code could be something like this (based on Timo's code):
<af:column sortProperty="PhoneNumber1"
sortable="false"
headerText="#{bindings.A.hints.PhoneNumber1.label}"
id="c146">
<af:outputText value="#{row.PhoneNumber1ResponseFlag eq 'False.' ? row.PhoneNumber1 : 'No value applied.'"
id="ot130"/>
</af:column>
<af:column sortProperty="PhoneNumber1ResponseFlag"
sortable="false"
headerText="#{bindings.B.hints.PhoneNumber1ResponseFlag.label}"
id="c80">
<af:outputText value="#{row.PhoneNumber1ResponseFlag}"
id="ot129"/>
</af:column>
Hope that helps,
Frederico. -
Create ViewCriteria comparing two columns from same table
Does anyone know how I can create a ViewCriteria where clause that compares two columns from the same table?
For example if I had two integer columns (MINSAL and MAXSAL) and wanted to see if they are equal. I would normally do the following SQL below.
SELECT * FROM EMPL
WHERE MINSAL = MAXSALIt works, but it is not ideal.
Setup a Transient column that performs a groovy evaluation of MINSAL=MAXSAL and then my ViewCriteria evaluates the column to true and I set Query Execution Mode to Both. -
Inserting a LONG to a BLOB in the same table
I have a table with a LONG column and would like to concatenate all existing columns into a new column in the same table and define it as a BLOB. I'm trying to figure out a way to do this. I tried the following and got error message
insert into cma_search_test
select obj_id,
line_id,
doc_nmbr,
supplier_part_num,
mnfctr,
mnfctr_part_nmbr,
line_desc,
ext_desc_txt,
vend_name,
cma_effect_dt,
cma_expir_dt,
last_updt_usr,
last_updt_tmsp,
obj_id||
line_id||
doc_nmbr||
supplier_part_num||
mnfctr||
mnfctr_part_nmbr||
line_desc||
to_lob(ext_desc_txt)||
vend_name||
cma_effect_dt||
cma_expir_dt||
last_updt_usr||
last_updt_tmsp "All_Columns"
from cma_search
to_lob(ext_desc_txt)||
ERROR at line 22:
ORA-00932: inconsistent datatypes
Any help would be appreciated.
Thanks,
TracyYou cannot concatenate a LONG field. You will have to use a procedure to accomplish what you want.
Use the DBMS_LOB package. -
JTable fixed Row and Column in the same window
Hi
Could anyone tip me how to make fixed row and column in the same table(s).
I know how to make column fixed and row, tried to combine them but it didnt look pretty.
Can anyone give me a tip?
Thanks! :)Got it to work!
heres the kod.. nothing beautiful, didnt clean it up.
* NewClass.java
* Created on den 29 november 2007, 12:51
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package tablevectortest;
* @author Sockan
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
public class FixedRowCol extends JFrame {
Object[][] data;
Object[] column;
JTable fixedTable,table,fixedColTable,fixedTopmodelTable;
private int FIXED_NUM = 16;
public FixedRowCol() {
super( "Fixed Row Example" );
data = new Object[][]{
{ "","A","A","A","",""},
{ "a","b","","","",""},
{ "a","","c","","",""},
{ "","","","d","",""},
{ "","","","","e",""},
{ "","","","","","f"},
{ "","b","","","",""},
{ "","","c","","",""},
{ "","","","d","",""},
{ "","","","","e",""},
{ "","b","","","",""},
{ "","","c","","",""},
{ "","","","d","",""},
{ "","","","","e",""},
{ "","","","","","f"},
{ "I","","W","G","A",""}};
column = new Object[]{"A","B","C","D","E","F"};
AbstractTableModel fixedColModel = new AbstractTableModel() {
public int getColumnCount() {
return 1;
public int getRowCount() {
return data.length;
public String getColumnName(int col) {
return (String) column[col];
public Object getValueAt(int row, int col) {
return data[row][col];
public boolean CellEditable(int row, int col) {
return true;
AbstractTableModel model = new AbstractTableModel() {
public int getColumnCount() { return column.length-2; }
public int getRowCount() { return data.length - FIXED_NUM; }
public String getColumnName(int col) {
return (String)column[col+1];
public Object getValueAt(int row, int col) {
return data[row][col+1];
public void setValueAt(Object obj, int row, int col) {
data[row][col+1] = obj;
public boolean CellEditable(int row, int col) {
return true;
AbstractTableModel fixedTopModel = new AbstractTableModel() {
public int getColumnCount() { return 1; }
public int getRowCount() { return data.length - FIXED_NUM; }
public String getColumnName(int col) {
return (String)column[col];
public Object getValueAt(int row, int col) {
return data[row][col];
public void setValueAt(Object obj, int row, int col) {
data[row][col] = obj;
public boolean CellEditable(int row, int col) {
return true;
AbstractTableModel fixedModel = new AbstractTableModel() {
public int getColumnCount() { return column.length-2; }
public int getRowCount() { return FIXED_NUM; }
public Object getValueAt(int row, int col) {
return data[row + (data.length - FIXED_NUM)][col+1];
table = new JTable( model );
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
fixedTable = new JTable( fixedModel );
fixedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
fixedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
fixedColTable= new JTable(fixedColModel);
fixedColTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
fixedColTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
fixedTopmodelTable = new JTable(fixedTopModel);
fixedTopmodelTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
fixedTopmodelTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane scroll = new JScrollPane( table );
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
JScrollPane fixedScroll = new JScrollPane( fixedTable ) {
public void setColumnHeaderView(Component view) {}
fixedScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
fixedScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
JScrollBar bar = scroll.getVerticalScrollBar();
JScrollBar dummyBar = new JScrollBar() {
public void paint(Graphics g) {}
dummyBar.setPreferredSize(bar.getPreferredSize());
scroll.setVerticalScrollBar(dummyBar);
final JScrollBar bar1 = scroll.getHorizontalScrollBar();
JScrollBar bar2 = fixedScroll.getHorizontalScrollBar();
bar2.addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
bar1.setValue(e.getValue());
JViewport viewport = new JViewport();
viewport.setView(fixedColTable);
viewport.setPreferredSize(fixedColTable.getPreferredSize());
fixedScroll.setRowHeaderView(viewport);
fixedScroll.setCorner(JScrollPane.UPPER_LEFT_CORNER, fixedColTable
.getTableHeader());
JViewport viewport2 = new JViewport();
viewport2.setView(fixedTopmodelTable);
viewport2.setPreferredSize(fixedTopmodelTable.getPreferredSize());
scroll.setRowHeaderView(viewport2);
scroll.setCorner(JScrollPane.UPPER_LEFT_CORNER, fixedTopmodelTable
.getTableHeader());
scroll.setPreferredSize(new Dimension(600, 19));
fixedScroll.setPreferredSize(new Dimension(600, 100));
getContentPane().add( scroll, BorderLayout.NORTH);
getContentPane().add(fixedScroll, BorderLayout.CENTER);
public static void main(String[] args) {
FixedRowCol frame = new FixedRowCol();
frame.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit(0);
frame.pack();
frame.setVisible(true);
} -
Compare two rows in same table
Hi,
I want to compare two rows (some columns) in the same table, and if the data in the data columns is different, I want to pick the latest one. The table is date tracked. For instance I have an address table with different addresses for an employee with effective date. I want to be able to pick the latest row if the postal code is different for the 2 rows. Is this possible in sql. I can do this in Pl/sql, but dont want to use it. Eg
address_id, postal_code, person_id,last_update_date
123, pn123,1,12-JAN-01
124,pu124,1,13-JAN-01
I want to be able to retrieve just the second line.
Any help is appreciatedWelcome to the forum!
Whenever you post please provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
>
The table is date tracked. For instance I have an address table with different addresses for an employee with effective date. I want to be able to pick the latest row if the postal code is different for the 2 rows.
>
Your question is a little confusing because you are using terms like 'date tracked' and 'effective date' without explaining exactly what your definitions of those terms is.
Why do you want the latest record ONLY if the postal code is different? What if the address is different? Then which record do you want?
Why not just take the record for each person/company that has the latest date? If the data is the same then it doesn't which record you get so the one with the latest date will do. And if the data is different taking the one with the latest date gives you the latest data.
The classic definition of effective date is 'the date the information becomes effective'. Information with a given effective date is NOT in effect before that date and is SUPERCEDED when data is entered with a later effective date if the actual date is later than or equal to the effective date. Using your data
>
123, pn123,1,12-JAN-01
124,pu124,1,13-JAN-01
>
The first record IS NOT effective for dates prior to 12-JAN-01. In fact for a query looking for data prior to that date there isn't any data.
The first record is also NOT effective for dates on or after 13-JAN-01. Only the second record is effective.
If you added a record for 14-JAN-01 this record would not be effective until on or after that date (i.e. not for another 4 1/2 months).
So for the classic definition of effective date the query needs to provide the AS OF date to use to obtain the data. If, as in your system, you are not allowed to create records with dates in the future and you just want the latest record then you can just select the record with the MAX(myDate) value for the given person_id, address_id or whatever your key values are.
Edited by: rp0428 on Aug 11, 2012 7:50 AM
Maybe you are looking for
-
Is it possible to do it by graphically selecting the segment of the xy-graph curve?
-
Have purchased above from John Lewis Cheadle 02/02/12, including in purchase price was set up charges. Didnt appear a problem until this morning when attempting to 1st time use Simple but true, have attempted to enter password as instructed but where
-
Apple TV on Interactive Whiteboard with no sound?
Working in a school, iPads and Apple TV are a vital part of day to day lessons. We connect Apple TV to the HD projectors in each room for Airplaying purposes on the iPads. When it is mirroring on to the projector, and on to the Whiteboard, we can get
-
SQL Aggregate function and Subquery issues
Hello, I'm trying to create an SQL statement that gives the rate of all Urgent surgeries Grouped by sector (i.e Surgery, Radiology), and Fiscal year To do this I need to divide the sum of surgeries with a state "Urgent" by the total surgeries In orde
-
Day light saving Time not taking effect
Hi all, I have Sun Solaris 10 with Generic 125101-05 version with JDK 1.5_07 . in which DST not taking . recently for Australia & New Zeland Time has changed with 1hour head . in server i have ntp syncing with Global server . but DST changes has not