SQL Query Problems
Hello,
I am trying to query a database column containing xml. How my problem is when I display my query on the page the data is not being shown properly.
The data in the database is like this:
<P><tag1>2003/05/22 11:01:34</tag1><tag2>2003/05/22</tag2><tag3>11:01:34</tag3><tag4></tag4>.......
However all that is returned is on the jsp page
2003/05/22 11:01:34<tag2>2003/05/22<tag3>11:01:34..............
i.e closing tags missing and empty pairs not shown at all.
My query is a simple
String sqlQuery="select * from table;
rs = stmt.executeQuery (sqlQuery);
rs.next();
out.print(rs.getString(1));
Can anyone suggest why the data stored in the column is being truncated and how I can prevent this.
Many thanks in advance
Les,
Hi,
For your problem, the solutions i thought is put your output between <pre></pre> tags in HTML
means
out.print("<pre>" + rs.getString("") + "</pre>")
hope this willl work.
have fun!!!
Similar Messages
-
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
------------------------------------------------------------------- -
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. -
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,
BalaYou 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. -
SQL query problem using analytical/report function
Hello there,
I am having some problem writing my query. I have this table below:
create table t (priority number,
plannedamount number,
availablepieces number,
material_id varchar2(20))
insert into t values (1, 15, 30, 'A');
insert into t values (2, 20, 30, 'A');
insert into t values (3, 5, 30, 'A');
insert into t values (4, 8, 30, 'A');
insert into t values (5, 4, 30, 'A');
insert into t values (1, 2, 10, 'B'); PRIORITY| PLANNED AMOUNT|AVAILABLE PIECES | MATERIAL_ID
1 15 30 A
2 20 30 A
3 5 30 A
4 8 30 A
5 4 30 A
1 2 30 B .
Each line is a customer order ordering a material. I am grouping by material and ordering it by priority. I want to display a new column called pieces not reserved yet. This column will show that if the order can be fully reserved for that current order ordering by priority.
If the row can be reserved it will substract and bring it to the next row. If it cannot the pieces not reserved will remain the same.
I've tried using sum(), lead(), first(), lag(), etc but I still cannot get the correct result.
PRIORITY| PLANNED AMOUNT|PIECES NOT RESERVED YET | MATERIAL_ID
1 15 30 A
2 20 15 A
3 5 15 A
4 8 10 A
5 4 2 A
1 2 30 B
Can anyone elaborate or have any hints on what method to use to create this column?
Thanks. .
Edited by: 998373 on Apr 5, 2013 11:42 AM
Edited by: 998373 on Apr 5, 2013 11:43 AMFrom 10.x on
with t(PRIORITY, PLANNED_AMOUNT,AVAILABLE_PIECES , MATERIAL_ID) as
select 1, 15, 30, 'A' from dual union all
select 2, 20, 30, 'A' from dual union all
select 3, 5, 30, 'A' from dual union all
select 4, 8, 30, 'A' from dual union all
select 5, 4, 30, 'A' from dual union all
select 1, 2, 30, 'B' from dual
select
MATERIAL_ID
, PRIORITY
, PLANNED_AMOUNT
, AVAILABLE_PIECES PIECES_NOT_RESERVED_YET
from t
model
partition by (material_id)
dimension by (PRIORITY)
measures (
PLANNED_AMOUNT
, AVAILABLE_PIECES
rules (
AVAILABLE_PIECES[priority>1] order by priority=
case when PLANNED_AMOUNT[cv()-1] <= AVAILABLE_PIECES[cv()-1]
then AVAILABLE_PIECES[cv()-1] - PLANNED_AMOUNT[cv()-1]
else AVAILABLE_PIECES[cv()-1]
end
MATERIAL_ID PRIORITY PLANNED_AMOUNT PIECES_NOT_RESERVED_YET
A 1 15 30
A 2 20 15
A 3 5 15
A 4 8 10
A 5 4 2
B 1 2 30 -
Hi!
I want to create a report with the script i copied at the bottom of this message. For some reason i get the following error:
Error: Unable to describe SQL statement. Please correct it (WWV-13010)
(WWV-)
ORA-01001: invalid cursor (WWV-11230)
ORA-00937: not a single-group group function (WWV-11230)
Critical Error in wwerr_api_error.get_errors! SQL Error Message: ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-01001: invalid cursor (WWV-)
Does anybody have a clue where this is coming from? It seems to me that there are no diffucult un-SQL like things in the script.
Thanks in advance!
SELECT rse.name||', '||rse.initials||' '||rse.prefix "Medewerker"
,dpt.name "Afdeling"
,sum(round(act.duration *24,2)) "Aantal uren"
,count(distinct(sht.begin_date)) "Aantal dagen"
,count(distinct(ill.begin_time)) "Aantal keer"
FROM ros.ros_departments@ROSPROD dpt
,ros.ros_scenarios@ROSPROD sco
,ros.ros_activity_types@ROSPROD aty
,ros.ros_activities@ROSPROD act
,ros.ros_duties@ROSPROD dty
,ros.ros_illnesses@ROSPROD ill
,ros.ros_shifts@ROSPROD sht
,ros.ros_resources@ROSPROD rse
WHERE rse.id = sht.rse_id
AND sht.name = 'Z'
AND sht.begin_date <= sysdate
AND ill.rse_id = rse.id
AND trunc(sht.begin_date) BETWEEN trunc(ill.begin_time) AND trunc(nvl(ill.end_time,sysdate))
AND dty.id = sht.dty_id
AND decode(sign(dty.begin_time)
,-1, sht.begin_date + 1
,sht.begin_date)
>= to_date('10-01-2000 00:00','dd-mm-yyyy hh24:mi')
AND decode(sign(dty.begin_time)
,-1,sht.begin_date + 1
,sht.begin_date)
<= to_date('10-01-2001 23:59','dd-mm-yyyy hh24:mi')
AND sht.begin_date >= to_date('10-01-2000 00:00','dd-mm-yyyy hh24:mi') - 1
AND sht.begin_date <= to_date('10-01-2001 23:59','dd-mm-yyyy hh24:mi') + 1
AND act.dty_id = dty.id
AND aty.id = act.ate_id
AND aty.name = 'Ziek'
AND sco.sce_rsr_id = sht.sce_id
AND sco.status = 'PUBLISHED' -- <> 'TRIAL' en 'PLAN'
AND dpt.id = sco.dpt_id
AND dpt.name NOT IN ('BEEK/VKL', 'BEEK/VLA','EELDE/VKL','EELDE/VLA','ROTTERDAM/VKL','ROTTERDAM/VLA','SIM','STO','RCN','XSurvey')
AND rse.name = :MDWPARAM
AND dpt.name = :AFDPARAM
GROUP BY rse.name||', '||rse.initials||' '||rse.prefix ,dpt.name
ORDER BY 2,1Hi,
Please run this sql statement in the SQL session. This way you will get the line number where the problem is happening.
The error seems to be because the column in the select is not in the group by clause.
Thanks,
Sharmila -
Access SQL Query Problem - Pls help
Hi,
I'm connecting to an Access database and have a query which looks somehting like this:
SELECT Accept.ACCEPT_NO,
Accept.CURRENCY,
Accept.INT_RATE,
Accept.F_AMOUNT,
Accept.DEALER,
Accept.MATURITY,
Accept.START_DATE,
Accept.DEAL_DATE,
Accept.DEALTICKET,
Accept.BANK_NAME,
Accept.CALC_DAYS,
"2001/11/22" AS CurrentDate
FROM Accept;
It works fine without the line with CurrentDate so i'm sure something's wrong there. What i want to do is set CurrentDate as a constant ("2001/11/22") i dont have any experience with Access so any help you could give me would be greatly appreciated.
Thanx in advance.I was able to successfully query an access 97 database using the following SQL:
String sql = "SELECT emp.emp_fname, emp.emp_lname, '2001/11/22' AS CurrentDate FROM emp";don't know why your's wouldn't work. Was there a SQLException? Or are you trying to get it to work using the Access SQL editor?
Jamie -
SQL Query Problem - Please Help
Post Author: nmellick
CA Forum: Data Connectivity and SQL
Hello,
I am trying to use a query in CR9 to pull the latest date of a DREXAM for each patient. The patient can have one item or several items. When I run this query, it only pulls back one record, the latest DREXAM from the whole table, not by patients. I need it by patients (tracking_id is the patient_id). Any ideas on what I'm doing wrong?
Here is the query:select t.tracking_id, t.tracking_group_cd, t.track_event_id, t.requested_dt_tm, t.complete_dt_tm, te.display_keyfrom V500.TRACKING_EVENT t, v500.track_event tewhere t.track_event_id = te.TRACK_EVENT_IDand te.display_key = 'DREXAM'and t.complete_dt_tm = (select max(complete_dt_tm) "MaxDate" from V500.TRACKING_EVENT t, v500.track_event te where t.track_event_id = te.TRACK_EVENT_ID and te.display_key = 'DREXAM');
Note: The tracking_id field shows by patient. When I run everything up to the last "and" (the complete date), it pulls all rows, which may be more than one per patient. Basically, I just want the latest DREXAM row per patient.
Thanks!Try to escape the special character '%' using '\%'.
-
Urgent Sql Query Problem - -Very Urgent
Hi Guys,
I need a urgent solution for a problem.I am
using the following query
select ename from emp where deptno =10
Now I will declare a bind variable and if user passes 'A'
then the query will run as it is and if he passes B
then it should run the above query with this additional clause -> birthdate - hiredate >15.
Please can any one help its very urgentAssuming that you have a birthdate column in your emp table, the following will do what you are asking for:
VARIABLE bind_var VARCHAR2(1)
EXECUTE :bind_var := '&bind_variable'
SELECT ename FROM
(SELECT 'A' AS selection, ename FROM emp WHERE deptno = 10
UNION ALL
SELECT 'B' AS selection, ename FROM emp WHERE deptno = 10 AND birthdate - hiredate > 15)
WHERE selection = :bind_var
However, the clause "birthdate - hiredate > 15" will only retrieve rows for employees who were born more than 15 days after they were hired. I doubt that this is what you really want, since this is impossible. -
SQL query problem while combining two values.
Hi,
I am having a table test with columns X and Y. X is not nullable where as Y is nullable.
I had a requirement where I have to get these two values seperated by '-' (Hyphen).
So I wrote the query like :
Select X||'-'|| Y from test.
But now Y is nullable. So I'm getting some values ended by hypen if y is null. So is there any way to append these two only if Y is present and not to join if Y is null or empty.
Help me out in resolving this issue.
Regards,
Venky.There are several ways to avoid/remove that hypen
1. select RTRIM(X||'-'||Y,'-') from test
2. select X||decode(Y,null,null,'-'||Y) from test
HTH,
Mohana -
SQL Query problem (PL/SQL function returning SQl query)
I am using 3.1.2 Apex. When I create the region source with the following code.
DECLARE
l_sql VARCHAR2(32767);
X1 VARCHAR2(9);
X2 VARCHAR2(9);
X3 VARCHAR2(9);
X4 VARCHAR2(9);
X5 VARCHAR2(9);
X6 VARCHAR2(9);
X7 VARCHAR2(9);
X8 VARCHAR2(9);
BEGIN
SELECT decode(:P3_FAILED_CDD,'0','0','1','1', '2','2' ) INTO X2
FROM DUAL;
SELECT decode(:P3_Order_status,'J','J','1','1','2') INTO X3
FROM DUAL;
SELECT decode(:P3_FAILED_STAGE,'0','0','1','1','2') INTO X4
FROM DUAL;
SELECT decode(:P3_ORDER_TYPE,'TYPE1','TYPE1','TYPE2','TYPE2','2') INTO X5
FROM DUAL;
SELECT decode(:P3_INCLUDE_SFIN,'NO','NO','YES','YES') INTO X6
FROM DUAL;
SELECT decode(:P3_CDD_MATCH,'0','0','1','1', '2','2' ) INTO X7
FROM DUAL;
SELECT decode(:P3_FIELD,'0','0','1','1', '2','2' ) INTO X8
FROM DUAL;
l_sql := 'SELECT
ORDER_NR,
FNN,
ST,
SOT,
STAGE,
CUST_NAME,
STG_DAYS,
ZONE,
P1.OWNER,
QUEUE_A,
STG_LFD,
LFD_LEFT,
CIJ_FLAG,
FST_FLAG,
CCD_COUNT,
TCD_COUNT,
LATEST_RET_CODE,
CRD,
CDD_DATE,
CRD_LEFT CDD_LEFT,
TCD_DATE RTCD_DATE,
PROP_TCD_DATE TCD_DATE,
PROJECT_ID,
APPLN_TBO,
CO_ORD_ID,
CON_WSTN,
P1.STATE,
A_DTB,
B_DTB,
DESIGN_NO,
CREATE_DATE,
DATE_APPLN,
CUSTOMER_ID,
SALES_QUEUE,
TRACKING_NR,
WORK_REQUIRED,
SFIN_STAGE_ENTERED_DATE,
APPLN_CONTACT_OFFICER,
A_LOCATION_ADDRESS,
B_LOCATION_ADDRESS,
SO_CREATE_USERID,
OP_SEP,
WMC_CODE
FROM RASS_TICKET_VIEW P1
WHERE WMC_CODE like :p3_wmc_code
AND ST in (SELECT SYSTEM_ID from PRDRF where PRODUCT_CATEGORY like :p3_product_cat)';
IF X2 = '0' then
l_sql := l_sql || ' and CRD_LEFT < 0';
END IF;
IF X2 = '1' then
l_sql := l_sql || ' and CRD_LEFT >= 0';
END IF;
IF X3 = 'J' then
l_sql := l_sql || ' and CIJ_FLAG = ''J''';
END IF;
IF X3 = '1' then
l_sql := l_sql || ' and CIJ_FLAG is null';
END IF;
IF X4 = '0' then
l_sql := l_sql || ' and LFD_LEFT < 0';
END IF;
IF X4 = '1' then
l_sql := l_sql || ' and LFD_LEFT >= 0';
END IF;
IF X5 = 'TYPE1' then
l_sql := l_sql || ' and SOT in (''NEW'',''NET'',''ERT'',''UGP'')';
END IF;
IF X5 = 'TYPE2' then
l_sql := l_sql || ' and SOT not in (''NEW'',''NET'',''ERT'',''UGP'')';
END IF;
IF X6 = 'NO' then
l_sql := l_sql || ' and STAGE in (''DSAL'',''DPLO'',''OISS'',''TRPB'',''OTST'',''TEQP'',''DSPS'')';
END IF;
IF X7 = '0' then
l_sql := l_sql || ' and PROP_TCD_DATE <= CDD_DATE';
END IF;
IF X7 = '1' then
l_sql := l_sql || ' and PROP_TCD_DATE > CDD_DATE';
END IF;
RETURN l_sql;
END;
The query returns data.
If I add some more code just after the where clause.
AND decode(CUST_CODE,'TW','TW','RET') like (select decode(OPS_SEP,'TS','%',OPS_SEP) from T_U_CDW_BU_OP_SEP where upper(USER_ID) = upper(:APP_USER))
The query just stops working and no error message is returned.
I thought there was an issue prior to version 3.1.2 that was fixed in version 3.1.2
Othwerwise is there a better way to write the code? As I have 7 radio btn's that control the condition within the where clause.
Thanks
Ron>
bug in APEX 3.0
>
Are you sure?
Do as Paul has suggested and post the code that doesn't work (including your extra line) using the {noformat}{noformat} tags +exactly+ as you had it in the region source.
Cheers
Ben -
SQL query problem: how tp select all duplication in the table?
Hi all,
I have a table with the following columns:
1. contact_id
2. fname
3. lname
4. email
The email column must be unique (unfortunately it's not); therefore, I have to delete all duplication in the system.
Question: how can I select all duplication in the table?
I tried this...didn't work (I'm expecting only the emails that are duplicated)
THANK YOU!
SELECT distinct TC1.email, TC1.contact_ID FROM ta_contacts AS TC1 where TC1.email <>'' AND TC1.email not in ( SELECT distinct TC2.email FROM ta_contacts AS TC2 where TC2.email <>'' )Sounds like an SQL and not a JDBC question. In any case, if a column needs to be unique, then you should, of course, designate a unique constraint on the table so you never end up with duplicates in the first place.
-
Hello,
I am trying to split the result of a field in "sub" results:
select otname from ordertrailer: this statement results in
OTNAME
163.24.27.167.U.BASE.F.I.4.3.10.837.1.34
I would like to have a query which gives me as results, the following:
OTNAME AA BB CC DD
163.24.27.167.U.BASE.F.I.4.3.10.837.1.34 163 24 27 167
and so on...
I have used the following query:
select id, otname, decode(id,1,substr(otname,1,instr(otname,'.',1,1)-1),decode(instr(otname,'.',1,id),0,
substr(otname,instr(otname,'.',1,id-1)+1,length(otname)-instr(otname,'.',1,id-1)+1),
substr(otname,instr(otname,'.',1,id-1)+1,instr(otname,'.',1,id)-instr(otname,'.',1,id-1)-1))) value
from (
select rownum id from dual
connect by level <= (select length(otname)-length(replace(otname,'.',''))+1
from ordertrailer
where otxact = 36852284
and otseq = 0)
) temp,
ordertrailer
where otxact = 36852284
and otseq = 6;
but I get the results in different rows:
ID OTNAME value
1 163.24.27.167.U.BASE.F.I.4.3.10.837.1.34 163
2 163.24.27.167.U.BASE.F.I.4.3.10.837.1.34 24
3 163.24.27.167.U.BASE.F.I.4.3.10.837.1.34 27
4 163.24.27.167.U.BASE.F.I.4.3.10.837.1.34 167
5 163.24.27.167.U.BASE.F.I.4.3.10.837.1.34 U
6 163.24.27.167.U.BASE.F.I.4.3.10.837.1.34 BASE
7 163.24.27.167.U.BASE.F.I.4.3.10.837.1.34 F
8 163.24.27.167.U.BASE.F.I.4.3.10.837.1.34 I
I need instead to have all data on the same row.
Thanks in advance
AlessandroTry changing the +'s into *'s:
with my_tab as (select '163.24.27.167.U.BASE.F.I.4.3.10.837.1.34' otname from dual union all
select 'fred.24.27.167.U.BASE.F.I.4.3.10.837.1.34' otname from dual union all
select '163.24.27.167.33.BASE.F.I.4.3.10.837.1.34' otname from dual union all
select '163.24.27.167' otname from dual)
select otname,
regexp_substr(otname, '[[:alnum:]]*[^.]', 1, 1) a,
regexp_substr(otname, '[[:alnum:]]*[^.]', 1, 2) b,
regexp_substr(otname, '[[:alnum:]]*[^.]', 1, 3) c,
regexp_substr(otname, '[[:alnum:]]*[^.]', 1, 4) d,
regexp_substr(otname, '[[:alnum:]]*[^.]', 1, 5) e,
regexp_substr(otname, '[[:alnum:]]*[^.]', 1, 6) f,
regexp_substr(otname, '[[:alnum:]]*[^.]', 1, 7) g,
regexp_substr(otname, '[[:alnum:]]*[^.]', 1, 8) h
from my_tab;
OTNAME A B C D E F G H
163.24.27.167.U.BASE.F.I.4.3.10.837.1.34 163 24 27 167 U BASE F I
fred.24.27.167.U.BASE.F.I.4.3.10.837.1.34 fred 24 27 167 U BASE F I
163.24.27.167.33.BASE.F.I.4.3.10.837.1.34 163 24 27 167 33 BASE F I
163.24.27.167 163 24 27 167
Maybe you are looking for
-
I have a MacBook (mid-2007) with 2gb ram (max allowed) and recently upgraded to a 750 GB hard drive. And I have over 590 GB free Tonight I got a popup box requiring me to force quit my applications because I had run out of room on my startup disk. I
-
Dear Gurus, In my current company we have 2 clients and have different Company Codes associated to the clients. We are contemplating merging of both the clients and have only one Client with all the company codes, can you briefly let me know what wou
-
Still some 'Not Assigned' in query result
Hi, In fact, I've built a query on a multiprovider ( 1 Cube + 1 ODS ) The ODS and the Cube are joined by the material (0material). The Cube and the ODS are well filled. Queries on each Infoprovider correctly display the results. When I launch my quer
-
SAPBEX VBA - I need the technical name of my workbook
Hello everybody, I have to solve the following problem: My task is to open an existing workbook (BE Analyzer) and paste a picture depending on the technical name of the workbook. I have already programed the the download of the picture, but I still n
-
Plugin database access to calendar
I am developing Web pages, which show a calendar of events by month. I have developed a simple JSP calendar and am wondering how I would go about plugging it into database I have experience of using JDBC to connect to database. The problem I have is