Query Schema error adding columns for a query at workbench channel
Hello experts,
For our customer, we have created a custom query and it has been included into the query group Master Agreement List to be also used on the Master Agreement List Channel. However, when use tries to add columns, following error is raised:
Do you know if this issue can be fixed? Is there any system property controlling this property?
Thanks in advance and best regards,
Isaac
Hello Isaac,
Thank you for providing the additional details. Some of the saved changes to the advanced list page query is stored as XML data in the database, so as rightly pointed out by Bogdan it appears that you may have hit the limit especially when dealing with large number of columns. Since the limitation is
at the DB level our options for a solution will be limited as well. I’m following up with development team to see if there is a way to optimize the xml to make little bit more room or may be come up with an alternate approach. Either way it would require product code change. It would be helpful if you could open a message and add the details so we can track it.
Regards,
Vikram
Similar Messages
-
RPD - Cannot obtain number of columns for the query result :Working with MS SQL 2012 schema
Hi All,
I have created my warehouse in MS SQL 2012.
For management purpose, I have created different schemas in SQL database
In RPD, Physical layer, when i view data > I get error as
[nQSError:16002] Cannot obtain number of columns for the query result.
[nQSError:16001] ODBC error state : S0002 code : 208 message: [Microsoft][ODBC SQL Server Driver][SQL Server] Invalid object name 'tbl'..
[nQSError:16001] ODBC error state : S0002 code : 208 message: [Microsoft][ODBC SQL Server Driver][SQL Server] Statements could not be prepared..
I have already browsed : OBIEE 11g Strange ODBC Driver Error with SQL Server : Total Business Intelligence ... did not help me
please help!!!Hi All,
After all R&D it is been found that Oracle business administrator( RPD) needs default dbo schema. It doesn't accept custom schema for pulling data.
If anybody have other views please share.!!
Thank you -
OBIEE - ESSBASE ERROR - 1200467 - Error executing formula for [MDX query]
I have an issue on essbase with a query with 50 member filters.
The environment is OBIEE 11g over ESSBASE 11.1.2 with an ASO cube.
The user for essbase are with database access filters.
I have the following issue, OBIEE returns a query that filter 30 members and the query runs ok, but the same query with a 50 member filter returns the following error when i execute it on MAXL :
MAXL Error
ERROR - 1200467 - Error executing formula for [MDX query]: status code [1130203] in function [].
ERROR - 1241101 - Unexpected Essbase error 1200467.
i paste an example of the query that returns OBIEE
With
set [_Account2] as '{Distinct({[Account].[Allocated FTE - Budget]})}'
set [_Employee0] as '[Employee].members'
set [_Fund4] as 'Generate([Fund].Generations(2).members, Descendants([Fund].currentmember, [Fund].Generations(4), leaves))'
set [_Position4] as '{Distinct({[Position].[POS111165], [Position].[POS111166], [Position].[POS111167], [Position].[POS111540], [Position].[POS112331], [Position].[POS113201], [Position].[POS113247], [Position].[POS113248], [Position].[POS113540], [Position].[POS113618], [Position].[POS113954], [Position].[POS114109], [Position].[POS114194], [Position].[POS115224], [Position].[POS115912], [Position].[POS115913], [Position].[POS116727], [Position].[POS117229], [Position].[POS117491], [Position].[POS117587], [Position].[POS117610], [Position].[POS117979], [Position].[POS119456], [Position].[POS121262], [Position].[POS121458], [Position].[POS121698], [Position].[POS123368], [Position].[POS124027], [Position].[POS124028], [Position].[POS124110], [Position].[POS124396], [Position].[POS125623], [Position].[POS125624], [Position].[POS126476], [Position].[POS127960], [Position].[POS129352], [Position].[POS129468], [Position].[POS129494], [Position].[POS129535], [Position].[POS129608], [Position].[POS129679], [Position].[POS129730], [Position].[POS129905], [Position].[POS130010], [Position].[POS130144], [Position].[POS133456], [Position].[POS134943], [Position].[POS135231], [Position].[POS135404], [Position].[POS135734]})}'
set [_Program3] as 'Generate([Program].Generations(2).members, Descendants([Program].currentmember, [Program].Generations(3), leaves))'
select
{ [Budget Item]
} on columns,
NON EMPTY {crossjoin({[_Account2]},crossjoin({[_Employee0]},crossjoin({[_Fund4]},crossjoin({[_Position4]},{[_Program3]}))))} properties GEN_NUMBER, [Account].[MEMBER_UNIQUE_NAME], [Account].[Memnor], [Program].[MEMBER_UNIQUE_NAME], [Program].[Memnor], [Employee].[MEMBER_UNIQUE_NAME], [Employee].[Memnor], [Fund].[MEMBER_UNIQUE_NAME], [Fund].[Memnor], [Position].[MEMBER_UNIQUE_NAME], [Position].[Memnor] on rows
from [BCPSASO2.BCPS_ASO]
any suggestions ?
Thanks
Niko
Edited by: user8367101 on Mar 1, 2011 10:31 AMHere it is:
It is a Windows Server 2003 R2
Processor 8393 SE
31.9 GB of RAM
32-Bit
How does "memscaling" works?
I also think that are high but it is the way it was configured before I managed the application. For my DB
Index Cache setting: 205800
Index cache current value: 205800
Data file cache setting: 33768
Data file cache current: 0
Data Cache setting: 877273
Cata cache current: 71540
Block Size: 65408 -
Heading and color scheme of the columns for the detail report
Is it possible to have a heading and color scheme of the columns for the reports displayed on drill down of a query in WAD?
Try the stylesheet in the properties of web template.
-
SSRS query shows error no columns
this is the query command Text:
="select pallet_id, pallet_create_dm,pn_id from MATS_ITG.pwax_pen_link where pallet_id in ("& Join(Parameters!pallet_id.Value,",") &")"
when it querys it shows error
An error has occurred during report processing. (rsProcessingAborted)
Query execution failed for dataset 'DsPartial_lookup'. (rsErrorExecutingCommand)
ERROR [42703] ERROR 2624: Column "SGAC2207H0" does not exist
pallet_id is a multiple value ,SGAC2207H0 is just my data
can not figure out why, Please help meHi ,
Pallet_ID parameter seems to passing string like 'SGAC2207H0' . Check and change the parameter to pass numbers by checking the assignment to the value column in the parameter. If still need the string to be passed , Try the below expression
="select pallet_id, pallet_create_dm,pn_id from MATS_ITG.pwax_pen_link where pallet_id in ('"& Join(Parameters!pallet_id.Value,"','") &"')"
Best Regards Sorna -
Adding columns to content query
I have created a Content Query that retrieves all of my tasks from my site collection that meets my filter criteria. However, The Item Views are incredibly limited
(basically just the title). I want to add ~5-7 additional columns to the query, such as due date. I understand I may have to do this through SharePoint designer. Please advise and if coding is required, please let me know what code to use.Hi,
I understand that you want to add columns to content query web part.
To include additional columns in the Web Part's query, we need to perform some minor customization in the .webpart file. We should programmatically instruct the Web Part to rename columns to names the default XSLT transformation expects, and then render
the columns by using the default XSLT transformation styles. For more information:
http://msdn.microsoft.com/en-us/library/ms497457(v=office.14).aspx
But the default XSLT transformations can render the following four fields:
Title, Description, LinkUrl, and ImageUrl, we can add a column and display it as the
Description field in the Web Part. If we want the other columns to appear in addition to the KB title and product, modify the XSLT transformation and add the rendering for the additional columns.
More information:
How to: Customize the SharePoint Content By Query Web Part by Using Custom Properties (ECM):
http://msdn.microsoft.com/en-us/library/aa981241(v=office.14).aspx
How to: Customize XSL for the SharePoint Content By Query Web Part (ECM):
http://msdn.microsoft.com/en-us/library/bb447557(v=office.14).aspx
How to: Customize the Rendering of a Field on a List View:
http://msdn.microsoft.com/en-us/library/ff606773(v=office.14).aspx
Customizing List Views with XSLT Transformations:
http://msdn.microsoft.com/en-us/library/cc300164(v=office.12).aspx
Best Regards,
Linda Li -
Adding columns in a query.
Hello,
I have 12 columns(jan,feb,mar,apr,......dec) in budget table.
Budget table:
year jan feb mar apr may jun jul aug sep oct nov dec
2009 1 2
2010 3 5
2009 3 5 6
I need to add the values of jan,feb,..... in a query and the sum of the same year.
Output of the query for the above table for 2009 should return 1+2+3+5+6=17 and for 2010 3+5=8
Please help me in writing the query to achieve the above result.
Thank uSomething like this?
with t as
select '2009' Year, 1 Jan, 2 Feb, null Mar, null Apr, null May, null Jun, null Jul, null Aug, null Sep, null Oct, null Nov, null Dec from dual union all
select '2010' Year, null Jan, null Feb, 3 Mar, null Apr, 5 May, null Jun, null Jul, null Aug, null Sep, null Oct, null Nov, null Dec from dual union all
select '2009' Year, null Jan, null Feb, 3 Mar, null Apr, 5 May, 6 Jun, null Jul, null Aug, null Sep, null Oct, null Nov, null Dec from dual
select t.Year, sum(nvl(t.Jan,0)+nvl(t.Feb,0)+nvl(t.Mar,0)+nvl(t.Apr,0)+nvl(t.May,0)+nvl(t.Jun,0)+nvl(t.Jul,0)+nvl(t.Aug,0)+nvl(t.Sep,0)+nvl(t.Oct,0)+nvl(t.Nov,0)+nvl(t.Dec,0)) as Year_Sum
from t
group by t.Year
/ -
How to change the name of the column for dynamic query
I would like to change the name of the column name to bidderone, biddertwo and bidderthree. the only problem is the vendors name unknown when I run the query and sometimes the query returns two vendors. the maximum vendor is three. here is the query and please let me know how this can be done. thank you so much. I am using oracle 10i
FOR lv_rec IN ( SELECT vendor, calcbtot
FROM (SELECT t.*, ROW_NUMBER () OVER (ORDER BY t.calcbtot Asc) rn
FROM ( SELECT DISTINCT
s.vendor,
TO_CHAR (s.calcbtot, '999,999,999.00') calcbtot
FROM bidtabs b, bidders s
WHERE b.CALL = s.CALL
AND b.letting = s.letting
AND b.vendor = s.vendor
AND b.letting = v_letting
AND b.CALL = v_call
ORDER BY 2) t)
WHERE rn <= 3 )
LOOP
lv_sql :=
lv_sql || ', TO_CHAR(MAX(DECODE(TRIM(S.VENDOR),'''|| TRIM (lv_rec.vendor) || ''', S.BIDPRICE)), ''$999,999,999.00'') AS "'|| TRIM (lv_rec.vendor) ||'" ';
END LOOP;thank you so so much for your help on this. I am sorry i did not post the entire code. my intention is to use bidderone, biddertwo,bidderthree as a column name insead of the name of the vendors and also calcuate the average of the three vendors. the maximum vendor will be three but the minumum could be one or two. hope this is enought information to help me out further . thank you
CREATE OR REPLACE PROCEDURE biddersquoteforbridge (
p_spnumber IN VARCHAR2,
p_result OUT sys_refcursor
IS
v_letting VARCHAR2 (40);
v_call VARCHAR2 (40);
lv_sql VARCHAR2 (32767) := NULL;
BEGIN
SELECT DISTINCT L.LETTING, CALL
INTO v_letting, v_call
FROM LETPROP L, PROPOSAL P
WHERE L.LCONTID = P.CONTID AND CPROJNUM= p_spnumber;
lv_sql :=
'SELECT O.PRPITEM "Item Number",
INITCAP(FUNC_GET_ITEM_DESCRIPTION(O.PRPITEM)) "Description",
O.CONTID "Contract Id",O.SECTION "Section" , P.CPROJNUM "SP Number", P.CFACSSUP "District",
FUNCT_GET_SECTION_IDENTIFIER(O.SECTION, O.CONTID) "Section Title", ''Q''||(TO_CHAR(D.DATELET, ''Q-YYYY'')) "Quarter",
O.IPLINENO "Line Number", O.QTY "Quantity" ';
FOR lv_rec IN ( SELECT vendor, calcbtot
FROM (SELECT t.*, ROW_NUMBER () OVER (ORDER BY t.calcbtot Asc) rn
FROM ( SELECT DISTINCT
s.vendor,
TO_CHAR (s.calcbtot, '999,999,999.00') calcbtot
FROM bidtabs b, bidders s
WHERE b.CALL = s.CALL
AND b.letting = s.letting
AND b.vendor = s.vendor
AND b.letting = v_letting
AND b.CALL = v_call
ORDER BY 2) t)
WHERE rn <= 3 )
LOOP
lv_sql :=
lv_sql || ', TO_CHAR(MAX(DECODE(TRIM(S.VENDOR),'''|| TRIM (lv_rec.vendor) || ''', S.BIDPRICE)), ''$999,999,999.00'') AS "'|| TRIM (lv_rec.vendor) ||'" ';
END LOOP;
lv_sql :=
lv_sql
|| '
FROM PROPITEM O ,
PROPOSAL P ,
LETPROP L ,
BIDDERS B ,
BIDTABS S ,
BIDLET D
WHERE O.CONTID = P.CONTID
AND P.CONTID = L.LCONTID
AND L.CALL = B.CALL
AND L.LETTING = B.LETTING
AND B.CALL = S.CALL
AND B.LETTING = S.LETTING
AND B.VENDOR = S.VENDOR
AND S.IPLINENO = O.IPLINENO
AND L.LETTING = D.LETTING
AND O.LINEFLAG =''L''
AND L.LETTING = :B1
AND L.CALL = :B2
GROUP BY
O.CONTID,
O.SECTION,
O.IPLINENO,
O.PRPITEM,
O.QTY,
P.CPROJNUM,
P.CFACSSUP,
O.PRICE ,
D.DATELET
ORDER BY O.IPLINENO ';
-- DBMS_OUTPUT.put_line (lv_sql);
OPEN p_result FOR lv_sql USING v_letting, v_call;
END; -
Cfreport ("HTML format") missing columns for a query
Using Linux Fedora, ColdFusion 8 Developer Edition.
Problem:
The command:
<cfreport
format="HTML"
template="ReportTemplateHtml.cfr"
filename="Report.html"
overwrite="yes"
query=#structReport.query#
>
With Format equal to PDF or RTF, which is correct output:
"item" "Description" "Qty" "Unit Price" "Extension"
The HTML output writes the following columns:
"item" "" "" "Unit Price" "Extension"
The "Description" and "Qty" are missing.
Any ideas as to why data is missing from HTML report?
The html output for the table is as follows:
<tr valign="top">
<td style="width: 18px; height: 18px;"></td>
<td colspan="3" style="background-color: #EDE9C6;
border-top-style: solid; border-top-width: 1px; border-top-color:
#000000; padding-top: 1px; border-left-style: solid;
border-left-width: 1px; border-left-color: #000000; padding-left:
3px; border-bottom-style: solid; border-bottom-width: 1px;
border-bottom-color: #000000; padding-bottom: 1px;
border-right-style: solid; border-right-width: 1px;
border-right-color: #000000; padding-right: 3px; "><span
style="font-family: Helvetica; background-color: #EDE9C6;
font-size: 10.0pt; font-weight:
bold;">Item</span></td>
<td colspan="6" style="width: 273px; height:
18px;"></td>
<td colspan="3" style="background-color: #EDE9C6;
border-top-style: solid; border-top-width: 1px; border-top-color:
#000000; padding-top: 1px; border-left-style: solid;
border-left-width: 1px; border-left-color: #000000; padding-left:
3px; border-bottom-style: solid; border-bottom-width: 1px;
border-bottom-color: #000000; padding-bottom: 1px;
border-right-style: solid; border-right-width: 1px;
border-right-color: #000000; padding-right: 3px; "><span
style="font-family: Helvetica; background-color: #EDE9C6;
font-size: 10.0pt; font-weight: bold;">Unit
Price</span></td>
<td colspan="3" style="background-color: #EDE9C6;
border-top-style: solid; border-top-width: 1px; border-top-color:
#000000; padding-top: 1px; border-left-style: solid;
border-left-width: 1px; border-left-color: #000000; padding-left:
3px; border-bottom-style: solid; border-bottom-width: 1px;
border-bottom-color: #000000; padding-bottom: 1px;
border-right-style: solid; border-right-width: 1px;
border-right-color: #000000; padding-right: 3px; "><span
style="font-family: Helvetica; background-color: #EDE9C6;
font-size: 10.0pt; font-weight:
bold;">Extension</span></td>
<td style="width: 19px; height: 18px;"></td>
</tr>Query Builder is a crutch tool. Small, lightweight, but limited. It does not have every inline function you see in the SQL reference guide. If you need more, then you have to do more on your own.
-
Adding column values in query designer
Hi,
I have requirement to add value in query designer the values should look like this
Column A Column B
10 10
20 30
30 60
40 100
the first values of column B will be same as Column A 10. The second value of column B = column A 1st value +Column A second value similarly Third value of column B = 1st + 2nd + 3rd values of column a. So on and so forth
Any help will be highly appriciated.
Regards,
rayHi
Just create the formula and go to the properties of that formula and go to the calculattion tab and in the "CALCULATE SINGLE VALUE AS " select the option the additive ( not sure but once check that will perform additive operation plz once check it) and select the cumulative check box.
I think u can get it , because in one of my project i did that calculation.
Hope u got it,
Thanx & Regards,
RaviChandra -
Query Program ! use this for your query's like SQLPlus , copy-paste and run
H!
Like the Subject Title:
If you have PHP and Oracle then you can use this if you are learning the query's or you don't wanna use SQLPlus.
BTW this is my first script, but it works fine here.
//the code
<?//made by [email protected]
IF($_SERVER['REQUEST_METHOD'] == 'POST' AND isset($_POST['username']) AND isset($_POST['password'])) {
//gebruik het juiste dll bestand.
dl("php_oci8.dll");
define("USERNAME",$username);
define("PASSWORD",$password);
$conn = OCILogon(USERNAME,PASSWORD);
$sql = stripslashes($sql);
IF($btnRollback){
ocirollback($conn);
echo "Rollback done !";
IF($btnCommit){
ocicommit($conn);
echo "Committed !";
IF($btnVersion){
echo OCIServerVersion($conn);
IF($btnSql){
$stmt = OCIParse($conn,$sql);
IF(OCIExecute($stmt) === TRUE){
$msg = "The Query was oke !";
if (OCIStatementType($stmt) == "SELECT") {
$ncols = OCINumCols($stmt);
echo "<table width=\"100%\" border=\"1\" cellspacing=\"1\" cellpadding=\"0\" bordercolor=\"#FFFFFF\" bordercolorlight=\"#FFFFFF\" bordercolordark=\"#FFFFFF\">\n";
echo "<tr>\n";
for($i=1;$i<=$ncols;$i++){
$column_name[$i] = OCIColumnName($stmt,$i); //tabel kopjes
$column_type[$i] = OCIColumnType($stmt,$i); //extra info
$column_size[$i] = OCIColumnSize($stmt,$i); //extra info
echo "<td class=\"row\"><b>$column_name[$i]</b></td>\n";
echo "</tr>\n";
while(OCIFetch($stmt)){
echo "<tr>\n";
for($i=1;$i<=$ncols;$i++){
$column_value[$i] = OCIResult($stmt,$i);
echo "<td class=\"row\">$column_value[$i]</td>\n";
echo "</tr>\n";
//extra info
echo "<tr>\n";
for($i=1;$i<=$ncols;$i++){
echo "<td class=\"row\"><i>$column_type[$i] $column_size[$i]</i></td>\n";
echo "</tr>\n";
echo "</table>\n";
OCIFreeStatement($stmt);
OCILogoff($conn);
?>
<style type="text/css">
<!--
.row {
background-color: #EEEEEE;
border: #000000;
border-style: solid;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9pt;
-->
</style>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="submit">
<hr>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="37%">
<textarea name="sql" cols="60" rows="10"><?echo $sql;?></textarea>
</td>
<td width="63%" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="12%">Username:</td>
<td width="88%">
<input type="text" name="username" value="<?echo $username;?>">
</td>
</tr>
<tr>
<td width="12%">Password:</td>
<td width="88%">
<input type="password" name="password" value="<?echo $password;?>">
</td>
</tr>
<tr>
<td width="12%"> </td>
<td width="88%"> </td>
</tr>
<tr>
<td width="12%">
<input type="submit" name="btnSql" value="Sql">
</td>
<td width="88%">
<input type="submit" name="btnCommit" value="Commit">
<input type="submit" name="btnRollback" value="Rollback">
<input type="submit" name="btnVersion" value="Version">
</td>
</tr>
</table>
<?echo $msg;?> </td>
</tr>
</table>
<br>
<font face="Verdana, Arial, Helvetica, sans-serif" size="1">don't use ;</font>
</form>But your script is not outputing the result of the query. So how do we view the returned resultset.
-
Help for a query to add columns
Hi,
I need for a query where I should add each TableC value as an additional column.
Please suggest...
I have 3 tables (TableA, TableB, TableC). TableB stores TableA Id and TableC stores TableB Id
Considering Id of TableA.
Sample data
TableA :
ID NAME TABLENAME ETYPE
23 Name1 TABLE NAMEA Etype A
TableB :
ID A_ID RTYPE RNAME
26 23 RTYPEA RNAMEA
61 23 RTYPEB RNAMEB
TableC :
ID B_ID COMPNAME CONC
83 26 Comp Name AA 1.5
46 26 Comp Name BB 2.2
101 61 Comp Name CC 4.2
Scenario 1: AS PER ABOVE SAMPLE DATA Put each TableC value as an additional column.
For an Id in TableA(23) where TableB contains 2 records of A_ID (26, 61) and TableC contains 2 records for 26 and 1 record for 61.
Output required: Put each TABLEC value as an additional column
TableA.NAME TableA.ETYPE TableB.RTYPE TableC_1_COMPNAME TableC_1_CONC TableC_2_COMPNAME TableC_2_CONC
Name1 EtypeA RTypeA Comp Name AA 1.5 Comp Name BB 2.2 so on..
Name1 EtypeA RTypeB Comp Name CC 4.2 NULL NULL
Scenario 2: If Table C contains ONLY 1 row for each Id in TableB, output should be somewhat
Output:
TableA.NAME TableA.ETYPE TableB.RTYPE TableC_1_COMPNAME
TableC_1_CONCvalue value value value valueHi,
Welcome to the forum!
Do you want the data from TableC presented
(1) in one column, or
(2) in several columns (a different column of results for each row in the original TableC)?
(1) Is called String Aggregation and is easier than (2).
The best way to do this is with a user-defined aggregate function (STRAGG) which you can copy from asktom.
Ignoring TableA for now, you could get what you want by saying
SELECT b.rtype
, STRAGG ( c.compname
|| ' '
|| c.conc
) AS c_data
FROM TableB b
JOIN TableC c ON b.id = c.b_id
GROUP BY b.rtype;(2) Presenting N rows of TableC as it they were N columns of the same row is called a pivot. Search for "pivot" or "rows to columns" to find examples of how to do this.
The number of columns in a result set is hard-coded into the query. If you don't know ahead of time how many rows in TableC will match a row in TableB, you can:
(a) guess high (for example, hard-code 20 columns and let the ones that never contain a match be NULL) or,
(b) use Dynamic SQL to write a query for you, which has exactly as many columns as you need.
The two scripts below contain basic information on pivots.
This first script is similar to what you would do for case (a):
-- How to Pivot a Result Set (Display Rows as Columns)
-- For Oracle 10, and earlier
-- Actually, this works in any version of Oracle, but the
-- "SELECT ... PIVOT" feature introduced in Oracle 11
-- is better. (See Query 2, below.)
-- This example uses the scott.emp table.
-- Given a query that produces three rows for every department,
-- how can we show the same data in a query that has one row
-- per department, and three separate columns?
-- For example, the query below counts the number of employess
-- in each departent that have one of three given jobs:
PROMPT ========== 0. Simple COUNT ... GROUP BY ==========
SELECT deptno
, job
, COUNT (*) AS cnt
FROM scott.emp
WHERE job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY deptno
, job;
Output:
DEPTNO JOB CNT
20 CLERK 2
20 MANAGER 1
30 CLERK 1
30 MANAGER 1
10 CLERK 1
10 MANAGER 1
20 ANALYST 2
PROMPT ========== 1. Pivot ==========
SELECT deptno
, COUNT (CASE WHEN job = 'ANALYST' THEN 1 END) AS analyst_cnt
, COUNT (CASE WHEN job = 'CLERK' THEN 1 END) AS clerk_cnt
, COUNT (CASE WHEN job = 'MANAGER' THEN 1 END) AS manager_cnt
FROM scott.emp
WHERE job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY deptno;
-- Output:
DEPTNO ANALYST_CNT CLERK_CNT MANAGER_CNT
30 0 1 1
20 2 2 1
10 0 1 1
-- Explanation
(1) Decide what you want the output to look like.
(E.g. "I want a row for each department,
and columns for deptno, analyst_cnt, clerk_cnt and manager_cnt)
(2) Get a result set where every row identifies which row
and which column of the output will be affected.
In the example above, deptno identifies the row, and
job identifies the column.
Both deptno and job happened to be in the original table.
That is not always the case; sometimes you have to
compute new columns based on the original data.
(3) Use aggregate functions and CASE (or DECODE) to produce
the pivoted columns.
The CASE statement will pick
only the rows of raw data that belong in the column.
If each cell in the output corresponds to (at most)
one row of input, then you can use MIN or MAX as the
aggregate function.
If many rows of input can be reflected in a single cell
of output, then use SUM, COUNT, AVG, STRAGG, or some other
aggregate function.
GROUP BY the column that identifies rows.
PROMPT ========== 2. Oracle 11 PIVOT ==========
WITH e AS
( -- Begin sub-query e to SELECT columns for PIVOT
SELECT deptno
, job
FROM scott.emp
) -- End sub-query e to SELECT columns for PIVOT
SELECT *
FROM e
PIVOT ( COUNT (*)
FOR job IN ( 'ANALYST' AS analyst
, 'CLERK' AS clerk
, 'MANAGER' AS manager
NOTES ON ORACLE 11 PIVOT:
(1) You must use a sub-query to select the raw columns.
An in-line view (not shown) is an example of a sub-query.
(2) GROUP BY is implied for all columns not in the PIVOT clause.
(3) Column aliases are optional.
If "AS analyst" is omitted above, the column will be called 'ANALYST' (single-quotes included).
{code}
The second script, below, shows one way of doing a dynamic pivot in SQL*Plus:
{code}
How to Pivot a Table with a Dynamic Number of Columns
This works in any version of Oracle
The "SELECT ... PIVOT" feature introduced in Oracle 11
is much better for producing XML output.
Say you want to make a cross-tab output of
the scott.emp table.
Each row will represent a department.
There will be a separate column for each job.
Each cell will contain the number of employees in
a specific department having a specific job.
The exact same solution must work with any number
of departments and columns.
(Within reason: there's no guarantee this will work if you
want 2000 columns.)
Case 0 "Basic Pivot" shows how you might hard-code three
job types, which is exactly what you DON'T want to do.
Case 1 "Dynamic Pivot" shows how get the right results
dynamically, using SQL*Plus.
(This can be easily adapted to PL/SQL or other tools.)
PROMPT ========== 0. Basic Pivot ==========
SELECT deptno
, COUNT (CASE WHEN job = 'ANALYST' THEN 1 END) AS analyst_cnt
, COUNT (CASE WHEN job = 'CLERK' THEN 1 END) AS clerk_cnt
, COUNT (CASE WHEN job = 'MANAGER' THEN 1 END) AS manager_cnt
FROM scott.emp
WHERE job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY deptno
ORDER BY deptno
PROMPT ========== 1. Dynamic Pivot ==========
-- ***** Start of dynamic_pivot.sql *****
-- Suppress SQL*Plus features that interfere with raw output
SET FEEDBACK OFF
SET PAGESIZE 0
SPOOL p:\sql\cookbook\dynamic_pivot_subscript.sql
SELECT DISTINCT
', COUNT (CASE WHEN job = '''
|| job
|| ''' ' AS txt1
, 'THEN 1 END) AS '
|| job
|| '_CNT' AS txt2
FROM scott.emp
ORDER BY txt1;
SPOOL OFF
-- Restore SQL*Plus features suppressed earlier
SET FEEDBACK ON
SET PAGESIZE 50
SPOOL p:\sql\cookbook\dynamic_pivot.lst
SELECT deptno
@@dynamic_pivot_subscript
FROM scott.emp
GROUP BY deptno
ORDER BY deptno
SPOOL OFF
-- ***** End of dynamic_pivot.sql *****
EXPLANATION:
The basic pivot assumes you know the number of distinct jobs,
and the name of each one. If you do, then writing a pivot query
is simply a matter of writing the correct number of ", COUNT ... AS ..."\
lines, with the name entered in two places on each one. That is easily
done by a preliminary query, which uses SPOOL to write a sub-script
(called dynamic_pivot_subscript.sql in this example).
The main script invokes this sub-script at the proper point.
In practice, .SQL scripts usually contain one or more complete
statements, but there's nothing that says they have to.
This one contains just a fragment from the middle of a SELECT statement.
Before creating the sub-script, turn off SQL*Plus features that are
designed to help humans read the output (such as headings and
feedback messages like "7 rows selected.", since we do not want these
to appear in the sub-script.
Turn these features on again before running the main query.
{code} -
Count number of colums for that query.
Hi all,
I need to return the number of columns for that query, the columns are not known...dynamic columns.
i.e
1) Example 1
select column1, column2
from dual;
Result should return counter = 2
2) Example 2:
select column1, column2,column3,column4, column5
from dual;
Result should return counter = 5
from dual;
Result should return counter = 2
Thanks.qwestion wrote:
I need to return the number of columns for that query, the columns are not known...dynamic columns.For this you'll need to use the DBMS_SQL package:
e.g.
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE procedure query_col_count(p_sql IN VARCHAR2) IS
2 c NUMBER;
3 rec_tab DBMS_SQL.DESC_TAB;
4 col_cnt INTEGER;
5 BEGIN
6 c := DBMS_SQL.OPEN_CURSOR;
7 DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
8 DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
9 DBMS_SQL.CLOSE_CURSOR(c);
10 DBMS_OUTPUT.PUT_LINE('Number of columns: '||col_cnt);
11* END;
SQL> /
Procedure created.
SQL> exec query_col_count('select empno, ename from emp');
Number of columns: 2
PL/SQL procedure successfully completed.
SQL> exec query_col_count('select * from emp');
Number of columns: 8
PL/SQL procedure successfully completed.
SQL> -
Hello all,
Can I benefit a little from your experience with SAP Query(ABAP) and Adhoc Query(ABAP)?
My customer want to use both SAP Query and Adhoc Query.
And they want to separate for SAP Query as preset report program and Adhoc Query as general-purpose reporting tool.
And I want to know how to separate authorizations of SAP Query and Adhoc Query as below.
As for SAP Query, users can only execute and cannnot change or delete it.
As for Adhoc Query, users can save Queries they created or changed in Adhoc Query.
I know there is only one authorization object for SAP Query:S_QUERY
Is there any solution for that kind of request?
Thanks and Regards,
HanaeHello,
We have check in the abap program ask you functional to give the authorization object i.e. y_k_autchk
and ask him for which filed we have to give authorizaion.
AUTHORITY-CHECK OBJECT y_k_autchk
ID 'WERKS' FIELD y_wa_tvarv-low. -
Newly added column not displayed in Interactive report
Hello,
I have a tableA with 3 columns.In the application i am displaying as Form with Report region as Interactive report(Oracle 10g Application Express 3.2).
I added one column to tableA.Now when i am refreshing the report by adding that column in the select query,the new added column is not displayed in the application.
How can i do this so that the added column can be displayed.I dont want to delete the whole thing and redo it again.
Thanks
SiyaHi Siya,
The Interactive Report will not show you the newly added columns by default. You have to select those columns from the actions menu and when all the required fields are displayed then save it as the default report.
Then you will be able to see all the columns.
Hope this solves your problem.
Thanks,
Satish.
Maybe you are looking for
-
I can no longer open any attachments that are sent to me. I click on and get cannot preview (but have had this for ages). I am clicking on download and nothing happens. It does not download. I clicked to install a new version after updating and click
-
Problem with gmail not working with apple mail..
Hi, i'm trying to set up a gmail account to the apple mail program on mac (still works in iphone and ipad). after many diffrent approaches, i think i have all the right setnings. But i still cant connect to the google IMAP, both with or without SSL.
-
What function to set coordinate system in 6i with API?
#define D2FP_COORD_SYS 72 here's the define that relates to what i want to do. what are the names of the functions that set/get the coordinate system. (i want to set it to character and change the default units) thanks, [email protected]
-
I'm trying to write a report that selects data from two schemas in two different HTMLDB tablespaces (or workspaces). How do I gain access from one workspace to the other? I've tried dblink and grants, but I'm unable to see users from one workspace to
-
Hi Experts, We have the Special user id specifically created to receive emails. The requirement is to send Notification mail to the emails received after few verifications. We have assigned the Z class in SO50 for this recipient address. And this Z