Retrieving a single value from sql:query
Hi all, pretty new to jsp and tag libraries so appoligies if this isn't the correct forum or my question is a bit lame...
I've got a basic input form written in JSP and i'm trying to use AJAX to return a customers name when they input there customer IS. My AJAX interaction works ok and so far i have got it to return a string value to indicate if the customer ID is valid or invalid.
However, now i want to return the customers name based on a SELECT SQL statement. My sql works ok but i can't figure out how to return / access the single cname field that is returned. ALL the <sql:query> examples that i have seen use a <c:forEach> loop but this doesn't seem to work for me.
My AJAX / Jsp code looks like this:
<%@ page contentType="text/html" info="Customer Id Lookup" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<sql:setDataSource scope="application"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/dbawp"
user="*******"
password="********"
/>
<sql:query var="qryValidCustomer" >
SELECT cname FROM camper WHERE cid = ?;
<sql:param value="${param.data}"/>
</sql:query>
<c:choose>
<c:when test="${qryValidCustomer.rowCount == 0}">
unknown camper
</c:when>
<c:otherwise>
<c:forEach items="${qryValidCustomer.row}" var="row">
${fn:escapeXml(row.cname)} <- Doesn't seem to work - i get nothing returned
</c:forEach>
<%--good camper--%>
</c:otherwise>
</c:choose>Can anyone point me in the right direction?
Manythanks in advance,
Sam
> my db fields contain a list of sections, " 1,2,3,4,"
When you find yourself storing delimited lists in a field,
that's a sign that you should
normalize
your data. Storing lists is difficult to query, error prone and bad
for performance.
A separate table should be used to represent a many-to-many
relationship.
Table - Columns
Advertisement - AdvertisementID, AdvertisementDescription,
...other columns
Type - TypeID, TypeTitle, ...
AdvertisementType - AdvertisementID, TypeID
Instead of storing the related types as a list
AdvertisementID | TypeID
1 | 1,2,3,4
Store them as separate records in the 3rd table
AdvertisementID, TypeID
1, 1 (ad # 1, type # 1)
1, 2 (ad # 1, type # 2)
1, 3 (ad # 1, type # 3)
1, 4 (ad # 1, type # 4)
Similar Messages
-
Passing Multiple Single Values from Sender Query to Receiver Query in RRI
Dear All.
We have 2 - Bex Reports ZBEX_1 & ZBEX_2
1. In ZBEX_1 having the fileds data like the below.
Account Doc. Number - Clearing Document --- Amount
12345 - 65432 --- 100
12346 - 54321 --- 50
2. In ZBEX_2 having the following data.
Account Doc.Number -- Amount
45342 - 10
66666 - 100
65432 - 10
54321 - 5
3. I am Traying to create RRI Between ZBEX_1 & ZBEX_2 , with Sender query as ZBEX_1 and Receiver query as ZBEX_2
If I drilldown from ZBEX_1 need to show the following output in the ZBEX_2
Account Doc. Number - Amount
65432 - 10
54321 - 5
i.e If Clearing Documnet in the ZBEX_1 is same as Account Doc. Number in ZBEX_2 those Account Doc. Numbers I have to show in the output of ZBEX_2 RRI Report.
Both the records I have to show at a time.
So please suggest me
1. How to pass Multiple Single Values to Next Query using RRI
2. How to Map Clearing Document to Account Doc. Number in RRI.
NOTE: Account Doc. Num length is same as Clearing Document
Please suggest me.
Thanks & Regards,
Kiran ManyamYour scenario of passing values from multiple records in Source does not suit well for RRI Jumps.
In ZBEX_2 query, create a Replacement path variable on Clearing Document. In that Replacement path variable, use the Replacement with query option and choose the ZBEX_1 as the underlying query source.
http://help.sap.com/saphelp_nw70ehp1/helpdata/en/bd/589b3c494d8e15e10000000a114084/frameset.htm
When you execute ZBEX_2, what ever clearing document values that ZBEX_1 has will be passed through the replacement path variable as a filter to the ZBEX_2
Hope it helps!
Uday Pothireddy -
How-To populate SELECT LIST default value from SQL Query
OK, I've done my homework, and did not find my answer in the Forum, so here it is.
I have a Page that displays fields from a SQL Query. The Page also has below that radiogroups, checkboxes, and Select Lists to allow the user to change values in the fields that are displayed at the top of the Region. I am able to pre-populate the radiogroups and checkboxes by performing a SELECT in the 'Source value or expression' of the Source area of the Page Item.
However, I am unable to do the same for the Select List fields. Their default value ends up being the first value in the LOV ('-- None --' for NULL values). Source Used: Only when current value in session state is null. Source Type: SQL Query. Also, when I first go into the Page when running it, and check the Session State values, they are all null, so I don't understand why the field is not populated by the SQL Query statement as the radiogroups and checkboxes are.
Any suggestions??? I've tried all sorts of combinations.Thank you for the suggestion.
I had considered that, but cannot do so, because we are using Oracle Application Express more for development than for data containment.
We have all our data in an Oracle 10.g DB which is separate from the OAEX server, and the OAEX app will reference that data via VIEWs and DB LINKs. We are doing so primarily as an added data security layer, where the data is housed separate from the app, in case the Web site is ever compromised. The data that can be viewed is restricted to a subset of the actual data that is available.
Since the data is on a separate server, (I assume) we will not be able to set the source type to Database column, because (I asume) that is dependent upon the data being housed by the OAEX server.
That still leaves me with having to populate the field with a SELECT statement from the Oracle DB. This unfortuneately is almost a show-stopper for me because of down-stream processing data requirements. Have not been able to come up with contingencies yet. -
How can I pass value from sql query to unix script
I am new to oracle/unix.
I want to write a simple script to find max date from a table and then pass date into a variable in a korn shell script.
sql is select max(date) from table;
how can I pass that value in unix shell as a variable. ThanksI use to code like this.
Enjoy Scripting.
cmd.sql
select sysdate from dual;
exit
db.sh
#! /usr/bin/ksh
. ~oracle/.orapaths
dbdate=$(sqlplus -S user/pwd@servicename @cmd.sql)
echo $dbdate
Run shell scripts
./db.sh
SYSDATE --------- 19-JAN-07 -
I have balance column and i need to pick only positive values from sql query.
Balance
200
-20
-220
100
Expected
Balance
200
100Hi Frank,
Sorry i think i am not clear.
below is my function get_total.
one billing_key is nothing but one billing period-each period has 6 programkeys.
by following function i will get 6 records by passing 6 programkeys and one biling key
now i need to get over all balance of all periods per program. condition is i need to take only +ve amounts from the below function and sum it up
expected out. i am just giving an example of output.
actual
programkey get_total
a 100
a -50
a -50
b 200
c 300
c -200
d -100
d -25
d 400
e 500
e -10
f 600
f -200
we are taking only +ve amounts from the above.
How can i write a procedure or script to acheive program_key and balance as below.
programkey balance
a 100
b 200
c 300
d 400
e 500
f 600
create or replace FUNCTION GET_TOTAL (p_bill_key IN varchar2,
p_prog_key IN varchar2) RETURN NUMBER AS
l_total NUMBER;
l_dum_bill NUMBER;
p_count NUMBER:=0;
BEGIN
BEGIN
SELECT count(*) into p_count
FROM billing_adjust b where b.billing_key = p_bill_key ;
if p_count < 1 then
SELECT NVL(surch_amount,0) + NVL(adjust_amount,0)
INTO l_total
FROM mv_billing a, mv_prog_surch b
WHERE a.billing_key = b.billing_key and
a.billing_key = p_bill_key and
b.program_key = p_prog_key;
return l_total ;
end if;
SELECT NVL(surch_amount,0) + NVL(adjust_amount,0)
INTO l_total
FROM billing_adjust b, prog_surch_adjust c
WHERE b.billing_adjust_key = c.billing_adjust_key and
b.billing_key = p_bill_key and
c.program_key = p_prog_key;
return l_total;
EXCEPTION
WHEN NO_DATA_FOUND THEN
null;
End;
RETURN 0;
END GET_TOTAL;
This is what i have started writing to acheive expected output need help on this.
Create or replace function balance(p_company_id) return number as
v_total_due number:=0;
v_total number:=0;
CURSOR p_idn IS
SELECT PROGRAM_KEY,PROGRAM_NAME FROM MV_PROGRAM_DICT where CURRENT_YN = 'Y' order by PROGRAM_NAME_ID;
cursor p_billkey_idn is
select biling_key from billing where company_id=p_company_id;
Begin
for v_idn in p_idn loop
for v_billkey in p_billkey loop
SELECT sum(get_total(v_billkey.billing_key,v_idn.program_key)) into balance
FROM dual
WHERE get_total(v_billkey.billing_key,v_idn.program_key)>0;
END LOOP;
END loop; -
Getting zero-sized reply error when running report from SQL query
Hi,
I have a Report from SQL Query in Portal. When I select Excel in Output Format and then run the report, it works properly, but when I select HTML in Output Format, the report works if the rows returned are not so many (I've been able to display the report for up to 701 rows), but when I try selecting a value from the LOV that selects many rows, I get the following error:
ERROR
The requested URL could not be retrieved
While trying to retrieve the URL: <data suppressed>
The following error was encountered:
Zero Sized Reply
Squid did not receive any data for this request.
Any ideas on how to fix this? Why does the number of rows returned affect the report this way?
Thanks,
LorenaProblem comes when any of the filter is applied in any one of the cases selected from the GUI.Do you mean that the problems only shows when you run the report in your browser via 9iAS?
Which version are you using?
Can you post the before report trigger? -
Getting Zero Sized Reply error in report from SQL query
Hi,
I have a Report from SQL Query in Portal 3.0.9. When I select Excel in Output Format and then run the report, it works properly, but when I select HTML in Output Format, the report works if the rows returned are not so many (I've been able to display the report for up to 701 rows), but when I try selecting a value from the LOV that selects many rows, I get the following error:
ERROR
The requested URL could not be retrieved
While trying to retrieve the URL: <data suppressed>
The following error was encountered:
Zero Sized Reply
Squid did not receive any data for this request.
Any ideas on how to fix this? Why does the number of rows returned affect the report this way?
Thanks,
LorenaHi,
I have a Report from SQL Query in Portal 3.0.9. When I select Excel in Output Format and then run the report, it works properly, but when I select HTML in Output Format, the report works if the rows returned are not so many (I've been able to display the report for up to 701 rows), but when I try selecting a value from the LOV that selects many rows, I get the following error:
ERROR
The requested URL could not be retrieved
While trying to retrieve the URL: <data suppressed>
The following error was encountered:
Zero Sized Reply
Squid did not receive any data for this request.
Any ideas on how to fix this? Why does the number of rows returned affect the report this way?
Thanks,
Lorena -
Can Portal Report from SQL Query use where column IN (:bind_variable)
I would like to create a portal report from sql query with IN (:bind_variable) in the where clause. The idea is that the user would enter comma-separated or comma-quote-separated values for the bind_variable. I have tried this several ways but nothing seems to work. Can this be done?
TrentonHi,
Which version of portal are you using. This is a bug. It has been fixed in 30984.
Thanks,
Sharmila -
Report from sql query invalid date condition
Hi, I created a Reports From SQL Query. My sql is like
"select column1, column2
from myschema.tablename
where mydate > :p_date1 and mydate < :p_date2"
I am using portal with turkish and english option. If I pass p_date paramaters 'dd-MON-yyyy' format
(for example p_date1 = 23-MAR-2003 p_date2 = 26-APR-2003) in english mode portlet is return correct result,
in turkish mode 'No Row Returned'. I changed my sql statement with
"select column1, column2
from myschema.tablename
where to_date(mydate,'dd/mm/yyy') > to_date(:p_date1,'dd/mm/yyy') and to_date(mydate) < to_date(:p_date2,'dd/mm/yyyy')"
and I pass p_date parameters 'dd/mm/yyyy' format (for example p_date1 = 23/03/2003 p_date2 = 26/04/2003)
but now turkish and english mode No row returned.
How may I write correct sql statament. My database NLS_DATE_FORMAT=DD/MM/YYYY and NLS_LANGUAGE=TURKISH.
thanks.Hi,
Try this for turkish mode:
Case 1: the 'mydate' column has a kind of a char data type (like char, varchar or varchar2)
and a value like '30/03/2003'
"select column1, column2
from myschema.tablename
where
to_date(mydate,'DD/MM/YYYY') > :p_date1
and
to_date(mydate,'DD/MM/YYYY') < :p_date2"
Case 2: the mydate column has a date type:
"select column1, column2
from myschema.tablename
where
mydate > :p_date1
and
mydate < :p_date2"
In both cases use the following parameter values:
p_date1 = 23/03/2003
p_date2 = 26/04/2003
This should work
Thanks
Peter -
Getting a single value from an array collection
I have an array collection that was created from an XML file
through the HTTP Service. One of the nodes in the XML file was
product_number and I can display all of the items in this node in a
datagrid so I know the array has the name of the node in it.
I would like to be able to retrieve a single item from the
array collection (e.g. a product_number = to xxx) and assign it to
a variable.
I would also like to be able to assign all the items in a
particlur column (e.g. all product_numbers) to separate variables
at the same time.
Any help would be greatly appreciated.You can apply a filterFunction.
Or you can do it the brute force way: loop over the elements,
and test for the value you want.
As far as putting values into variables, I am not sure what
you want.
And this is not a Flex Builder question and should go in the
General Discussion forum.
Tracy -
Can I declare variables in Reports from SQL Query
Hi
I have a Report from SQL Query published as a portlet on a page among other reports. In the query report I am using the fuction WWCTX_API.GET_USER at quite a few places to filter the data returned to the user. Can I assingn the user id to a variable at some level & replace the fuction WWCTX_API.GET_USER with the variable in all the places.
For eg:
usr varchar2(25);
usr:= PORTAL30.WWCTX_API.GET_USER;
select USER_ID, USER_LVL, BUSINESS_ID, BRANCH_ID from crs_user where user_id=usr;
can i declare variable and assign the value like the above at any level(Report or Page Level) to the acces the variale in queries.
Thanks in advanceI have found that you can't use a * in a dynamic page.
Try this:
<ORACLE>
DECLARE
usr varchar2(25):=PORTAL30.WWCTX_API.GET_USER;
BEGIN
for c in
(SELECT <column_name> <alias> FROM PORTALWORK.CRS_USER WHERE USER_ID=usr)
Loop
htp.p(c.<alias>);
END;
</ORACLE>
You can also add table tags for column formating:
<table>
<tr><td>column 1</td></tr><tr><td nowrap>
<ORACLE>
DECLARE
usr varchar2(25):=PORTAL30.WWCTX_API.GET_USER;
BEGIN
for c in
(SELECT <column_name> <alias> FROM PORTALWORK.CRS_USER WHERE USER_ID=usr)
Loop
htp.p(c.<alias>);
END;
</ORACLE>
</td></tr></table>
Martin -
How to Sort by the length of the returned value from a query.
Hi,
I was wondering if it is possible to sort by the length of the returned value from a query?
For example if I want to get a list of people with the name 'Samuel', I would like to short by how short the length of the whole name is.
Sort by length of the name in SQL
Samuel Syda
Samuel Indranaka
Samuel Johnsons
Samuel Longhenderson
Thank you.Hi,
Sorting is done by an ORDER BY clause at the end of the main query.
In most cases, you can ORDER BY any expression, even f it is not in the SELECT clause. In this case, it sounds like you just need:
ORDER BY LENGTH (name_column)
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Post your query, using an ORDER BY clause like the one above, and point out where that query is producing the wrong results, and explain, using specific examples, how you get the right results from the given data in those places.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002 -
Retrieve Title field values from multiple lists and add into another list
Hi , Iam trying to retrieve Title field value from multiple lists. and add them into another list. using Javascript. Can any one help me in doing this. Below is the code.. function save() { clientContext = new SP.ClientContext.get_current(); oWebsite = clientContext.get_web(); oList = clientContext.get_web().get_lists().getByTitle('MainList'); clientContext.load(oList); clientContext.executeQueryAsync(OnSucceeded, onQueryFailed); } function GetListItemValue(listName, fieldName) { var list = oWebsite.get_lists().getByTitle(listName); var eventValue = document.getElementById(fieldName).value; eventValue = eventValue.replace(",", ""); var camlQuery = new SP.CamlQuery(); var filterdata = '<view><query><where><eq><fieldref name="Title/"><value type="Text">' + myreqValue.trim() + '</value></fieldref></eq></where></query></view>'; camlQuery.set_viewXml(filterdata); listItems = list.getItems(camlQuery); clientContext.load(list); clientContext.load(listItems, 'Include(Id)'); clientContext.executeQueryAsync(Succeeded,Failed); } function OnSucceeded() { itemCreateInfo = new SP.ListItemCreationInformation(); oListItem = oList.addItem(itemCreateInfo); oListItem.set_item('Title', 'My New Title'); var deptItemLookupField = new SP.FieldLookupValue(); //Problem in below line...I was unable to get ID var getId = GetListItemValue("Listname1", "txtboxname1"); alert("ID" + getId); if (getId != undefined) { deptItemLookupField.set_lookupId(getId); } var getId12 = GetListItemValue("Listname12", "txtboxname12"); alert("ID" + getId12); if (getId12 != undefined) { deptItemLookupField.set_lookupId(getId12); } oListItem.update(); clientContext.executeQueryAsync(itemadded, itemFailed); } function itemadded() { alert('Item added successfully'); } function itemFailed(sender, args) { alert('Item added itemFailed' + args.get_message() + '\n' + args.get_stackTrace()); }
RajHi,
For this requirement, you will need to retrieve all the lists objects you want firstly, then execute the requests one by one to get the value of the Title column using CAML or
LINQ.
How to: Retrieve Lists Using JavaScript
http://msdn.microsoft.com/en-us/library/office/hh185009(v=office.14).aspx
About
retrieve list items:
http://msdn.microsoft.com/en-us/library/office/hh185007(v=office.14).aspx
You can use
Promise in your script to make your requests sequentially:
http://www.shillier.com/archive/2013/03/04/using-promises-with-the-javascript-client-object-model-in-sharepoint-2013.aspx
http://www.learningsharepoint.com/2013/08/13/using-deferred-and-promise-to-handle-async-calls-in-sharepoint-client-object-model/
Best regards
Patrick Liang
TechNet Community Support -
Single row from this query without create a group by
Can I have a single row from this query without create a group by on tipo (TIPO can have only 2 value (A,D)
SELECT
CASE TIPO
WHEN 'D' THEN SUM(IMPORTO) ELSE 0 END DIMPORTO,
CASE TIPO
WHEN 'A' THEN SUM(IMPORTO) ELSE 0 END AIMPORTO
FROM MGIORNALE
WHERE K_CONTO = '100001' --CONTO
AND DECODE(T_MOVIM,'MRAP',TO_DATE('31/12/'||to_char(a_competenza),'DD/MM/YYYY'),DATA_RG)
-- BETWEEN DATAA AND DATAB
BETWEEN '01/01/2006' AND '31/12/2006'
--GROUP BY TIPO
--AND TIPO = COL_conto
Thanks in advanceIs like this?
sum (CASE TIPO
WHEN 'D' THEN IMPORTO ELSE 0 END) DIMPORTO, -
Query based Report (Reports From SQL Query)
Hi All,
I am facing a problem with a report. I need your help.
I am creating a Report From SQL Query (Portal) with some arguments passed at runtime. I am able to view the output, if the query returns few rows ( arount 1000 rows). But for some inputs it needs to generate >15000 records, at this point the page is getting time out (i think!) and showing error page. I am able to execute query from the SQL Plus console ot using TOAD editor. Here the query is not taking more that 2 mins time to show the result.
If i am executing from Portal i observed that, once i give the appropriate input and hit submit button a new oracle process is getting created for the query on UNIX (I am usign "TOP" command to check processes). The browser page will be shown error page after 5 minutes (i am assuming session time out!) , but on the backend the process will be executed for more than 30 mins.
Can i increase a timeout of portal page, how i can do this?
The data returned as a result of the query is sized more than 10 MB. Is caching this much data is possible by the browser page? is the returned data is creating any problem here.
Please help me to find appropriate reasone for the failure?Can you post the URL that is giving you the page not found error ? I am not sure if I can be of much help though.
In order to increase your chances to get a reply you should also post your question in the Portal Forum - Oracle Application Server Portal
Edited by: Rodolfo Ferrari on Jun 16, 2009 3:49 PM
Maybe you are looking for
-
Is it possible to use an iPhone as a controller for iPad (for games).
Is it possible to use an iPhone as a controller for iPad? And if so what apps are supported. And will gta 3, vice city, San Andreas and dead trigger 2 work with it.
-
Need to reformat external hard drive for time machine?
Hello, We recently purchased an external hard drive for our family iMac after we had to have a new hard drive put in. We picked up a Western Digital 1tb My Book (http://www.wdc.com/en/products/Products.asp?DriveID=725). I set up the external hd with
-
PO ORDCHG - idoc - releationship browser population Error
Hi , I tried to create a purchase order and changed it. All the configurations for IDOC are working fine for Purchase order creation and Change. The IDOC generated for Purchase order create is populated in the Releation ship browser but however the I
-
Hallo, wenn ich auf ein PDF Dokument klicke, öffnet sich Acrobat mit einem nicht näher bezeichneten Fehler (siehe screenshot). Ich muss meinst 4-5 mal wieder neu auf das Dokument klicken, bis es dann endlich angezeigt wird. Manchmal geht es überhaupt
-
Do I have to add commit in SQL Server stored procedure
In SQL Server, any statement not within a transaction is automatically commit. for example, single statement "INSERT INTO Table" is commit automatically. but in PL/SQL, you have to issue "COMMIT" after the statement. Since I have about 500 stored pro