SQL query problem with sorting
Hi,
I have question regarding sql query . Right now I am getting the results like this if i use this sql query
select ID,Name,Desc,Priority from emp order by Priority ;
Priority is varchar field. I don't want to change the Priority field and cannot add a new column in the table. Because i don't have permission to do that.
ID Name Desc Priority
=============================================
234 paul paul desc Highest
3452 mike mike desc High
4342 smith smith desc Low
6565 kelly kelly desc Low
9878 nate nate desc Medium
3223 deb deb desc High
============================================
I need a query to get the results like that.
ID Name Desc Priority
=============================================
234 paul paul desc Highest
3452 mike mike desc High
3223 deb deb desc High
9878 nate nate desc Medium
4342 smith smith desc Low
6565 kelly kelly desc Low
============================================
If any one knows about this one, please let me know.
Thanks,
Bala
You are aware that there are differences in the SQL implementation between Sqlserver and Oracle? You could try something like this, if there's a INSTR function:
ORDER BY INSTR('Highest,High,Medium,Low,', Priority || ',')You may have to change the "Priority || ," to a "Priority + ','), if string concatenation is done differently in sqlserver. Don't know about the ('), maybe you need (").
C.
Similar Messages
-
ORA-06502 on 'SQL query' report with sort in 'Report Attributes'
Hi All,
We get the next error if we set sorting on a column in a 'Report' based on a 'SQL query'. Removing the sort, error disappeares:
failed to parse SQL query:
ORA-06502: PL/SQL: numeric or value error: NULL index table key value
Any suggestions?
ErikErik,
Thanks, this explains it. By specifying the request as part of your URL you run into the recently uncovered issue. The request you're setting is REMFROMLIST and ADD2LIST. You probably either have links that include those requests or you have branches where you specify them. Either way, in order to get reports sorting to work, you'll have to make sure that the request strings are not part of your URL. This is a work-around and the upcoming HTML DB patch release will solve this issue.
One way of avoiding this is to have computations on the previous pages that set a napplication level or page level item to the REMFROMLIST and ADD2LIST values and then you can use those items for your conditions that are currently evaluating those strings.
Hope this helps and sorry for the inconvenience,
Marc -
SQL Query problems with Mysql - possible Java bug
I have a query that works fine on mysql, but does not work in my jsp page.... my db connection and all that jazz is fine.
select somefields from table order by (integerfield / doublefield)
two notes... the query works without the order by. And the query works with the order by when I'm working directly with the db. Any ideas? This is driving me nuts!!!!
Thanks,
TysonNevermind, just a dumb mistake... finally figured it out.
-
SELECT query - problem with SORT
Hi,
Same select query behaves different way on development and quality server
on Development it returns unsorted and Quality returns sorted
it can be resolved by SORT but why does it behave differently
Do you know what is setting in database
thanksFrom F1 on SELECT:
Orders the records in a SELECT statement. Without the ORDER-BY clause, the order
in which the selected lines are supplied is undefined. This means that two similar SELECT
statements may produce lines in a different order.
Rob -
Problem with sorting involving user defined types and reports
Hello!
I have a problem with sorting involving Reports and user defined objet types.
I have created the following object types
CREATE TYPE type_balance_compte AS OBJECT
NUM_CPT_SEQ NUMBER(8)
,NUM_CPT VARCHAR2(35)
CREATE TYPE TB_type_balance_compte IS TABLE OF type_balance_compte
At the reports query I use:
SELECT ...
FROM table(cast(test_pkg.balance_comptes(:P_num_soc) as TB_type_balance_compte)) c
The procedure balance_comptes will retrieve data from various tables into the type.
The report is ordered by a certain string field that usually contains characters and numbers.
I need to have numbers always before characters, meaning the data should come in this order in the report for example:
0
1
A
B
So, before the report query, I have placed a call to DBMS_SESSION.SET_NLS( 'nls_sort', 'binary' ) to guarantee NLS_SORT in case it is originally set to FRENCH.
The problem here is that even after this call, I have the report ordered like this
A
B
0
1
And not the numbers before as it should be.
To try and find out where the problem was, I have created a table to use instead of the object type described above. In this case, it worked correctly. So all I know by now is that is has something to do with the type or cast, but what exactly? Does anybody now how to solve this without using a table?
Many thanks
AriadneI have placed a call to DBMS_SESSION.SET_NLS( 'nls_sort', 'binary' ) why not order directly then:
SQL> select *
from table (sys.dbms_debug_vc2coll ('A', 1, '5', 'C', 'a'))
order by nlssort (column_value, 'NLS_SORT = binary')
COLUMN_VALUE
1
5
A
C
a
5 rows selected.? -
How to numberformat when using sql:query alogn with c:forEach JSTL tags
Is there anyway to format the numeric values returned from the database when using <sql:query> alogn with <c:forEach> tags
Here is my jsp code
<sql:query..../>
<c:forEach var="row" items="${queryResults.rows}">
<tr>
<td><c:out value="${row.COL1}" /></td>
<td><c:out value="${row.COL2}" /></td>
</tr>
</c:forEach>
Col1 values are numeric without any formats Eg: 1000, 10000, 1000000 etc.
how can i format them to 1,000 , 10,1000 , 100,000 etcIt is polite to mention what your answer was. These posts are not just here for you to ask questions, but to be used as a resource for other people to find answers. Saying "I solved it" with no details helps noone.
I presume you discovered the JSTL <fmt:formatNumber> tag? -
Problem in executeQuery(SQL query sentence with a ' );
for example:
String strName="";
//here strName is searching key value.
String strQueryString="SELECT * FROM Authors WHERE name='" strName "'";
ResultSet rs=st.executeQuery(strQueryString);
if strName value is "yijun_lee",that will return all information which the name columns value is "yijun_lee" with SQL Query sentence SELECT * FROM Authors WHERE name='yijun_lee'
but if strName value is "yijun ' lee",that value contains a '.that will error!
how to do?
thanks very much!You could parse <strName > and insert another ' for each '
A concrete example would be SELECT * FROM Authors WHERE name='yijun '' lee'HTH -
SQL Query Result with Random Sorting
Hi Experts,
My Oracle Version : Oracle9i
I have three tables which are given below,
Table Name: check_team
team_id team_code
100 A
101 B
102 C
103 D
Table Name: check_product
product_id product_code
1 XXX
2 XYZ
Table Name: check_team_products
tprod_id tprod_team_id tprod_product_id
1 100 1
2 100 2
3 101 1
4 101 2
5 102 1
6 102 2
7 103 1
8 103 2
Required Output First Time:
team_id team_code product_id product_code
100 A 1 XXX
101 B 2 XYZ
102 A 1 XXX
103 B 2 XYZ
Required Output Second Time:
team_id team_code product_id product_code
100 B 2 XYZ
101 A 1 XXX
102 B 2 XYZ
103 A 1 XXXI need the result as Required Output specified above and also the result has to be random too.. Can someone help me in writing a SQL Query to get results as that?
Added Oracle VersionSo, is it something like this you want?
SQL> ed
Wrote file afiedt.buf
1 with check_team as (select 100 as team_id, 'A' as team_code from dual union all
2 select 101, 'B' from dual union all
3 select 102, 'C' from dual union all
4 select 103, 'D' from dual)
5 ,check_product as (select 1 as product_id, 'XXX' as product_code from dual union all
6 select 2, 'XYZ' from dual)
7 ,check_team_products as (select 1 as tprod_id, 100 as tprod_team_id, 1 as tprod_product_id from dual union all
8 select 2, 100, 2 from dual union all
9 select 3, 101, 1 from dual union all
10 select 4, 101, 2 from dual union all
11 select 5, 102, 1 from dual union all
12 select 6, 102, 2 from dual union all
13 select 7, 103, 1 from dual union all
14 select 8, 103, 2 from dual)
15 --
16 -- end of test data
17 --
18 select team_id, team_code, product_id, product_code
19 from (
20 select t.team_id, t.team_code, p.product_id, p.product_code
21 ,row_number() over (partition by team_id order by dbms_random.random()) as rn
22 from check_team t join check_team_products tp on (tp.tprod_team_id = t.team_id)
23 join check_product p on (p.product_id = tp.tprod_product_id)
24 )
25* where rn = 1
SQL> /
TEAM_ID T PRODUCT_ID PRO
100 A 2 XYZ
101 B 1 XXX
102 C 2 XYZ
103 D 1 XXX
SQL> /
TEAM_ID T PRODUCT_ID PRO
100 A 2 XYZ
101 B 1 XXX
102 C 2 XYZ
103 D 1 XXX
SQL> /
TEAM_ID T PRODUCT_ID PRO
100 A 1 XXX
101 B 2 XYZ
102 C 1 XXX
103 D 1 XXX -
SQL query problem - select max (case... aggregate function)
Hi,
I have a problem with below sql query, it gives me problem/error message 'ORA-00937: not a single-group group function', why?
select sag.afdeling, sag.sagsnr, to_char(sag.start_dato, 'yyyy-mm-dd'), sag.stat, BOGF_TRANS.TRANSTYPE,
max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
from sag
join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
If I exclude (columns) as below it give me correct summations (max (case... sum(...)) but then I miss some important info that I need
select
max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
from sag
join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
Any ideas?Moved to more sutable forum, sorry.
-
A challenging dynamic SQL query problem
hi All,
I have a very interesting problem at work:
We have this particular table defined as follows :
CREATE TABLE sales_data (
sales_id NUMBER,
sales_m01 NUMBER,
sales_m02 NUMBER,
sales_m03 NUMBER,
sales_m04 NUMBER,
sales_m05 NUMBER,
sales_m06 NUMBER,
sales_m07 NUMBER,
sales_m08 NUMBER,
sales_m09 NUMBER,
sales_m10 NUMBER,
sales_m11 NUMBER,
sales_m12 NUMBER,
sales_prior_yr NUMBER );
The columns 'sales_m01 ..... sales_m12' represents aggregated monthly sales, in which 'sales_m01' translates to 'sales for the month of january, january being the first month, 'sales_m02' sales for the month of february, and so on.
The problem I face is that we have a project which requires that a parameter be passed to a stored procedure which stands for the month number which is then used to build a SQL query with the following required field aggregations, which depends on the parameter passed :
Sample 1 : parameter input: 4
Dynamically-built SQL query should be :
SELECT
SUM(sales_m04) as CURRENT_SALES,
SUM(sales_m01+sales_m02+sales_m03+sales_m04) SALES_YTD
FROM
sales_data
WHERE
sales_id = '0599768';
Sample 2 : parameter input: 8
Dynamically-built SQL query should be :
SELECT
SUM(sales_m08) as CURRENT_SALES,
SUM(sales_m01+sales_m02+sales_m03+sales_m04+
sales_m05+sales_m06+sales_m07+sales_m08) SALES_YTD
FROM
sales_data
WHERE
sales_id = '0599768';
So in a sense, the contents of SUM(sales_m01 ....n) would vary depending on the parameter passed, which should be a number between 1 .. 12 which corresponds to a month, which in turn corresponds to an actual field range on the table itself. The resulting dynamic query should only aggregate those columns/fields in the table which falls within the range given by the input parameter and disregards all the remaining columns/fields.
Any solution is greatly appreciated.
Thanks.Hi another simpler approach is using decode
try like this
SQL> CREATE TABLE sales_data (
2 sales_id NUMBER,
3 sales_m01 NUMBER,
4 sales_m02 NUMBER,
5 sales_m03 NUMBER,
6 sales_m04 NUMBER,
7 sales_m05 NUMBER,
8 sales_m06 NUMBER,
9 sales_m07 NUMBER,
10 sales_m08 NUMBER,
11 sales_m09 NUMBER,
12 sales_m10 NUMBER,
13 sales_m11 NUMBER,
14 sales_m12 NUMBER,
15 sales_prior_yr NUMBER );
Table created.
SQL> select * from sales_data;
SALES_ID SALES_M01 SALES_M02 SALES_M03 SALES_M04 SALES_M05 SALES_M06 SALES_M07 SALES_M08 SALES_M09 SALES_M10 SALES_M11 SALES_M12 SALES_PRIOR_YR
1 124 123 145 146 124 126 178 189 456 235 234 789 19878
2 124 123 145 146 124 126 178 189 456 235 234 789 19878
1 100 200 300 400 500 150 250 350 450 550 600 700 10000
1 101 201 301 401 501 151 251 351 451 551 601 701 10000----now for your requirement. see below query if there is some problem then tell.
SQL> SELECT sum(sales_m&input_data), DECODE (&input_data,
2 1, SUM (sales_m01),
3 2, SUM (sales_m01 + sales_m02),
4 3, SUM (sales_m01 + sales_m02 + sales_m03),
5 4, SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04),
6 5, SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04 + sales_m05),
7 6, SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04+sales_m05+sales_m06),
8 7, SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04+sales_m05+sales_m06+sales_m07),
9 8, SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04+sales_m05+sales_m06+sales_m07+sales_m08),
10 9, SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04+sales_m05+sales_m06+sales_m07+sales_m08+sales_m09),
11 10,SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04+sales_m05+sales_m06+sales_m07+sales_m08+sales_m09+sales_m10),
12 11,SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04+sales_m05+sales_m06+sales_m07+sales_m08+sales_m09+sales_m10+sales_m11),
13 12,SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04+sales_m05+sales_m06+sales_m07+sales_m08+sales_m09+sales_m10+sales_m11+sales_m12)
14 ) total
15 FROM sales_data
16 WHERE sales_id = 1;
Enter value for input_data: 08
Enter value for input_data: 08
old 1: SELECT sum(sales_m&input_data), DECODE (&input_data,
new 1: SELECT sum(sales_m08), DECODE (08,
SUM(SALES_M08) TOTAL
890 5663 -
PL/SQL function body returning SQL Query Problem
I have wandered around the forums and found quite a bit of helpful information that has gotten me to the point I am now at. Unfortuntely, PL/SQL is not my strongest point and I am getting an error when I attempt to run my report.
This is what I have for my package:
CREATE OR REPLACE PACKAGE LIB2.report_query
is
function create_report2(v1 IN varchar2) RETURN VARCHAR2;
end report_query;
CREATE OR REPLACE PACKAGE BODY LIB2.report_query
as
function create_report2(v1 in varchar2) return varchar2
is
l_vc_format HTMLDB_APPLICATION_GLOBAL.VC_ARR2 := HTMLDB_UTIL.STRING_TO_TABLE(v1);
l_format varchar2(255) := HTMLDB_UTIL.TABLE_TO_STRING(l_vc_format);
q1 varchar2(32767) := ' ';
begin
q1 :=
'select b.BOOK_ID, bk.book_id bkid, bkk.book_id bkkid, b.TITLE, b.SUBTITLE, b.SERIES, b.VOLUME, b.ISBN, f.FORMAT_RET, b.DESCRIPTION, .PUBLISHED,'
||'b.PURCHASED_FROM, b.COMMENTS, b.WEBSITE, c.LENGTH_MINS, stragg(p.last_name || '', '' || p.first_name) Author, '
||'stragg(p.person_id) person_id, '
||'pb.name PUBLISHER, decode(b.abridged, ''Y'',''Abridged'',''N'',''Unabridged'') Abridged,'
||'(nvl(d.disk01,0)+nvl(d.disk02,0)+nvl(d.disk03,0)+nvl(d.disk04,0)+nvl(d.disk05,0)+nvl(d.disk06,0)+nvl(d.disk07,0)+nvl(d.disk08,0)+'
||'nvl(d.disk09,0)+nvl(d.disk10,0)+nvl(d.disk11,0)+nvl(d.disk12,0)+nvl(d.disk13,0)+nvl(d.disk14,0)+nvl(d.disk15,0)+nvl(d.disk16,0)+nvl(d.disk17,0)+'
||'nvl(d.disk18,0)+nvl(d.disk19,0)+nvl(d.disk20,0)+nvl(d.disk21,0)+nvl(d.disk22,0)+nvl(d.disk23,0)+nvl(d.disk24,0)+nvl(d.disk25,0)+nvl(d.disk26,0)+'
||'nvl(d.disk27,0)+nvl(d.disk28,0)+nvl(d.disk29,0)+nvl(d.disk30,0)+nvl(d.disk31,0)+nvl(d.disk32,0)+nvl(d.disk33,0)+nvl(d.disk34,0)+nvl(d.disk35,0)+'
||'nvl(d.disk36,0)+nvl(d.disk37,0)+nvl(d.disk38,0)+nvl(d.disk39,0)+nvl(d.disk40,0)+nvl(d.disk41,0)+nvl(d.disk42,0)+nvl(d.disk43,0)+nvl(d.disk44,0)+'
||'nvl(d.disk45,0)+nvl(d.disk46,0)+nvl(d.disk47,0)+nvl(d.disk48,0)+nvl(d.disk49,0)+nvl(d.disk50,0)) total_tracks'
||'from book b, '
||'book bk,'
||'book bkk,'
||'person p,'
||'lkup_book_author la,'
||'lkup_book_publisher lp,'
||'lkup_book_format lkf,'
||'format f,'
||'publisher pb,'
||'conversion_info_audio c,'
||'lkup_book_disk_info d'
||'where b.book_id = la.book_id'
||'and b.book_id = bk.book_id'
||'and b.book_id = bkk.book_id'
||'and p.person_id = la.author_id'
||'and b.book_id = lp.book_id'
||'and b.book_id = c.book_id'
||'and b.book_id = d.book_id'
||'and b.book_id = lkf.book_id'
||'and lkf.format_id = f.format_id'
||'and pb.publisher_id(+) = lp.publisher_id'
||'and b.wishlist = ''N'''
||'and (upper(b.book_id) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(b.title) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(b.subtitle) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(b.series) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(b.volume) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(b.isbn) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(b.format) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(b.description) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(b.published) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(b.purchased_from) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(b.comments) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(b.website) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(p.last_name) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(p.first_name) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(pb.name) like ''%'' || upper(:P40_SEARCH) || ''%'''
||'or upper(:P40_SEARCH) is null)'
||'and ((upper(b.title) like ''%'' || upper(:P40_TITLE) || ''%'' or upper(:P40_TITLE) is null))'
||'and ((upper(b.series) like ''%'' || upper(:P40_SERIES) || ''%'' or upper(:P40_SERIES) is null))'
||'and ((upper(p.last_name) like ''%'' || upper(:P40_LASTNAME) || ''%'' or upper(:P40_LASTNAME) is null))'
||'and ((upper(p.first_name) like ''%'' || upper(:P40_FIRSTNAME) || ''%'' or upper(:P40_FIRSTNAME) is null))'
||'and ((upper(f.format_ret) in (upper(l_vc_format)) or upper(:P40_FORMAT) is null))'
||'group by b.BOOK_ID, bk.book_id, bkk.book_id, b.TITLE, b.SUBTITLE, b.SERIES, b.VOLUME, b.ISBN, f.FORMAT_ret, b.DESCRIPTION, '
||'b.PUBLISHED, b.PURCHASED_FROM, b.COMMENTS, b.WEBSITE, c.LENGTH_MINS, pb.name, b.abridged, '
||'(nvl(d.disk01,0)+nvl(d.disk02,0)+nvl(d.disk03,0)+nvl(d.disk04,0)+nvl(d.disk05,0)+nvl(d.disk06,0)+nvl(d.disk07,0)+nvl(d.disk08,0)+'
||'nvl(d.disk09,0)+nvl(d.disk10,0)+nvl(d.disk11,0)+nvl(d.disk12,0)+nvl(d.disk13,0)+nvl(d.disk14,0)+nvl(d.disk15,0)+nvl(d.disk16,0)+nvl(d.disk17,0)+'
||'nvl(d.disk18,0)+nvl(d.disk19,0)+nvl(d.disk20,0)+nvl(d.disk21,0)+nvl(d.disk22,0)+nvl(d.disk23,0)+nvl(d.disk24,0)+nvl(d.disk25,0)+nvl(d.disk26,0)+'
||'nvl(d.disk27,0)+nvl(d.disk28,0)+nvl(d.disk29,0)+nvl(d.disk30,0)+nvl(d.disk31,0)+nvl(d.disk32,0)+nvl(d.disk33,0)+nvl(d.disk34,0)+nvl(d.disk35,0)+'
||'nvl(d.disk36,0)+nvl(d.disk37,0)+nvl(d.disk38,0)+nvl(d.disk39,0)+nvl(d.disk40,0)+nvl(d.disk41,0)+nvl(d.disk42,0)+nvl(d.disk43,0)+nvl(d.disk44,0)+'
||'nvl(d.disk45,0)+nvl(d.disk46,0)+nvl(d.disk47,0)+nvl(d.disk48,0)+nvl(d.disk49,0)+nvl(d.disk50,0))';
RETURN q1;
EXCEPTION
WHEN OTHERS THEN
RETURN q1;
end create_report2;
end;
And here is what I have for my Region Source on my report:
return lib2.report_query.create_report2(v('P40_FORMAT'));
Here is my error when I run the page:
failed to parse SQL query:
ORA-00936: missing expression
I have tried the region source line in many variations, this is just my latest one. None of them have worked. I am quite obviously missing something quite important and probably extremely silly. Any ideas?
Thanks!
ChrissyChrissy,
This is what the package returns as a query:
select b.BOOK_ID, bk.book_id bkid, bkk.book_id bkkid,
b.TITLE, b.SUBTITLE, b.SERIES, b.VOLUME, b.ISBN, f.FORMAT_RET,
b.DESCRIPTION, .PUBLISHED,b.PURCHASED_FROM, b.COMMENTS, b.WEBSITE,
c.LENGTH_MINS, stragg(p.last_name || ', ' || p.first_name) Author,
stragg(p.person_id) person_id, pb.name PUBLISHER, decode(b.abridged,
'Y','Abridged','N','Unabridged') Abridged,
(nvl(d.disk01,0)+nvl(d.disk02,0)+nvl(d.disk03,0)+nvl(d.disk04,0)+nvl(d.disk05,0)
nvl(d.disk06,0)nvl(d.disk07,0)+nvl(d.disk08,0)+nvl(d.disk09,0)+nvl(d.disk10,0)
nvl(d.disk11,0)nvl(d.disk12,0)+nvl(d.disk13,0)+nvl(d.disk14,0)+nvl(d.disk15,0)
nvl(d.disk16,0)nvl(d.disk17,0)+nvl(d.disk18,0)+nvl(d.disk19,0)+nvl(d.disk20,0)
nvl(d.disk21,0)nvl(d.disk22,0)+nvl(d.disk23,0)+nvl(d.disk24,0)+nvl(d.disk25,0)
nvl(d.disk26,0)nvl(d.disk27,0)+nvl(d.disk28,0)+nvl(d.disk29,0)+nvl(d.disk30,0)
nvl(d.disk31,0)nvl(d.disk32,0)+nvl(d.disk33,0)+nvl(d.disk34,0)+nvl(d.disk35,0)
nvl(d.disk36,0)nvl(d.disk37,0)+nvl(d.disk38,0)+nvl(d.disk39,0)+nvl(d.disk40,0)
nvl(d.disk41,0)nvl(d.disk42,0)+nvl(d.disk43,0)+nvl(d.disk44,0)+nvl(d.disk45,0)
nvl(d.disk46,0)nvl(d.disk47,0)+nvl(d.disk48,0)+nvl(d.disk49,0)+nvl(d.disk50,0)) total_tracksfrom book b,
book bk,book bkk,person p,lkup_book_author la,lkup_book_publisher lp,
lkup_book_format lkf,format f,publisher pb,conversion_info_audio c,
lkup_book_disk_info dwhere b.book_id = la.book_idand b.book_id = bk.book_idand b.book_id = bkk.book_idand p.person_id = la.author_idand
b.book_id = lp.book_idand b.book_id = c.book_idand b.book_id = d.book_idand
b.book_id = lkf.book_idand lkf.format_id = f.format_idand pb.publisher_id(+) = lp.publisher_idand
b.wishlist = 'N'and (upper(b.book_id) like '%' || upper(:P40_SEARCH) || '%'
or upper(b.title) like '%' || upper(:P40_SEARCH) || '%'or upper(b.subtitle) like '%' ||
upper(:P40_SEARCH) || '%'or upper(b.series) like '%' || upper(:P40_SEARCH) || '%'or
upper(b.volume) like '%' || upper(:P40_SEARCH) || '%'or upper(b.isbn) like '%' ||
upper(:P40_SEARCH) || '%'or upper(b.format) like '%' || upper(:P40_SEARCH) || '%'or upper(b.description) like '%' || upper(:P40_SEARCH) || '%'or upper(b.published)
like '%' || upper(:P40_SEARCH) || '%'or upper(b.purchased_from) like '%' ||
upper(:P40_SEARCH) || '%'or upper(b.comments) like '%' || upper(:P40_SEARCH)
|| '%'or upper(b.website) like '%' || upper(:P40_SEARCH) || '%'or
upper(p.last_name) like '%' || upper(:P40_SEARCH) || '%'or upper(p.first_name)
like '%' || upper(:P40_SEARCH) || '%'or upper(pb.name) like '%' ||
upper(:P40_SEARCH) || '%'or upper(:P40_SEARCH) is null)and
((upper(b.title) like '%' || upper(:P40_TITLE) || '%' or
upper(:P40_TITLE) is null))and ((upper(b.series) like '%' ||
upper(:P40_SERIES) || '%' or upper(:P40_SERIES) is null))and
((upper(p.last_name) like '%' || upper(:P40_LASTNAME) || '%' or
upper(:P40_LASTNAME) is null))and ((upper(p.first_name) like '%' ||
upper(:P40_FIRSTNAME) || '%' or upper(:P40_FIRSTNAME) is null))and
((upper(f.format_ret) in (upper(l_vc_format)) or upper(:P40_FORMAT) is null))
group by b.BOOK_ID, bk.book_id, bkk.book_id, b.TITLE, b.SUBTITLE, b.SERIES, b.VOLUME,
b.ISBN, f.FORMAT_ret, b.DESCRIPTION, b.PUBLISHED, b.PURCHASED_FROM, b.COMMENTS, b.WEBSITE,
c.LENGTH_MINS, pb.name, b.abridged, (nvl(d.disk01,0)+nvl(d.disk02,0)+nvl(d.disk03,0)
nvl(d.disk04,0)nvl(d.disk05,0)+nvl(d.disk06,0)+nvl(d.disk07,0)+nvl(d.disk08,0)
nvl(d.disk09,0)nvl(d.disk10,0)+nvl(d.disk11,0)+nvl(d.disk12,0)+nvl(d.disk13,0)
nvl(d.disk14,0)nvl(d.disk15,0)+nvl(d.disk16,0)+nvl(d.disk17,0)+nvl(d.disk18,0)
nvl(d.disk19,0)nvl(d.disk20,0)+nvl(d.disk21,0)+nvl(d.disk22,0)+nvl(d.disk23,0)
nvl(d.disk24,0)nvl(d.disk25,0)+nvl(d.disk26,0)+nvl(d.disk27,0)+nvl(d.disk28,0)
nvl(d.disk29,0)nvl(d.disk30,0)+nvl(d.disk31,0)+nvl(d.disk32,0)+nvl(d.disk33,0)
nvl(d.disk34,0)nvl(d.disk35,0)+nvl(d.disk36,0)+nvl(d.disk37,0)+nvl(d.disk38,0)
nvl(d.disk39,0)nvl(d.disk40,0)+nvl(d.disk41,0)+nvl(d.disk42,0)+nvl(d.disk43,0)
nvl(d.disk44,0)nvl(d.disk45,0)+nvl(d.disk46,0)+nvl(d.disk47,0)+nvl(d.disk48,0)
nvl(d.disk49,0)nvl(d.disk50,0))
This query will never work. I marked only couple of errors you have there. Actually,
I meant "formating" errors rather than "syntactical" errors. You are missing spaces
all over the place. This is why I suggested to use a CLOB column in a test table
to return the query for debugging purposes - this is how I do it at least, when I need
to escape and concatenate a lot of code.
If you are referencing item values from a user session in a function or a procedure,
then you need to use the v('ITEM') syntax instead of :ITEM syntax. However, if the
output of this procedure will be used as a function returning SQL query, you will
be fine with :ITEM.
Denes Kubicek
http://deneskubicek.blogspot.com/
http://htmldb.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
Query problem with accumulated key figures
Hi BI Gurus!
I have a report problem that I hope you can help me with!
In my report I have 2 key figures. One for accumulated revenue previous year (KF1) and one for accumulated revenue current year (KF2). Both key figures should be presented in a graph in monthly buckets.
January figures from both the key figures shoule be presented in the same bucket. Therfore I can't use 0CALYEAR since we have the "year" information in there. Instead I'm using 0CALMONTH2 which is only two digits, 01 for January. That way I can map figures from both previous year and current year in the same bucket.
I need the figures to be accumulated and this is what I have problem with. When I run the report today in February 2010 it looks like this:
Month KF1 KF2
01 10 15
02 10 20
03 15
04 10
05 20
06 10
07 10
08 15
09 15
10 20
11 20
12 10
This is how I would like the report to look like:
Month KF1 KF2
01 10 15
02 20 35
03 35
04 45
05 65
06 75
07 85
08 100
09 115
10 135
11 155
12 165
I have tried to use the setting "accumulated" for the key figures but then I get this result:
Month KF1 KF2
01 10 15
02 20 35
03 35 35
04 45 35
05 65 35
06 75 35
07 85 35
08 100 35
09 115 35
10 135 35
11 155 35
12 165 35
Since the KF2 is revenue for current year and I run the report in February I don't want any figures to be displayed in Mars...
I have tried to restrict the key figures by 0CALMONTH2 and 0CALYEAR. The KF1 is havein a restriction to only show values for 0CALYEAR - 1 and an interval for 0CALMONTH2 from JAN - DEC.
The KF2 is having a restriction to only show values in the interval "first month in year - current month" (in this example JAN - FEB) for 0CALMONTH2. And current year for 0CALYEAR.
Despite my restrictions for KF2 the numpers repeats itself for every month...
Any suggestion how I can resolve this?
Best regards
Anders FlorinHi Khaled and thank you for trying to help me!
I agree with you and think the users should accept the report as it is. But they are claiming that top management will not accept this and they would really want this to be fixed the whay that they want. I have tried to push back on this and said that I'm not sure that it can be resoleved and that it could cost them a lot of money if I try.
But I will try to resolve it for them if I have spare time in the end of the project. I have not promised them anything but it would really be nice if I could fix it.
So when you say I need to use a structure and a calculated key figure. How should the calculated key figure and the structure be configured?
If I use a structure in the rows I guess I can't use same object in calc.key.figure right? Like if I use 0CALMONTH2 in the structure I'm not able to restrict the key figure with the same object? If that is correct I also have a ZMONTH object, different story why I have that... , that I can use in the same way as 0CALMONTH2. Or is this only a problem when I use "local" formulas within the query and not using a "global" calculated key figure? Cause I have only used the "loacal" formula calculated key figure in this report....
Br
Anders -
SQL query slow with call to function
I have a SQL query that will return in less than a second or two with a function in-line selected in the "from" clause of the statement. As soon as I select that returned value in the SQL statement, the statement takes from anywhere from 2 to 5 minutes to return. Here is a simplified sample from the statement:
This statement returns in a second or 2.
select A.pk_id
from stu_schedule A, stu_school B, stu_year C, school_year D,
(select calc_ytd_class_abs2(Z.PK_ID,'U') ytd_unx
from stu_schedule Z) II
where B.pk_id = A.fk_stu_school
and C.pk_id = B.fk_stu_year
and D.pk_id = C.year
and D.school_year = '2011';
if I add this function call in, the statement runs extremely poor.
select A.pk_id,
II.ytd_unx
from stu_schedule A, stu_school B, stu_year C, school_year D,
(select calc_ytd_class_abs2(Z.PK_ID,'U') ytd_unx
from stu_schedule Z) II
where B.pk_id = A.fk_stu_school
and C.pk_id = B.fk_stu_year
and D.pk_id = C.year
and D.school_year = '2011';
Here is the function that is called:
create or replace FUNCTION calc_ytd_class_abs2 (p_fk_stu_schedule in varchar2,
p_legality in varchar2) return number IS
l_days_absent number := 0;
CURSOR get_class_abs IS
select (select nvl(max(D.days_absent),'0')
from cut_code D
where D.pk_id = C.fk_cut_code
and (D.legality = p_legality
or p_legality = '%')) days_absent
from stu_schedule_detail B, stu_class_attendance C
where B.fk_stu_schedule = p_fk_stu_schedule
and C.fk_stu_schedule_detail = B.pk_id;
BEGIN
FOR x in get_class_abs LOOP
l_days_absent := l_days_absent + x.days_absent;
END LOOP;
return (l_days_absent);
END calc_ytd_class_abs2;Query returns anywhere from 6000 to 32000 rows. For each of those rows a parameter is passed in to 4 different functions to get ytd totals. When I call the functions in the in-line view but do not select from them in the main SQL, the report (oh, this is Application Express 4.0 interactive reports, just an FYI) runs fast. The report comes back in a few seconds. But when I select from the in-line view to display those ytd totals, the report runs extremely slow. I know there are the articles about context switching and how mixing SQL with PL/SQL performs poorly. So I tried a pipeline table function where the function for the ytd totals populate the columns of the pipeline table and I select from the pipeline table in the SQL query in the interactive report. That seemed to perform a little worse from what I can tell.
Thanks for any help you can offer. -
A Problem With Sorting via Applescript
Hello everyone. I have always lurked these forums and learnt many things along the way, but this is my first question, and I hope that someone can help me out. I apologise for the huge post.
I have created a spreadsheet in Numbers that I plan to use for a soccer tournament. There are 8 Groups of 4 teams in the competition, so I have set each Group up on its own sheet in order to record the results of the games. Group 1 is on Sheet 1, Group 2 is on Sheet 2 etc. These results are then fed into a second table on the each page in order to create a competition ladder for each group. So far so good, works beautifully. See image:
My next step is sorting these tables so that they form a proper "results table" with the best team on top. My wish is to sort the results table in this order:
Points
Diff
F
Although not very experienced with Applescript, I have written a script to sort all of the 8 sheets so that I don't have to do them one at a time. Unfortunately I find that every second sheet does not sort correctly, even though I am using the same instructions for each seet in my script.
See here, sheet two:
Sheet 3 sorts correctly but not sheet 4, sheet 5 is good but sheet 6 bad etc...
This is my script:
tell application "Numbers"
tell table "Ladder1" of sheet "Group1" of document "Manu"
sort by column "k" direction descending
end tell
tell table "Ladder1" of sheet "Group1" of document "Manu"
sort by column "i" direction descending
end tell
tell table "Ladder1" of sheet "Group1" of document "Manu"
sort by column "g" direction descending
end tell
tell table "Ladder2" of sheet "Group2" of document "Manu"
sort by column "k" direction descending
end tell
tell table "Ladder2" of sheet "Group2" of document "Manu"
sort by column "i" direction descending
end tell
tell table "Ladder2" of sheet "Group2" of document "Manu"
sort by column "g" direction descending
end tell
tell table "Ladder3" of sheet "Group3" of document "Manu"
sort by column "k" direction descending
end tell
tell table "Ladder3" of sheet "Group3" of document "Manu"
sort by column "i" direction descending
end tell
tell table "Ladder3" of sheet "Group3" of document "Manu"
sort by column "g" direction descending
end tell
tell table "Ladder4" of sheet "Group4" of document "Manu"
sort by column "k" direction descending
end tell
tell table "Ladder4" of sheet "Group4" of document "Manu"
sort by column "i" direction descending
end tell
tell table "Ladder4" of sheet "Group4" of document "Manu"
sort by column "g" direction descending
end tell
tell table "Ladder5" of sheet "Group5" of document "Manu"
sort by column "k" direction descending
end tell
tell table "Ladder5" of sheet "Group5" of document "Manu"
sort by column "i" direction descending
end tell
tell table "Ladder5" of sheet "Group5" of document "Manu"
sort by column "g" direction descending
end tell
tell table "Ladder6" of sheet "Group6" of document "Manu"
sort by column "k" direction descending
end tell
tell table "Ladder6" of sheet "Group6" of document "Manu"
sort by column "i" direction descending
end tell
tell table "Ladder6" of sheet "Group6" of document "Manu"
sort by column "g" direction descending
end tell
tell table "Ladder7" of sheet "Group7" of document "Manu"
sort by column "k" direction descending
end tell
tell table "Ladder7" of sheet "Group7" of document "Manu"
sort by column "i" direction descending
end tell
tell table "Ladder7" of sheet "Group7" of document "Manu"
sort by column "g" direction descending
end tell
tell table "Ladder8" of sheet "Group8" of document "Manu"
sort by column "k" direction descending
end tell
tell table "Ladder8" of sheet "Group8" of document "Manu"
sort by column "i" direction descending
end tell
tell table "Ladder8" of sheet "Group8" of document "Manu"
sort by column "g" direction descending
end tell
end tell
Can anybody see any obvious errors with the script? Any info would be greatly appreciated. Thanks!First I would look at some items to simplify the script:
I did NOT run this.
tell application "Numbers"
set LadderNumber to 1
repeat 8 times
set theLadder to "Ladder" & LadderNumber
set theGroup to "Group" & LadderNumber
tell table theLadder of sheet theGroup of document "Manu"
sort by column "k" direction descending
sort by column "i" direction descending
sort by column "g" direction descending
end tell
set LadderNumber to (LadderNumber + 1)
end repeat
end tell
I don't see a problem with the script. I suggest adding a dummy table to each sheet and confirming you can set a value in the dummy table from the script (maybe after manually setting the value to some default value). you can also add print dialogs at each step to see what's happening... like:
set aValue to <what ever>
display dialog "The value is: " & aValue
just some thoughts -
Hi,
I have a search form with 1 field (date picker) - the user chooses a date and a report based on a sql query is shown.
I want the report to be based on only the month and year, and not the particular day.
If there is a date picker (or something similar) for only month and/or year, then I can change my form, but I don't see this option.
So, I'm trying to write my query to ignore the Day portion in the search form and just do a search based on the month and year, but i'm having trouble with this.
This is my query...
select d.dept, count(e.emp_id) "No. of Employees"
from dept d, employees e
where e.date_created = trunc(:P13_DATE, 'MONTH YYYY')
and d.dept_id = e.dept_id
group by dept
order by dept
How do I write the where clause so that the search is done only on month and year?
Or otherwise, how can I change the search form to exclude the day from the date?
Thanks.Hi,
Oh, the invalid number is the result of :P13_DATE being a string value. all item values are actually strings (or varchar2 if you like) when you referencing them with ':Px_ITEM' format. With the pl/sql function there are 2 possible ways to reference item, namely the function: V('Px_ITEM') and NV('Px_ITEM'). Although in SQL varchar2 => number conversion can be dealed with by the SQL engine.
Unfortunally there is no pl/sql method for getting a DATE of an date-picker item (based on its format mask etc.). Patrick Wolf has added this function in his ApExLib framework, function DV. I find this a nice extension.
Maybe you are looking for
-
My ipad is disabled what do i need to do
my ipad is disabled what do i need to do
-
Can I limit the number of words in text fields?
I am creating a fillable form using Adobe Acrobat XI. I know how to limit the character count in a text field, but my client would prefer that the field limit the actual number of words. Is there a way to do this? Thank you! Jeanne
-
HP OJ 6500 Wireless Networkprinter persisting in going offline
After having installed and hooked in my wireless homenetwork this Officejet HP6500 (E709n wireless) printer, one year ago, it worked fine until some time ago when it did not react to printcommands. Inspection of Windows “Printers and Faxdevices” in X
-
Hi, I want to know whether a page conflict will occur when one thread is reading a read-only database but there are other threads which are "adding" (only) data to the same database and another write-only database - IF I put the data on a SAN/NAS. I
-
Show File Info window disappears before I can change permissions on it.
I am trying to access a Pages document in a file sharing arrangement, but Pages won't allow me to access it. I checked permissions and need to add permissions, but the Show File Info window closes before I can do anything to change permissions.