Eliminating Null After Pivoting the Column
hello,
I have a request where we are suppoed to Pivot a columns to Rows, doing so we get nulls. My questions here is what is the best approach to Pivot and Eliminate Nulls. does anyone came across anything similar?
ID
Name
Typeof record
Data1
Data 2
Data3
1
John
Type A
100
400
700
2
John
Type b
200
500
800
3
John
Type c
300
600
900
4
Marry
Type A
1000
4000
7000
5
Marry
Type b
2000
5000
8000
6
Marry
Type c
3000
6000
9000
To
ID
Name
PersonsData
Type A
Type B
Type C
1
John
Data1
100
2
John
Data1
200
3
John
Data1
300
1
John
Data2
400
2
John
Data2
500
3
John
Data2
600
1
John
Data3
700
2
John
Data3
800
3
John
Data3
900
4
Marry
Data1
1000
5
Marry
Data1
2000
6
Marry
Data1
3000
4
Marry
Data2
4000
5
Marry
Data2
5000
6
Marry
Data2
6000
4
Marry
Data3
7000
5
Marry
Data3
8000
6
Marry
Data3
9000
How are you doing it?
Based on what you are showing us, you are unpivoting the [data] columns and pivoting the [type of record]. Then you will need to group by [name] and [person_data] but you will need to get rid of the [id] column because it is represented by the new columns
derived from [type_of_record] or removing it previous to the pivoting (guessing they are tied (id, type_of_record)).
DECLARE @T table (
id int,
name varchar(35),
type_of_record varchar(15),
data1 int,
data2 int,
data3 int);
INSERT INTO @T
(id, name, type_of_record, data1, data2, data3)
VALUES
(1, 'John', 'Type a', 100, 400, 700),
(2, 'John', 'Type b', 200, 500, 800),
(3, 'John', 'Type c', 300, 600, 900),
(4, 'Marry', 'Type a', 1000, 4000, 7000),
(5, 'Marry', 'Type b', 2000, 5000, 8000),
(6, 'Marry', 'Type c', 3000, 6000, 9000);
SELECT
P.name,
p.person_data,
MAX([Type a]) AS [type a],
MAX([Type b]) AS [type b],
MAX([Type c]) AS [type c]
FROM
@T
UNPIVOT
(value FOR person_data IN ([data1], [data2], [data3])) AS U
PIVOT
(MAX(value) FOR type_of_record IN ([Type a], [Type b], [Type c])) AS P
GROUP BY
P.name,
p.person_data
ORDER BY
P.name,
p.person_data;
-- removing column id previous to the pivoting
WITH R1 AS (
SELECT
U.name,
U.type_of_record,
U.person_data,
U.value
FROM
@T
UNPIVOT
(value FOR person_data IN ([data1], [data2], [data3])) AS U
SELECT
P.*
FROM
R1
PIVOT
(MAX(value) FOR type_of_record IN ([Type a], [Type b], [Type c])) AS P;
GO
AMB
Some guidelines for posting questions...
AYÚDANOS A AYUDARTE, guía básica de consejos para formular preguntas
Similar Messages
-
SQL Help -- Need help with pivoting the columns to rows
I have a requierement to split the columns into multiple rows. For example:
EMP_DEPT
rowid empid1 ename1 dept1 empid2 ename2 dep2 empid2 ename2 dep3 empid4 ename4 dept4
100001 1 'SCOTT' 10 2 'DAVE' 20 3 'MILLER' 10 4 SMITH 20
100002 1 'SCOTT' 10 2 'DAVE' 20 3 'MILLER' 20
Note: EMP_DEPT may not always have all the 4 employee info populated for example in row 2 only 3 employees info is there
I need to convert it and insert into EMPLOYEE table as follows:
EMPLOYEE
empid ename dept
1 SCOTT 10
2 DAVE 20
3 MILLER 10
4 SMITH 20
1 SCOTT 10
2 DAVE 20
3 MILLER 20
Thanks
KevFrank Thank You for your response.
I am on oracle 10gR2.
Posting some sample DDL and data here as requested:
CREATE TABLE EMP
PK NUMBER(10),
EMP_NAME1 VARCHAR2(100 BYTE),
EMP_ID1 NUMBER(10),
EMP_NAME2 VARCHAR2(100 BYTE),
EMP_ID2 NUMBER(10),
DEPT_NAME1 VARCHAR2(200 BYTE),
DEPT_ID1 NUMBER(10),
DEPT_NAME2 VARCHAR2(200 BYTE),
DEPT_ID2 NUMBER(10)
CREATE TABLE EMP_DEPT
( PK NUMBER(10),
ENTY_TYPE VARCHAR2(100),
ENTY_NAME VARCHAR2(100),
ENTY_ID NUMBER(10)
Insert into EMP
(PK, EMP_NAME1, EMP_ID1, EMP_NAME2, EMP_ID2, DEPT_NAME1, DEPT_ID1, DEPT_NAME2, DEPT_ID2)
Values
(1, 'SCOTT', 10001, 'FRANK', 10002,
'MARKETING', 10, 'ACCOUNTING', 20);
Insert into EMP
(PK, EMP_NAME1, EMP_ID1, EMP_NAME2, EMP_ID2, DEPT_NAME1, DEPT_ID1)
Values
(2, 'SCOTT1', 10003, 'FRANK1', 10004,
'MARKETING1', 30);
COMMIT;
SELECT
FROM
EMP;
PK EMP_NAME1 EMP_ID1 EMP_NAME2 EMP_ID2 DEPT_NAME1 DEPT_ID1 DEPT_NAME2 DEPT_ID2
1 SCOTT 10001 FRANK 10002 MARKETING 10 ACCOUNTING 20
2 SCOTT1 10003 FRANK1 10004 MARKETING1 30 My requirement is to:
SELECT from emp and INSERT INTO EMP_DEPT so that columns are broken into rows as follows
PK ENTY_TYPE, ENTY_NAME ENTY_ID
1 EMPLOYEE SCOTT 10001
2 EMPLOYEE FRANK 10002
3 DEPARTMENT MARKETING 10
4 DEPARTMENT ACCOUNTING 20
5 EMPLOYEE SCOTT1 10003
6 EMPLOYEE FRANK1 10004
7 DEPARTMENT MARKETING1 30 Thanks
Kevin
Edited by: user10210466 on Dec 8, 2010 1:37 PM -
9.2.0.6
if I do
select column_name
from user_tab_columns where table_name = 'EMP' order by column_id;
I get the list of columns:
EMPNO
ENAME
JOB
MGR
HIREDATE
SAL
COMM
DEPTNO
what I want to do is display them in the form of
'EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO'
In the past when I have done this type of thing I have used a union but the problem there is I in my real situation I will not know how long my list will be.
Thanks.Check this links, they provide some examples:
http://asktom.oracle.com/pls/ask/f?p=4950:8:15858227305267421226::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:15151874723724
http://asktom.oracle.com/pls/ask/f?p=4950:8:15858227305267421226::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:8119875218670 -
How to resize the columns in the report
Hi
I want to resize the columns in my report to make them smaller so that they don't overlap, but after resizing the columns still overlap so that some columns headings are under the other ones.
ThanksYou can do it either by, going to the property palette of the column and then change the horizontal elasticity to 'Variable', this way it will shrink or enlarge the size automatically. Or, you can do in manually in the layout model, click the column then click the edge of the field and drag it to make it longer or shorter.
-Marilyn -
How to display the column into the narrative or section from pivot table
I have a report. I have the basic number displayed in the pivot table, but missing one column and I need move one column to the top. The column missing (% of tested) should be calculated by column c /column F's last number, ie, F7=48. My desired column would be H3=c3/F48 9/48, H4=c4/F488/48.... But I could not get the number 48 into my formula, because it is the running total of the all column E. These data is in Pivot table.
I also need display No of Students 74 in the top of the report. I am not able to get this number from pivot table. It is count distinct on student key from the repository.
I appreciate any help.
A B C D E F G
2 # of Questions Average # Correct % Correct Running total no. of test items No of students
3 PATTERNS, FUNCTIONS, AND ALGEBRA 9 4.68 51.95 9 74
4 PROBABILITY AND STATISTICS 8 3.97 49.66 17 74
5 MEASUREMENT AND GEOMETRY 11 6.11 55.53 28 74
6 NUMBER AND NUMBER SENSE 8 4.16 52.03 36 74
7 COMPUTATION AND ESTIMATION 12 8.2 68.36 48 74
Edited by: user7315022 on Feb 3, 2010 2:28 PMI wish it was this easy. I must not explain it right. All the score from each student and each question for each subject and each test is stored in database. The number of question for the subject is the max of the questions for each subject. Basically, it needs 'parittion by'... But in the OBIEE, it would not let me add any 'partition by' in the column formula. Is this true? ie, can you use partition by in the column formula? Here are the query from trace file.
RqList
TEST_YEAR_SEASONS.TEST_SEASON_NAME as c1 GB,
REPORTING_SCHOOL_YEARS.SCHOOL_YEAR as c2 GB,
MAX_TEST_SCORE:[DAggr(STUDENT_TEST_SCORES.MAX_TEST_SCORE by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, STUDENT_TEST_SCORES.STDNT_STNDRD_TEST_KEY, STUDENT_TEST_SCORES.STUDENTS_KEY, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, TEST_SCORE_TYPES.TEST_SCORE_TYPE_NAME, SCHOOLS.SCHOOL_NAME, STUDENT_TEST_SCORES.TEST_SCORE_NUMBER] )] as c3 GB,
STUDENT_TEST_SCORES.TEST_SCORE_NUMBER as c4 GB,
DIVISION_TOTAL_TESTS:[DAggr(STUDENT_TEST_SCORES.DIVISION_TOTAL_TESTS by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, STUDENT_TEST_SCORES.STDNT_STNDRD_TEST_KEY, STUDENT_TEST_SCORES.STUDENTS_KEY, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, TEST_SCORE_TYPES.TEST_SCORE_TYPE_NAME, SCHOOLS.SCHOOL_NAME, STUDENT_TEST_SCORES.TEST_SCORE_NUMBER] )] as c5 GB,
RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME as c6 GB,
RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME as c7 GB,
TEST_SCORE_TYPES.TEST_SCORE_TYPE_NAME as c8 GB,
SCHOOLS.SCHOOL_NAME as c9 GB,
SUM_TEST_SCORE:[DAggr(STUDENT_TEST_SCORES.SUM_TEST_SCORE by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, STUDENT_TEST_SCORES.STDNT_STNDRD_TEST_KEY, STUDENT_TEST_SCORES.STUDENTS_KEY, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, TEST_SCORE_TYPES.TEST_SCORE_TYPE_NAME, SCHOOLS.SCHOOL_NAME, STUDENT_TEST_SCORES.TEST_SCORE_NUMBER] )] as c10 GB,
SUM_TEST_SCORE:[DAggr(STUDENT_TEST_SCORES.SUM_TEST_SCORE by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, STUDENT_TEST_SCORES.STDNT_STNDRD_TEST_KEY, STUDENT_TEST_SCORES.STUDENTS_KEY, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, TEST_SCORE_TYPES.TEST_SCORE_TYPE_NAME, SCHOOLS.SCHOOL_NAME, STUDENT_TEST_SCORES.TEST_SCORE_NUMBER] )] / nullif( COUNT_TEST_SCORE:[DAggr(STUDENT_TEST_SCORES.COUNT_TEST_SCORE by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, STUDENT_TEST_SCORES.STDNT_STNDRD_TEST_KEY, STUDENT_TEST_SCORES.STUDENTS_KEY, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, TEST_SCORE_TYPES.TEST_SCORE_TYPE_NAME, SCHOOLS.SCHOOL_NAME, STUDENT_TEST_SCORES.TEST_SCORE_NUMBER] )] , 0) as c11 GB,
MAX_TEST_SCORE:[DAggr(STUDENT_TEST_SCORES.MAX_TEST_SCORE by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, STUDENT_TEST_SCORES.STDNT_STNDRD_TEST_KEY, STUDENT_TEST_SCORES.STUDENTS_KEY, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, TEST_SCORE_TYPES.TEST_SCORE_TYPE_NAME, SCHOOLS.SCHOOL_NAME, STUDENT_TEST_SCORES.TEST_SCORE_NUMBER] )] as c12 GB,
(SUM_TEST_SCORE:[DAggr(STUDENT_TEST_SCORES.SUM_TEST_SCORE by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, STUDENT_TEST_SCORES.STDNT_STNDRD_TEST_KEY, STUDENT_TEST_SCORES.STUDENTS_KEY, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, TEST_SCORE_TYPES.TEST_SCORE_TYPE_NAME, SCHOOLS.SCHOOL_NAME, STUDENT_TEST_SCORES.TEST_SCORE_NUMBER] )] / nullif( COUNT_TEST_SCORE:[DAggr(STUDENT_TEST_SCORES.COUNT_TEST_SCORE by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, STUDENT_TEST_SCORES.STDNT_STNDRD_TEST_KEY, STUDENT_TEST_SCORES.STUDENTS_KEY, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, TEST_SCORE_TYPES.TEST_SCORE_TYPE_NAME, SCHOOLS.SCHOOL_NAME, STUDENT_TEST_SCORES.TEST_SCORE_NUMBER] )] , 0)) / nullif( MAX_TEST_SCORE:[DAggr(STUDENT_TEST_SCORES.MAX_TEST_SCORE by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, STUDENT_TEST_SCORES.STDNT_STNDRD_TEST_KEY, STUDENT_TEST_SCORES.STUDENTS_KEY, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, TEST_SCORE_TYPES.TEST_SCORE_TYPE_NAME, SCHOOLS.SCHOOL_NAME, STUDENT_TEST_SCORES.TEST_SCORE_NUMBER] )] , 0) * 100 as c13 GB,
STUDENT_TEST_SCORES.STDNT_STNDRD_TEST_KEY as c14 GB,
STUDENT_TEST_SCORES.STUDENTS_KEY as c15 GB,
max(SUM_TEST_SCORE:[DAggr(STUDENT_TEST_SCORES.SUM_TEST_SCORE by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, SCHOOLS.SCHOOL_NAME] )] by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, SCHOOLS.SCHOOL_NAME] at_distinct [ ] ) / nullif( max(COUNT_TEST_SCORE:[DAggr(STUDENT_TEST_SCORES.COUNT_TEST_SCORE by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, SCHOOLS.SCHOOL_NAME] )] by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, SCHOOLS.SCHOOL_NAME] at_distinct [ ] ) , 0) as c16 GB,
(max(SUM_TEST_SCORE:[DAggr(STUDENT_TEST_SCORES.SUM_TEST_SCORE by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, SCHOOLS.SCHOOL_NAME] )] by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, SCHOOLS.SCHOOL_NAME] at_distinct [ ] ) / nullif( max(COUNT_TEST_SCORE:[DAggr(STUDENT_TEST_SCORES.COUNT_TEST_SCORE by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, SCHOOLS.SCHOOL_NAME] )] by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, SCHOOLS.SCHOOL_NAME] at_distinct [ ] ) , 0)) / nullif( max(MAX_TEST_SCORE:[DAggr(STUDENT_TEST_SCORES.MAX_TEST_SCORE by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, SCHOOLS.SCHOOL_NAME] )] by [ REPORTING_SCHOOL_YEARS.SCHOOL_YEAR, TEST_YEAR_SEASONS.TEST_SEASON_NAME, RPT_TEST_DEFINITIONS.TEST_SUBJECT_NAME, RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME, SCHOOLS.SCHOOL_NAME] at_distinct [ ] ) , 0) * 100 as c17 GB
DetailFilter: RPT_TEST_DEFINITIONS.TEST_LEVEL_NAME = 'GRADE 5' and SCHOOLS.SCHOOL_NAME = 'GLASGOW MIDDLE' and TEST_SCORE_TYPES.TEST_SCORE_TYPE_NAME = 'RAW SCORE' and TEST_YEAR_SEASONS.TEST_SEASON_NAME = 'SPRING' and REPORTING_SCHOOL_YEARS.SCHOOL_YEAR = '200102' and TESTS.TEST_ID = 'SOL' and TEST_DEFINITIONS.PARENT_TEST_SUBJECT_NAME = 'MATHEMATICS' and STUDENT_TEST_SCORES.TEST_SCORE_NUMBER < 900
OrderBy: c1 asc, c2 asc, c4 asc, c6 asc, c7 asc, c8 asc, c9 asc, c14 asc, c15 asc
+++azadams:320000:32001b:----2010/02/03 16:48:36
-------------------- Sending query to database named tacdev (id: <<51109>>):
select distinct D1.c5 as c1,
D1.c4 as c2,
D1.c9 as c3,
D1.c14 as c4,
D1.c12 as c5,
D1.c6 as c6,
D1.c7 as c7,
D1.c15 as c8,
D1.c8 as c9,
D1.c11 as c10,
D1.c11 / decode(D1.c10 , 0 , to_number(null), D1.c10) as c11,
D1.c9 as c12,
(D1.c11 / decode(D1.c10 , 0 , to_number(null), D1.c10)) / decode(D1.c9 , 0 , to_number(null), D1.c9) * 100 as c13,
D1.c13 as c14,
D1.c16 as c15,
D1.c3 / decode(D1.c2 , 0 , to_number(null), D1.c2) as c16,
(D1.c3 / decode(D1.c2 , 0 , to_number(null), D1.c2)) / decode(D1.c1 , 0 , to_number(null), D1.c1) * 100 as c17
from
(select max(D1.c1) over (partition by D1.c4, D1.c5, D1.c6, D1.c7, D1.c8) as c1,
sum(D1.c2) over (partition by D1.c4, D1.c5, D1.c6, D1.c7, D1.c8) as c2,
sum(D1.c3) over (partition by D1.c4, D1.c5, D1.c6, D1.c7, D1.c8) as c3,
D1.c4 as c4,
D1.c5 as c5,
D1.c6 as c6,
D1.c7 as c7,
D1.c8 as c8,
max(D1.c1) over (partition by D1.c4, D1.c16, D1.c5, D1.c13, D1.c6, D1.c7, D1.c15, D1.c8) as c9,
sum(D1.c2) over (partition by D1.c4, D1.c16, D1.c5, D1.c13, D1.c6, D1.c7, D1.c15, D1.c8) as c10,
sum(D1.c3) over (partition by D1.c4, D1.c16, D1.c5, D1.c13, D1.c6, D1.c7, D1.c15, D1.c8) as c11,
sum(D1.c12) over (partition by D1.c4, D1.c16, D1.c5, D1.c13, D1.c6, D1.c7, D1.c15, D1.c8) as c12,
D1.c13 as c13,
D1.c14 as c14,
D1.c15 as c15,
D1.c16 as c16
from
(select max(T56699.TEST_SCORE_NUMBER) as c1,
count(T56699.TEST_SCORE_NUMBER) as c2,
sum(T56699.TEST_SCORE_NUMBER) as c3,
T33435.SCHOOL_YEAR as c4,
T34232.TEST_SEASON_NAME as c5,
T52429.TEST_SUBJECT_NAME as c6,
T52429.TEST_LEVEL_NAME as c7,
T59709.SCHOOL_NAME as c8,
count(T36922.STDNT_STNDRD_TEST_KEY) as c12,
T36922.STDNT_STNDRD_TEST_KEY as c13,
T56699.TEST_SCORE_NUMBER as c14,
T56693.TEST_SCORE_TYPE_NAME as c15,
T36922.STUDENTS_KEY as c16
from
SCHOOLS T59709,
TEST_DEFINITIONS T58733,
TEST_SCORE_TYPES T56693,
RPT_TEST_DEFINITIONS T52429,
TEST_YEAR_SEASONS T34232,
REPORTING_SCHOOL_YEARS T33435,
TESTS T34149,
DETAIL_TEST_SCORES T33341,
STUDENT_STANDARD_TEST T36922,
TEST_SCORES T56699
where ( T33341.TEST_SCORE_TYPES_KEY = T56693.TEST_SCORE_TYPES_KEY and T36922.ADMIN_SCHOOLS_KEY = T59709.SCHOOLS_KEY and T34232.TEST_YEAR_SEASONS_KEY = T36922.TEST_YEAR_SEASONS_KEY and T33435.REPORTING_SCHOOL_YEARS_KEY = T36922.REPORTING_SCHOOL_YEARS_KEY and T34149.TESTS_KEY = T36922.TESTS_KEY and T36922.TEST_DEFINITIONS_KEY = T58733.TEST_DEFINITIONS_KEY and T33341.STDNT_STNDRD_TEST_KEY = T36922.STDNT_STNDRD_TEST_KEY and T33341.TEST_SCORES_KEY = T56699.TEST_SCORES_KEY and T33435.SCHOOL_YEAR = '200102' and T34149.TEST_ID = 'SOL' and T34232.TEST_SEASON_NAME = 'SPRING' and T36922.RPT_TEST_DEFINITIONS_KEY = T52429.RPT_TEST_DEFINITIONS_KEY and T52429.TEST_LEVEL_NAME = 'GRADE 5' and T56693.TEST_SCORE_TYPE_NAME = 'RAW SCORE' and T58733.PARENT_TEST_SUBJECT_NAME = 'MATHEMATICS' and T59709.SCHOOL_NAME = 'GLASGOW MIDDLE' and T56699.TEST_SCORE_NUMBER < 900 )
group by T33435.SCHOOL_YEAR, T34232.TEST_SEASON_NAME, T36922.STDNT_STNDRD_TEST_KEY, T36922.STUDENTS_KEY, T52429.TEST_SUBJECT_NAME, T52429.TEST_LEVEL_NAME, T56693.TEST_SCORE_TYPE_NAME, T56699.TEST_SCORE_NUMBER, T59709.SCHOOL_NAME
) D1
) D1 -
TableView - How to update a running balance column after any other column in the view is re-sorted
To keep this simple and to illustrate a problem that I am trying to solve let's say we have
a domain class that contains an income per day.
This class has two persistent properties - populated from a database table - date and income.
And there is one transient property - running balance - that shows the accumulated income
starting from the first record. This property is not persisted and it is used only to show
the running/accumulated income in a table view.
This domain object is shown in a table view with three columns:
- date
- income
- running balance
The first two columns - date and income - are sortable. When the user clicks on the column
heading these can will be sorted in ascending or descending order. The running balance
column needs to reflect this change and be correctly updated.
So the question is : how would you implement the running balance update after the data in
the table has been updated by the user?
Take 1)
=============
The obvious approach is to use "setOnSort" method to consume the SortEvent event and re-sort the
data but the sort-event does not contain any useful information that would tell from which column
the sort event originated.
Take 2)
=============
Found a possible solution:
- TableView.getSortOrder() returns a list that defines the order in which TableColumn instances are sorted after the user clicked one or more column headings.
- TableColumn.getSortType() returns the sort type - ascending/descending.
- This info can be used in the TableView.setOnSort() event handler to re-sort the data and update the balance at the same time.
Take 3)
=============
When the TableView.setOnSort() event handler is called the data is already sorted therefore the only thing that needs to be done is to update the running balance.I think I understand what you're trying to do. If I've missed it, apologies, but I think this will provide you with something you can work from anyway.
I would listen to the data instead of watching specifically for sorting. This will be much more robust if you add new functionality later (such as adding and removing rows, editing the data that's there, etc).
Specifically, for the runningBalance column, create a cellValueFactory that provides a DoubleBinding; this binding should listen for changes to the data and compute the value by running through the table's items up to the point of the item for which it's displaying the value. (Hope you can untangle that sentence.)
Example. The important part is the cellValueFactory for the cumulativeAmountCol. I guess I should mention that you shouldn't try this exact approach with very large tables as the performance might be pretty bad (computations of the order of n x m on changing data, where n is the number of rows in the table and m is the number of visible rows in the table).
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import javafx.application.Application;
import javafx.beans.Observable;
import javafx.beans.binding.DoubleBinding;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellDataFeatures;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.util.Callback;
public class CumulativeTableColumnExample extends Application {
private final static int NUM_ITEMS = 20 ;
@Override
public void start(Stage primaryStage) {
final TableView<LineItem> table = new TableView<>();
// using the extractor here makes sure the table item list fires a list changed event if any amounts change
// this enables the cumulative amount column to keep up to date when the amount in a different row changes.
table.setItems(FXCollections.observableList(createRandomData(), new Callback<LineItem, Observable[]>() {
@Override
public Observable[] call(LineItem item) {
return new Observable[] {item.amountProperty()};
final TableColumn<LineItem, Date> dateCol = new TableColumn<>("Date");
final TableColumn<LineItem, Number> amountCol = new TableColumn<>("Amount");
final TableColumn<LineItem, Number> cumulativeAmountCol = new TableColumn<>("Cumulative Amount");
table.getColumns().addAll(Arrays.asList(dateCol, amountCol, cumulativeAmountCol));
dateCol.setCellValueFactory(new PropertyValueFactory<LineItem, Date>("date"));
amountCol.setCellValueFactory(new PropertyValueFactory<LineItem, Number>("amount"));
cumulativeAmountCol.setCellValueFactory(new PropertyValueFactory<LineItem, Number>("amount"));
cumulativeAmountCol.setSortable(false); // otherwise bad things might happen
final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
dateCol.setCellFactory(new Callback<TableColumn<LineItem, Date>, TableCell<LineItem, Date>>() {
@Override
public TableCell<LineItem, Date> call(TableColumn<LineItem, Date> col) {
return new TableCell<LineItem, Date>() {
@Override
public void updateItem(Date date, boolean empty) {
super.updateItem(date, empty);
if (empty) {
setText(null);
} else {
setText(dateFormat.format(date));
cumulativeAmountCol.setCellValueFactory(new Callback<CellDataFeatures<LineItem, Number>, ObservableValue<Number>> () {
@Override
public ObservableValue<Number> call(CellDataFeatures<LineItem, Number> cellData) {
final LineItem currentItem = cellData.getValue() ;
DoubleBinding value = new DoubleBinding() {
super.bind(table.getItems());
@Override
protected double computeValue() {
double total = 0 ;
LineItem item = null ;
for (Iterator<LineItem> iterator = table.getItems().iterator(); iterator.hasNext() && item != currentItem; ) {
item = iterator.next() ;
total = total + item.getAmount() ;
return total ;
return value;
final NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
// generics hell.. can't wait for lambdas...
final Callback<TableColumn<LineItem, Number>, TableCell<LineItem, Number>> currencyCellFactory = new Callback<TableColumn<LineItem, Number>, TableCell<LineItem, Number>>() {
@Override
public TableCell<LineItem, Number> call(TableColumn<LineItem, Number> column) {
return new TableCell<LineItem, Number>() {
@Override
public void updateItem(Number amount, boolean empty) {
if (empty) {
setText(null) ;
} else {
setText(currencyFormat.format(amount));
amountCol.setCellFactory(currencyCellFactory);
cumulativeAmountCol.setCellFactory(currencyCellFactory);
BorderPane root = new BorderPane();
root.setCenter(table);
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
public List<LineItem> createRandomData() {
Random rng = new Random();
List<LineItem> items = new ArrayList<>();
for (int i=0; i<NUM_ITEMS; i++) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, rng.nextInt(365)-365);
double amount = (rng.nextInt(90000)+10000)/100.0 ;
items.add(new LineItem(cal.getTime(), amount));
return items ;
public static void main(String[] args) {
launch(args);
public static class LineItem {
private final ObjectProperty<Date> date ;
private final DoubleProperty amount ;
public LineItem(Date date, double amount) {
this.date = new SimpleObjectProperty<>(this, "date", date);
this.amount = new SimpleDoubleProperty(this, "amount", amount);
public final ObjectProperty<Date> dateProperty() {
return date;
public final Date getDate() {
return date.get();
public final void setDate(Date date) {
this.date.set(date);
public final DoubleProperty amountProperty() {
return amount ;
public final double getAmount() {
return amount.get();
public final void setAmount(double amount) {
this.amount.set(amount); -
Mail needs to be sent after updating the salary column of emp table
Hi,
we have table test_emp_table, oracle form based application is running on this table...
it conatins salary column, we have requirement that, when every any update to the salary column, a mail needs to be sent to concerned person with new and old salary values..
I did that using the following procedure...
===========
-- Create Temporary Table to hold the Updated values
create table email_parameters
( id number primary key,
oldsal varchar2(10),
newsal varchar2(10),
ename varchar2(100));
--- Create Procedure
CREATE OR REPLACE PROCEDURE send_email_new (
l_job IN NUMBER ) is
l_oldsal varchar2(100);
l_newsal varchar2(100);
l_emp_name varchar2(100);
l_message varchar2(100);
BEGIN
SELECT oldsal
INTO l_oldsal
FROM email_parameters
WHERE ID = l_job;
SELECT newsal
INTO l_newsal
FROM email_parameters
WHERE ID = l_job;
SELECT ename
INTO l_emp_name
FROM email_parameters
WHERE ID = l_job;
l_message:=
'Employee Name= '
|| l_emp_name
|| chr(10)||chr(10)
|| 'Old Salary= '
|| l_oldsal
|| chr(10)||chr(10)
|| 'New Salary= '
|| l_newsal;
send_mail(l_message);
DELETE FROM email_parameters
WHERE ID = l_job;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (DBMS_UTILITY.format_error_stack);
DBMS_OUTPUT.put_line (DBMS_UTILITY.format_call_stack);
END;
--- Create Trigger
create or replace trigger send_email_trg
after update on TEST_EMP_TABLE
for each row
declare
l_job number;
begin
dbms_job.submit (job => l_job,
what => 'send_email_new(job);' );
insert into email_parameters
values (l_job, :old.sal,:new.sal,:new.ename);
end send_email_trg;
-- Create Procedure for Sending Mail
create or replace procedure send_mail(l_message varchar2) is
c utl_smtp.connection;
PROCEDURE send_header(name VARCHAR2, header VARCHAR2) AS
BEGIN
utl_smtp.write_data(c,name ||':'|| header || UTL_TCP.CRLF);
END;
BEGIN
c := utl_smtp.open_connection('192.168.0.18');
utl_smtp.helo(c, 'abc.com');
utl_smtp.mail(c, '[email protected]');
utl_smtp.rcpt(c, '[email protected]');
utl_smtp.open_data(c);
send_header('From', '[email protected]');
send_header('To', '[email protected]');
send_header('Subject', 'Warning: Employee Solary has been updated!');
utl_smtp.write_data(c, UTL_TCP.CRLF || l_message);
utl_smtp.close_data(c);
utl_smtp.quit(c);
EXCEPTION
WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
BEGIN
utl_smtp.quit(c);
EXCEPTION
WHEN utl_smtp.transient_error
OR utl_smtp.permanent_error THEN
NULL;
END;
raise_application_error(-20000, SQLERRM);
END;
====================
But I have doubt, if there is any problem with mail server, if user is updating salary column from form based application at same time....
will table trigger allows him to save the new record or not????? or will he get any errors????thanks justin...
I have written that code..but it works...problem is ...i am not able to understand the flow...what happens in the order, until mail is sent...
i have another code.....
I have written with out dbms_job, i have witten directly in the trigger itself...
Tom suggested the procedure, what i have given above..but not the below procedure....
I am not able to understand, what is the difference between them.....
CREATE OR REPLACE TRIGGER test_emp_table_trg
AFTER UPDATE
ON test_emp_table
FOR EACH ROW
WHEN (NEW.sal <> OLD.sal)
DECLARE
l_employee_name VARCHAR2 (240);
l_old_sal VARCHAR2 (240);
l_new_sal VARCHAR2 (240);
l_message VARCHAR2 (240);
BEGIN
/* Gets the employee full name */
BEGIN
SELECT ename
INTO l_employee_name
FROM test_emp_table
WHERE empno = :OLD.empno;
EXCEPTION
WHEN OTHERS
THEN
l_employee_name := NULL;
END;
/* Gets the old Salary */
BEGIN
SELECT sal
INTO l_old_sal
FROM test_emp_table
WHERE empno = :OLD.empno;
EXCEPTION
WHEN OTHERS
THEN
l_old_sal := 0;
END;
/* Gets the new position name */
BEGIN
SELECT sal
INTO l_new_sal
FROM test_emp_table
WHERE empno= :NEW.empno;
EXCEPTION
WHEN OTHERS
THEN
l_new_sal := 0;
END;
l_message:=
'Employee Name= '
|| l_employee_name
|| 'Old Salary= '
|| l_old_sal
|| 'New Salary= '
|| l_new_sal;
BEGIN
send_mail (l_message);
END;
==========
can you please describe it clearly???
thanks in advance my dear friend????
Edited by: oraDBA2 on Oct 4, 2008 10:26 PM -
Help in Pivot Query- To change the column data to rows data!
Hello Gurus -
I have to change the row to Column -
When i use the query -
select NVL (T2.NAME, ' Grand Total') AS State,count(T2.NAME) as Total
from Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name like '%Compass Juice' GROUP BY ROLLUP (T2.NAME)
Then i have got the following data -
STATE TOTAL
Analysis 17
Closed 1302
Development 9
Duplicate 24
Failed 2
OnHold 4
Opened 146
QA 1
ReadyForQA 1
Withdrawn 335
Grand Total 1841
But i want the data in following format -
State Analysis Closed Development Duplicate Failed OnHold Opened QA ReadyForQA Withdrawn GrandTotal
Total 17 1302 9 24 2 4 146 1 1 335 1841
Kindly help me with this. I searched the forum and saw the usage of Max and NVL, Decode but i am unable to understand it to use in my query. kindly help me with this.Hi,
In 11g you can use pivot.
[http://www.oracle.com/technology/pub/articles/oracle-database-11g-top-features/11g-pivot.html]
example
SQL> desc customers
Name Null? Type
CUST_ID NUMBER(10)
CUST_NAME VARCHAR2(20)
STATE_CODE VARCHAR2(2)
TIMES_PURCHASED NUMBER(3)
When this table is selected:
select cust_id, state_code, times_purchased
from customers
order by cust_id;
The output is:
CUST_ID STATE_CODE TIMES_PURCHASED
1 CT 1
2 NY 10
3 NJ 2
4 NY 4
... and so on ...
Note how the data is represented as rows of values: For each customer, the record shows the customer's home state and how many times the customer purchased something from the store. As the customer purchases more items from the store, the column times_purchased is updated.
Now consider a case where you want to have a report of the purchase frequency each state�that is, how many customers bought something only once, twice, thrice and so on, from each state. In regular SQL, you can issue the following statement:
select state_code, times_purchased, count(1) cnt
from customers
group by state_code, times_purchased;
Here is the output:
ST TIMES_PURCHASED CNT
CT 0 90
CT 1 165
CT 2 179
CT 3 173
CT 4 173
CT 5 152
... and so on ...
This is the information you want but it's a little hard to read. A better way to represent the same data may be through the use of crosstab reports, in which you can organized the data vertically and states horizontally, just like a spreadsheet:
Times_purchased
CT NY NJ ... and so on ...
1 0 1 0 ...
2 23 119 37 ...
3 17 45 1 ...
... and so on ...
Prior to Oracle Database 11g, you would do that via some sort of a decode function for each value and write each distinct value as a separate column. The technique is quite nonintuitive however.
Fortunately, you now have a great new feature called PIVOT for presenting any query in the crosstab format using a new operator, appropriately named pivot. Here is how you write the query:
select * from (
select times_purchased, state_code
from customers t
pivot
count(state_code)
for state_code in ('NY','CT','NJ','FL','MO')
order by times_purchased
Here is the output:
. TIMES_PURCHASED 'NY' 'CT' 'NJ' 'FL' 'MO'
0 16601 90 0 0 0
1 33048 165 0 0 0
2 33151 179 0 0 0
3 32978 173 0 0 0
4 33109 173 0 1 0
... and so on ... -
Increasing the width of Pivot table Columns
Hi Gurus,
Small pivot table --> ( ie having less no of columns which generally can be seen in a single page without scrolling to the right)
If i have a small pivot table , then in the column properties through additional formatting options i can increase the width of an individual column.
However if the pivot table is Big,I am not able to increase the width of the individual column .
I tried setting width in the additional formatting options in the Content Properties( just above Rows and below Section there is a small grey box containing finger).
Now the Content Properties indeed increases the width of the column, but it also increase the width of the whole Pivot Table.
See...If i have a fixed number of columns in a PIVOT Table that do not change with prompt, then this solution work fine...
but the problem comes when the no of columns in pivot Table reduces based on the prompt selected.
In this case the less no of columns tries to occupy the whole width set in the content properties.
In short, with Content Properties the width of the PIVOT Table becomes fixed, irrespective of the no of columns coming.
Also after setting content properties, I am not able to print the report to PDF.
So the Question is... Can we increase the width of a Big Pivot Table whose no of columns keeps on changing based on the prompt....
Big pivot table -->
(ie table having no of columns which exceeds a single window frame and have to scroll to right to see the rest of the columns)
I hope i have not made things messy...
Thanks
AshishAshish,
Yes, you can set a fixed size for these. I'm sure you are fixing these because of PDF issue which might be irregular in sizes. Just play arnd with Custom CSS options. -
Custom sort pivot table columns with Essbase as the data source
Is it possible to sort columns in a pivot table according to an arbitrary value that I define when the data is coming from Essbase?
For example, say I have a dimension called Soda, with values Coke, Diet Coke, Dr. Pepper and Diet Dr. Pepper. I create a report with a sales measure with the measure labels on the rows and the Soda dimension on the column. By default the columns will be sorted alphabetically:
Coke Diet Coke Diet Dr. Pepper Dr. Pepper
Sales 1M .5M .75M 1.25M
I want to create a report that looks like this:
Coke Diet Coke Diet Dr. Pepper Dr. Pepper
Sales
I think I could do this if the source was relational just by creating bins or creating a custom column with a case statement that assigns each Soda an arbitrary value and then sort on this value. Everything I've tried with Essbase as the source, though, results in:
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 42043] An external aggregate is found in an outer query block. (HY000)
Any ideas?Hi,
1. You can try solve the 'An external aggregate is found in an outer query block' by changing aggregation rule for your measure both in physical and business layer.
By default it's set to Aggr_External - change it to Sum
In physical : Column properties->Aggregation rule
In business model : Column properties->Aggregation tab -> Default aggregation rule.
This may change the result - after changing check whether you still get correct values.
2. Also, in case the desired order is the same as the order of members in the Essbase cube, and you want to leave Aggr_External, you can create a calculated column that will help you with the sort.
See http://oraclebizint.wordpress.com/2008/04/28/oracle-bi-ee-101332-handling-sort-order-in-hyperion-essbase-931-evaluate-and-mdx/
Hope this helps,
Alex -
I use MS Excel 2007.
I want to keep the column fixed whenever I refresh data in pivot tables.
I tried even coding it with a macro:
Columns("B:F").Select
Columns("B:F").EntireColumn.AutoFit
And, in another time I tried columnwidth value to a fixed number; both doesnt work.
Please suggest a solution
Thanks in advance
Rafeek KBMHi Rafeek,
One solution is to set the column width after manually or programmatically refresh the PivotTable, for example:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim ws As Worksheet
Set ws = Application.ActiveWorkbook.ActiveSheet
ws.Columns("A").ColumnWidth = 10
End Sub
Another option is to set the column width, then protect the columns from been updated by the user, before refreshing the PivotTable, unprotect the worksheet. For example:
Public Sub LockColumnA()
Dim ws As Worksheet
Set ws = Application.ActiveWorkbook.ActiveSheet
ws.Columns("A").ColumnWidth = 10
ws.Columns("A").Locked = True
ws.Protect "123"
End Sub
Public Sub UnprotectWorksheet()
Dim ws As Worksheet
Set ws = Application.ActiveWorkbook.ActiveSheet
ws.Unprotect ("123")
End Sub
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. -
To display the column value though it is null
Hi all,
lineItems.ShipToCustomer.VName is having null in this case
When I execute this query I get zero records returned,the problem lies in lineItems.ShipToCustomer.VName :
select lineItems.ShipToCustomer.VName,C.VDealNumber CPRNumber, W.created SubmitDate, lineItems.VLineID LineItemNumber,lineItems.VProduct.Description Product from com.eastman.pricing.CprForm C,com.vendavo.platform.workflow.VWorkflow W where C.objectId=W.VWorkflowEntity.objectId and VID = 'CPR-013005'
When I execute after removing lineItems.ShipToCustomer.VName then the query returns one record:
select C.VDealNumber CPRNumber, W.created SubmitDate, lineItems.VLineID LineItemNumber,lineItems.VProduct.Description Product from com.eastman.pricing.CprForm C,com.vendavo.platform.workflow.VWorkflow W where C.objectId=W.VWorkflowEntity.objectId and VID = 'CPR-013005'
One more observation is when I include the column as lineItems.ShipToCustomer i.e after omitting only vname then I get one record returned.ShipToCustomer is a vector field.Anything to do with vector.
How do I get one row returned even though the lineItems.ShipToCustomer.VName is included in the query?
Thanks in advanceThis query is specific to the project i'm working it is called VQL which mostly follows the SQL standards that is why i'm not able to use nvl() which is not implemented in VQL....
The problem which i'm facing i have explained below:
lineItems.ShipToCustomer.VName is having null in this case
When I execute this query I get zero records returned,the problem lies in lineItems.ShipToCustomer.VName :
select lineItems.ShipToCustomer.VName,C.VDealNumber CPRNumber, W.created SubmitDate, lineItems.VLineID LineItemNumber,lineItems.VProduct.Description Product from com.eastman.pricing.CprForm C,com.vendavo.platform.workflow.VWorkflow W where C.objectId=W.VWorkflowEntity.objectId and VID = 'CPR-013005'
When I execute after removing lineItems.ShipToCustomer.VName then the query returns one record:
select C.VDealNumber CPRNumber, W.created SubmitDate, lineItems.VLineID LineItemNumber,lineItems.VProduct.Description Product from com.eastman.pricing.CprForm C,com.vendavo.platform.workflow.VWorkflow W where C.objectId=W.VWorkflowEntity.objectId and VID = 'CPR-013005'
One more observation is when I include the column as lineItems.ShipToCustomer i.e after omitting only vname then I get one record returned.ShipToCustomer is a vector field.Anything to do with vector.
How do I get one row returned even though the lineItems.ShipToCustomer.VName is included in the query? -
Need to change the column constrain from NOT NULL to NULL
Hi,
My requriment is I have to change the column constraint (NOT NULL) to NULLable (column having data), I used below query for that
alter table table_name modify transaction_cost2 default null
even command is successfull, but column constrain is still NOT NULL.
can you any one help on this.. ( steps to change column constain from not null to null)
Thanks,ALTER TABLE table_name
MODIFY( transaction_cost2 NUMBER NULL )That assumes that the data type of the TRANSACTION_COST2 column is NUMBER-- you'll want to use the current data type if it is something else. I'm hoping that the fact that you have a column named TRANSACTION_COST2 doesn't imply that you have an incorrectly normalized data model. But the name of the column certainly implies that you do.
Justin -
How to re-arrange the columns present in pivot table view in obiee 10?
Can you please tell me How to re-arrange the columns present in pivot table view in obiee 10?
I have columns as 1,2,3,4,6,7, in pivot table view.
I have calculated item (column 5 as summation of 1,2,3,4) and caluclated itme (column 9 as summation of 6,7)...now if i arrange ascending then calculated columns 5,9 don't get affected.
I need the order as 1,2,3,4,5,6,7,9 -
Return the column names for which the row values are not null.
Hi i m a new guy to db admin, and i need a sql script which should return column names of the particular table. and the returned column should have value (fyi - if the column has null value column name should not come in the sql o/p).
Exmple:
table name - A
s.no name mark status fee
1 aa 45 p null
2 bb 30 null paid
3 cc 35 p paid
fyi -1) if i give the table name(A) and s.no (2) the o/p should be -- name,mark.
2) if i give the tablename(A) and s.no (1) the o/p should be --- name,mark,status.
Thanks
Krishna.
Edited by: user13294228 on Jun 14, 2010 10:54 PMBTW,
The previous solution is for all values of the column, if you want a specific row, you can add it in where clause.
I mean in your example, it you look like:
SET serveroutput on;
DECLARE
l_cnt NUMBER;
l_str VARCHAR2 (255) := '';
l_table_name VARCHAR2 (255) := 'YOUR_TABLE_NAME';
l_col_cond VARCHAR2 (255) := 'S_NO';
l_val NUMBER := 1;
CURSOR c_col
IS
SELECT column_name
FROM user_tab_columns
WHERE table_name = l_table_name;
BEGIN
FOR i IN c_col
LOOP
EXECUTE IMMEDIATE 'SELECT COUNT ('
|| i.column_name
|| ') FROM '
|| l_table_name
|| ' WHERE '
|| l_col_cond
|| ' = '
|| l_val
INTO l_cnt;
l_str := l_str || CASE
WHEN l_cnt = 0
THEN ''
ELSE i.column_name
END || ',';
END LOOP;
l_str := SUBSTR (l_str, 1, LENGTH (l_str) - 1);
DBMS_OUTPUT.put_line (l_str);
END;Saad,
Edited by: S.Nayef on Jun 15, 2010 11:54 AM
Maybe you are looking for
-
A/R and A/P Invoice Draft - Post - Status Tracking
We post an A/R or A/P Invoice as an Draft Document using DI API, we do this for the convinience of the User to change the Tax components accordingly. Once this is done the draft document is posted as an Invoice and the draft document to be deleted. C
-
How to skip the job during 12.1.1 upgrade automatically
Hi All, We have completed our upgrade to R12.1.3 from 11.5.10.2 and during the upgrade process we have come across a worker failure for MSDOPDCODE.sql as below ERROR at line 1: ORA-33292: Insufficient permissions to access analytic workspace APPS.ODP
-
EM Client keeps saying "Unauthorized"...
I am having a problem getting my iCloud email and calendar to work with eM Client on my Windows 8.1 PC. I've followed these instructions, but I keep getting the "Server Says 'Unauthorized'." error. I went through all the configurations I could, and
-
Restore Preview default background?
Hello! Can you help me guys? How can I restore the default background in Preview? (10.7 Lion). I changed it to a color in the preferences but I can't change it back to the default texture... :S (that is here by the way: /System/Library/Frameworks/App
-
DPI and "Zoom" Setting Reset In Microsoft Office
I recently purchased a new laptop that comes with a 15.6" screen and 1920 x 1080 resolution. Native, it makes it very hard to read text. I was flipping back and forth between a variety of different DPI / zoom settings to find one that was a good fit.