Query returns no records
Hi
create table t2(nm date)
insert into t2 values(sysdate)
SQL> select * from t2;
NM
13-FEB-09
SQL> select * from t2
2 where nm=sysdate;
no rows selectedThough nm column in T2 table is having sysdate as value..
But the select query says no rows return ..
Why???
How to change the query so as to get the result..
Thanks
the column nm is also of DATE datatype..
How can we convert it to date again using to_date function
SQL> select to_char(nm,'dd-mm-yyyy') from t2;
TO_CHAR(NM
13-02-2009the above query is working..
But
Select * from t2 where nm=sysdate; is not working..
How to compare the date columns in where clause
Edited by: josh1612 on Feb 12, 2009 10:22 PM
Similar Messages
-
Using index in a query return few records than full table access
Today we have an issue with a query, when it use the ok index the returned are not all records that apply to where clause condition.
See bellow
explain plan for
select * from movdb.zan_m03 where
M00AF = TO_DATE('11/01/28','YY/MM/DD') AND
M00za = 10 AND
m00AC = 50 AND
M00AD between 136906 and 136999
SELECT * FROM TABLE(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 1882720105
| Id | Operation | Name |
| 0 | SELECT STATEMENT | |
| 1 | TABLE ACCESS BY INDEX ROWID| ZAN_M03 |
|* 2 | INDEX RANGE SCAN | PK_ZAN_M03 |
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
2 - access("M00AF"=TO_DATE('11/01/28','YY/MM/DD') AND "M00ZA"=10 AND
"M00AC"=50 AND "M00AD">=136906 AND "M00AD"<=137141)
filter("M00AD"<=137141 AND "M00AD">=136906)
Note
- rule based optimizer used (consider using cbo)
20 rows selected.
The query above return only one row insted 1579 record that apply to this conditions.
When forcing a full table acess with a hint, the query return all records that apply, the 1579 record.
select /*+ FULL(zan_m03) */ M00AF, M00za, m00AC , M00AD from movdb.zan_m03 where
M00AF = TO_DATE('11/01/28','YY/MM/DD') AND
M00za = 10 AND
m00AC = 50 AND
M00AD between 136906 and 137141
Can you help me to identify what's happening?
I am with Oracle 10g R2 10.2.0.4 standard edition
the statistics are up to date
the opitimizer_mode are rule, but altering in session level to all_rows happens the same issue.
Nothing about corruption in the alert log.
Thanks in advance
Regards
CristianoYes the query are the same and correct restriction for where clause are M00AD between 136906 and 137141.
I've pasted, by mistake, another test query
The corrects are:
select M00AF, M00za, m00AC , M00AD from movdb.zan_m03 where
M00AF = TO_DATE('11/01/28','YY/MM/DD') AND
M00za = 10 AND
m00AC = 50 AND
M00AD between 136906 and 137141
This use pk index and return one row
select /*+ FULL(zan_m03) */ M00AF, M00za, m00AC , M00AD from movdb.zan_m03 where
M00AF = TO_DATE('11/01/28','YY/MM/DD') AND
M00za = 10 AND
m00AC = 50 AND
M00AD between 136906 and 137141
This does a full table access and return 1579 records
I´ve been searching for wrong results bugs on my oracle support, but not found one that mentions something like our issue.
I checked the dba_tables and dba indexes and the number of rows are different, and I think this would be the same because it's is a pk.
Look this
SQL> select NUM_ROWS from dba_tables where table_name = 'ZAN_M03'
2 /
NUM_ROWS
228527878
select NUM_ROWS from dba_indexes where index_name = 'PK_ZAN_M03';
SQL> select NUM_ROWS from dba_indexes where index_name = 'PK_ZAN_M03';
NUM_ROWS
217510185
Is normal a index for pk having much fewer rows than table? I think not, but not sure.
Again
Thanks in advance
Regards
Cristiano -
Query returns zero records in coldfusion context, but works fine in Navicat
I've got a query that's returning zero records when I load a page. If I copy and paste that same query (from the debug output) into navicat, I get rows returned (as I expect). Has anyone seen this? It happens locally (CF9) AND remotely on our staging server (CF10). Even weirder, it's a query that was previously working fine - I simply added an if statement to the where clause, and all of a sudden...
Here's the query:
<CFQUERY name="LOCAL.getEncounterServices" datasource="#REQUEST.dsn#">
SELECT
a.EncounterProductID,
a.DateTime AS ServiceDate,
aa.CartItemID,
aaa.CartID,
aaaaa.CartStatus,
b.ProductID,
b.ProductName,
b.CPTCode,
b.Price,
c.EncounterID,
c.DateTimeClosed AS EncounterClosedDate,
d.FirstName,
d.LastName
FROM
EncounterProducts a
LEFT JOIN CartItemProduct aa ON (a.EncounterProductID = aa.EncounterProductID AND aa.Active = 1)
LEFT JOIN CartItem aaa ON (aa.CartItemID = aaa.CartItemID)
LEFT JOIN Cart aaaa ON (aaa.CartID = aaaa.CartID)
LEFT JOIN CartStatus aaaaa ON (aaaa.CartStatusID = aaaaa.CartStatusID),
Product b,
Encounters c,
Contacts d,
EncounterStatuses e
WHERE
1 = 1
AND (aa.CartItemID IS NULL OR aaaaa.CartStatus = 'Deleted')
AND a.Active = 1
AND a.ProductID = b.ProductID
AND a.EncounterID = c.EncounterID
AND c.PatientID = d.ContactID
AND c.EncounterStatusID = e.EncounterStatusID
AND e.EncounterStatus = 'Closed'
<CFIF IsDefined("ARGUMENTS.encounter") AND IsObject(ARGUMENTS.encounter)>
AND c.EncounterID = <CFQUERYPARAM cfsqltype="cf_sql_integer" value="#ARGUMENTS.encounter.getID()#">
<CFELSE>
AND c.DateTimeClosed >= <CFQUERYPARAM cfsqltype="cf_sql_date" value="#ARGUMENTS.startDate#">
AND c.DateTimeClosed < <CFQUERYPARAM cfsqltype="cf_sql_date" value="#DateFormat(DateAdd('d', 1, ARGUMENTS.endDate), 'yyyy-mm-dd')# 00:00:00">
</CFIF>
AND c.LocationID = <CFQUERYPARAM cfsqltype="cf_sql_integer" value="#ARGUMENTS.locationID#">
AND c.CustomerID = <CFQUERYPARAM cfsqltype="cf_sql_integer" value="#ARGUMENTS.customerID#">
</CFQUERY>
All of this worked just fine before I added the lines:
<CFIF IsDefined("ARGUMENTS.encounter") AND IsObject(ARGUMENTS.encounter)>
AND c.EncounterID = <CFQUERYPARAM cfsqltype="cf_sql_integer" value="#ARGUMENTS.encounter.getID()#">
<CFELSE>
AND c.DateTimeClosed >= <CFQUERYPARAM cfsqltype="cf_sql_date" value="#ARGUMENTS.startDate#">
AND c.DateTimeClosed < <CFQUERYPARAM cfsqltype="cf_sql_date" value="#DateFormat(DateAdd('d', 1, ARGUMENTS.endDate), 'yyyy-mm-dd')# 00:00:00">
</CFIF>
Previously, it had just been:
AND c.DateTimeClosed >= <CFQUERYPARAM cfsqltype="cf_sql_date" value="#ARGUMENTS.startDate#">
AND c.DateTimeClosed < <CFQUERYPARAM cfsqltype="cf_sql_date" value="#DateFormat(DateAdd('d', 1, ARGUMENTS.endDate), 'yyyy-mm-dd')# 00:00:00">
With no IF/ELSE statement.
Anyone seen anything like this before? Any ideas?
Thanks.Right, I'll start disabusing myself of the DateFormat!
I'm sorry, I should've posted the actual query too. It's inserting the first part - "AND c.EncounterID = ....."
Here's the full query:
LOCAL.getEncounterServices (Datasource=xmddevdb, Time=9ms, Records=0) in /Applications/ColdFusion9/wwwroot/XMD_NEW/xmd_dev/cfc/ShoppingGateway.cfc @ 16:56:28.028
SELECT
a.EncounterProductID,
a.DateTime AS ServiceDate,
aa.CartItemID,
aaa.CartID,
aaaaa.CartStatus,
b.ProductID,
b.ProductName,
b.CPTCode,
b.Price,
c.EncounterID,
c.DateTimeClosed AS EncounterClosedDate,
d.FirstName,
d.LastName
FROM
EncounterProducts a
LEFT JOIN CartItemProduct aa ON (a.EncounterProductID = aa.EncounterProductID AND aa.Active = 1)
LEFT JOIN CartItem aaa ON (aa.CartItemID = aaa.CartItemID)
LEFT JOIN Cart aaaa ON (aaa.CartID = aaaa.CartID)
LEFT JOIN CartStatus aaaaa ON (aaaa.CartStatusID = aaaaa.CartStatusID),
Product b,
Encounters c,
Contacts d,
EncounterStatuses e
WHERE
1 = 1
AND (aa.CartItemID IS NULL OR aaaaa.CartStatus = 'Deleted')
AND a.Active = 1
AND a.ProductID = b.ProductID
AND a.EncounterID = c.EncounterID
AND c.PatientID = d.ContactID
AND c.EncounterStatusID = e.EncounterStatusID
AND e.EncounterStatus = 'Closed'
AND c.EncounterID = ?
AND c.LocationID = ?
AND c.CustomerID = ?
Query Parameter Value(s) -
Parameter #1(cf_sql_integer) = 28
Parameter #2(cf_sql_integer) = 16
Parameter #3(cf_sql_integer) = 6
Thansk again for the help! -
Search query returning ALL records
DW CS3 - MS Access - ASP/VBScript
I have a search form for records to display on the same page with keywords highlighted. The search is returning ALL records and highlighting keywords throughout rather than returning specific records with the searched word. What am I missing? I'm sure it's something terribly simple.....
<input name="search" type="text" id="search" value="<%= Request.QueryString("search") %>" />
SELECT item, item, item, item
FROM tbl_name
WHERE item OR item OR item LIKE %MMColParam%
ORDER BY sql_orderby, Date DESC
Name: MMColParam
Type: Text
Value: Request.Querystring("search")
Default Value: %I was using the word "item" as an example for multiple columns without actually naming them - they are not the same. I should've used this example:
SELECT shoes, socks, hats, gloves
FROM tbl_apparel
WHERE shoes OR socks OR hats LIKE %MMColParam%
ORDER BY sql_orderby, Date DESC
In the past, I had four duplicate query parameters for four columns which worked fine. But since I only have one search term, I thought I could eliminate three of the duplicate parameters and use just one with the OR statement.
In the past, you questioned me on this. You stated, "You only have one search term and so all of the parameters have the same value, but DW still wants to creates 4 parameters. If you were coding this by hand you wouldn't do it that way, but DW's one-size-fits-all code generates four seperate parms. It's nothing to worry about." -
URGENT Select Query Returning No Records take same time as that of insert
Hello Everrybody,
I am facing a wierd problem...
I have table with 15 fields and I am selecting a record with some condition...
for e.g
select field1,field2,field3....... from tablea where field1=123
Now I have index on field1
When I do SQL Trace it show me time taken as
00:00:00:60 in oracle 817 SQL PLUS
and using
oracle 92 sql plus it show as
00:00:00:01 in oracle 817 SQL PLUS
Now Query is what does this 60 denotes milliseconds or what in oracle 92 and in oracle 817 sql plus.....
Also this query does not return any rows...
When I run the SP that insert records in same table...That sp take about same time as that of select returning no rows......
Why is ORACLE Taking so much time for that select ????
Please help.....8i measures timings in 100th of a second but I believe that 9i measures stuff in 1000th of a second. However, from your output it looks like SQL*Plus trace is rounding up to the nearest centisecond.
Time is a very poor way of judging performance when you're talking less than a second per operation. You'd be better off looking at CPU usage and IO activity.
Anyway, here are some questions for you to research:
(1) Is field1 a unique index?
(2) How many rows does this table hold?
(3) How fresh are the statistics on the table and the index?
(4) What's the explain plan? What's the TKPROF output?
(5) Are all of the above the same on both databases?
Cheers, APC -
Query returning more records ...
Hi All,
I am having a bit issues here. I have three tables and i am trying following query and it is returning 7 rows but I am expecting one row to return -
>
select distinct l.olic_id, b.obat_id, l.olic_key
from op_licences l, op_batches b, op_licence_batches ba
where BA.OBAT_ID = b.obat_id
and l.olic_id = ba.olic_id
and l.olic_key='HQ67138'
>
Getting the following result:
>
OLIC_ID OBAT_ID OLIC_KEY
2 3 HQ67138
2 1468 HQ67138
2 1469 HQ67138
2 1470 HQ67138
2 1471 HQ67138
2 1472 HQ67138
2 1473 HQ67138
7 rows returned in 0.14 seconds
>
I also have tried to use outer join and inner join but still does not work. Can any body tell me how can I get one record instead of 7?
Thanks in advance,
Regards,
M Tajuddini am trying following query and it is returning 7 rows but I am expecting one row to returnYou are getting seven different rows so clearly your query is not as selective as it ought to be. Which of those rows is the one you're expecting? Given that, you need to look at the source data and establish the additional criteria you need in order to filter out the other six rows. It looks like OBAT_ID is the troublesome part.
Given that these are your tables and your business rules there is absolutely no chance that we will be able to solve this for you.
Cheers, APC
blog: http://radiofreetooting.blogspot.com -
SAP query returning duplicate records
Hi all,
I'll try to elaborate as much as possible so here goes:
I have a query that I am trying to run in SAP B1 8.8 which is not returning the true set of results I am expecting.
Essentially I am trying to filter by product based on delivery notes. I have the query as follows -
SELECT count(*), sum(T0.[DocTotal]-T0.[VatSum]) as "Order Value"
FROM ODLN T0 INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode
WHERE DateName(mm,T0.DocDate) = 'November'
and DateName(yyyy,T0.DocDate) = '2011'
and (T1.[GroupCode] = '102' or T1.[GroupCode] = '107')
This returns the correct result of 1320 row numbers and the given sum.
When I try to break this query down further by product using the query below, the values are doubled, tripled, quadrupled etc and summed up to give a number that is extremely high.
The code is as follows:
SELECT distinct count (*), sum(distinct T0.[DocTotal]-T0.[VatSum]) as "Order Value" from DLN1 T1
inner join ODLN T0 on T0.DocEntry = T1.DocEntry
Inner join OITM T2 on T2.ItemCode = T1.ItemCode
inner join OCRD T3 on T0.CardCode = T3.CardCode
WHERE DateName(mm,T0.DocDate) = 'November'
and DateName(yyyy,T0.DocDate) = '2011'
and (T3.[GroupCode] = '102' or T3.[GroupCode] = '107')
and (T2.[ItmsGrpCod] = '108' or T2.[ItmsGrpCod] = '112' or T2.[ItmsGrpCod] = '115')
This also returns 1819 rows where there should be less based on the product.
Please let me know if I am not explaining myself well or need further clarification.
Thanks!hi,
try to run this code from your SQL management studio
SELECT SUM(T0.DocTotal - T0.VatSum) AS [Order Value], T0.DocTotal - T0.VatSum AS [Order Value], T0.DocNum, T0.DocDate, T0.CardCode, T0.CardName, T0.DocTotal,
T1.ItemCode, T1.Dscription, T1.Quantity, T2.GroupCode, T3.ItmsGrpCod
FROM ODLN AS T0 INNER JOIN
DLN1 AS T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
OCRD AS T2 ON T0.CardCode = T2.CardCode INNER JOIN
OITM AS T3 ON T1.ItemCode = T3.ItemCode
GROUP BY T0.DocTotal - T0.VatSum, T0.DocNum, T0.DocDate, T0.CardCode, T0.CardName, T0.DocTotal, T1.ItemCode, T1.Dscription, T1.Quantity, T2.GroupCode,
T3.ItmsGrpCod
HAVING (T2.GroupCode = 102 OR
T2.GroupCode = 107) AND (T3.ItmsGrpCod = 108 OR
T3.ItmsGrpCod = 112 OR
T3.ItmsGrpCod = 115) AND (T0.DocDate BETWEEN CONVERT(DATETIME, '2011-11-01 00:00:00', 102) AND CONVERT(DATETIME, '2011-11-17 00:00:00', 102))
regards,
Fidel -
CONNECT BY QUERY returns different count of rown in 10g resp. 11g databases
Folks,
I just spot a bellow issue in our databases.
1.) 10g database:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.5.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> select * from global_name;
SQL> SELECT ROWNUM
2 FROM dual
3 CONNECT BY ROWNUM <= 2;
ROWNUM
1
2
3
SQL> 2. 11g database
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select * from global_name;
SQL> SELECT ROWNUM
2 FROM dual
3 CONNECT BY ROWNUM <= 2;
ROWNUM
1
2
SQL> As you can see in 10g above query returns 3 records, in 11g only 2.
Why it's like that? Can it be somehow set, to produce the same output?
Many thanks,
TomasI get correct rows on both database version !
Oracle Versions
10g 10.2.0.1.0
11g 11.1.0.6.0
SQL> select rownum from dual connect by rownum <= 2;
ROWNUM
1
2
SQL> select * from v$version ;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> select rownum from dual connect by rownum <= 2;
ROWNUM
1
2
SQL> select * from v$version ;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
PL/SQL Release 11.1.0.6.0 - Production
CORE 11.1.0.6.0 Production
TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 - Production -
WKT polygon returns extra records on intersect query
We have spatially enabled table with min/max lat/long with 1 degree cell data on which we perform queries coming from an application using well known text. We need to use WKT because we need to support user defined shapes of point, line, polygon, etc. (My test cases uses a rectangle). Our WKT data is accurate to 4 decimal places.
//WKT version returns 100 records: (this is bad result)
SELECT COUNT(*) from (select * from MAP_TABLE WHERE series='downunder') where sdo_relate(geometry,sdo_util.rectify_geometry(mdsys.sdo_geometry
('POLYGON((117.0627 -31.8451,117.0627 -27.0075,134.5875 -27.0075, 134.5875 -31.8451, 117.0627 -31.8451)))',8307),0.00005),'mask=anyinteract,querytype=window') = 'TRUE'
// array version returns 90 records: (this is expected result)
SELECT COUNT(*) from (select * from MAP_TABLE WHERE series='downunder') where sdo_relate(geometry,mdsys.sdo_geometry(2003,8307,null,mdsys.sdo_elem_info_array(1,1003,3),
mdsys.sdo_ordinate_array(117.0627, -31.8451,134.5875,-27.0007)),'mask=anyinteract,querytype=window') = 'TRUE'
The WKT seems to return extra records as if a .5 rounding error on the spatial query. We checked for tolerance; in USER_SDO_GEOM_METADATA, SDO_TOLERENCE for lon and lat in DIMINFO column are set to .0000005, and SRID of 8307, and the spatial index for the table has been recreated with .0000005 (just in case).
Why is WKT not accurate?Hi Mike,
Well, I'll be the first to line up and say that the WKT implementation has some issues. You already know them as you are doing that rectify_geometry step to account for some of them (incorrectly rotated rings which is what your example has).
Noel is right that your example is not pushing along your case since an optimized rectangle is not the same as a regular rectangle, particularly in a geodetic cs. And that is one tiny tolerance in the rectify step! Is all your data at that tolerance? That's 0.0019685 inches! Wikipedia says the width of a human hair is 0.003937 inches so your tolerance is 1/3 of the width of a human hair. :)
Anyhow, the second link Noel posted has the blurb we want: "When Spatial constructs the MBR internally for the query, lines along latitude lines are densified by adding points at one-degree intervals. This might affect results for objects within a few meters of the edge of the MBR (especially objects in the middle latitudes in both hemispheres)." So your optimized rectangle when its used internally by Oracle spatial looks like the results from this query:
SELECT
SDO_CS.TRANSFORM(
MDSYS.SDO_GEOMETRY(2003,8307,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,3),MDSYS.SDO_ORDINATE_ARRAY(117.0627, -31.8451,134.5875,-27.0007)),
8307
FROM
dualSo you can probably expect some differences in query results in comparison to the four point rectangle that your WKT input creates. And certainly will happen at the follicle scale!
Could you post a different example that does not use an optimized rectangle where the SDO and WKT produce different outputs?
If your data is stored as WKT, how did an optimized rectangle get into this story in the first place? If you need to store an optimized rectangle as WKT - well you can't do that. You could do the above transform trick on any optimized rectangles in your data and then put all the resulting points into your WKT. Then things should match on the output query side. But that would mean chucking out the whole concept of optimized triangles from your dataset.
Cheers,
Paul -
Need help writing a MySQL query that will return only records with matching counter-parts
Since I don't know how to explain this easily, I'm using the
table below as an example.
I want to create a MySQL query that will return only records
that have matching counter-parts where 'col1' = 'ABC'.
Notice the 'ABC / GHI' record does not have a
counter-matching 'GHI / ABC' record. This record should not be
returned because there is no matching counter-part. With this
table, the 'ABC / GHI' record should be the only one returned in
the query.
How can I create a query that will do this?
id | col1 | col2
1 | ABC | DEF
2 | DEF | ABC
3 | ABC | GHI
4 | DEF | GHI
5 | GHI | DEF
*Please let me know if you have no idea what I'm trying to
explain.AngryCloud wrote:
> Since I don't know how to explain this easily, I'm using
the table below as an
> example.
>
> I want to create a MySQL query that will return only
records that have
> matching counter-parts where 'col1' = 'ABC'.
>
> Notice the 'ABC / GHI' record does not have a
counter-matching 'GHI / ABC'
> record. This record should not be returned because there
is no matching
> counter-part. With this table, the 'ABC / GHI' record
should be the only one
> returned in the query.
>
> How can I create a query that will do this?
>
>
> id | col1 | col2
> --------------------
> 1 | ABC | DEF
> 2 | DEF | ABC
> 3 | ABC | GHI
> 4 | DEF | GHI
> 5 | GHI | DEF
>
>
> *Please let me know if you have no idea what I'm trying
to explain.
>
Please be more clear. You say that 'ABC / GHI' should not be
returned,
and then you say that 'ABC / GHI' should be the only one
returned. Can't
have both... -
Query is returning multiple records for a bank account id and party id
Hi All,
I am not getting why this query is returning multiple records for a particular bank account id and party id:
SELECT instrument_payment_use_id
,instrument_type
,instrument_id
,start_date
,ext_pmt_party_id
FROM iby_pmt_instr_uses_all
WHERE instrument_id =:lv_num_ext_bank_account_id
and exists (select 1 from iby_external_payees_all b where PAYEE_PARTY_ID= :lv_num_party_id and b.ext_payee_id = ext_pmt_party_id)
I want above values to be used in api iby_disbursement_setup_pub.set_payee_instr_assignment in R12.
Please help asap.
ThanksO/P of query run for
SELECT rowid, instrument_payment_use_id
FROM iby_pmt_instr_uses_all
WHERE instrument_id =6642
AND EXISTS (
SELECT 1
FROM iby_external_payees_all b
WHERE payee_party_id= 85470
AND b.ext_payee_id = ext_pmt_party_id);
is below:
Rowid INSTRUMENT_PAYMENT_USE_ID
AABiDXAGIAABhiKAAS 236586
AABiDXAGRAABSjtAAz 148437
The version is R12 -
Oracle:JDBC Call returns no results, SQL*Plus returns 1 record, Please help
Any help would be greatly appreciated.
Running 9.2.0.5.0, and using latest 9.2 JDBC 1.4_g drivers in thin mode.
Execute the following query from SQL*Plus and it returns one row, from JDBC using a PreparedStatement, I get no results. Here's the query, table def, record, etc.:
Query:
SELECT
ID_WEB_FRM,ID_WEB_SIT,CDE_LVL_1_FUNC,
CDE_LVL_2_FUNC,NUM_WEB_FUNC_PG,NUM_WEB_PG_ID
FROM
WEB_FRM
WHERE
ID_WEB_FRM = ' '
OR
(ID_WEB_SIT = 'test' AND CDE_LVL_1_FUNC = ' '
AND CDE_LVL_2_FUNC = 'u2T' AND NUM_WEB_FUNC_PG = 1
AND NUM_WEB_PG_ID = 0)
Record returned from SQL*Plus:
ID_WEB_FRM ID_WEB_SIT CDE CDE NUM_WEB_FUNC_PG NUM_WEB_PG_ID
NfRRmc5XZu test u2T 1 0
Both in the data returned and the query, there are no blanks, but they are a single space instead (hard to see in message here).
Java code:
int count = 1;
findDBNameStatement.setString(count++," ");
findDBNameStatement.setString(count++,form.getSiteID());
findDBNameStatement.setString(count++," ");
findDBNameStatement.setString(count++, form.getFunctionID());
findDBNameStatement.setInt(count++,form.getPageNumber());
findDBNameStatement.setInt(count++,form.getSectionNumber());
ResultSet resultSet = findDBNameStatement.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
resultSet.next() returns false
DB table:
CREATE TABLE web_frm (
ID_WEB_FRM varchar2(10) NOT NULL,
ID_WEB_SIT varchar2(20) NOT NULL,
NAM_WEB_FRM varchar2(40),
TXT_EMAIL_SUBJ varchar2(50),
CDE_LVL_1_FUNC char(3),
CDE_LVL_2_FUNC char(3) NOT NULL,
NUM_WEB_FUNC_PG int NOT NULL,
NUM_WEB_PG_ID smallint NOT NULL,
DTE_WEB_FRM_EFF date NOT NULL,
DTE_WEB_FRM_TRM date,
CDE_VLDT_RUL char(3),
DTE_LAST_EXPRT date,
TXT_CNFRMN_MSG varchar2(4000),
IND_UPDT_ALWD char(1) NOT NULL,
TXT_RECAP_HDR varchar2(4000),
TXT_RECAP_FTR varchar2(4000),
CDE_WEB_OBJ char(3),
NUM_MAX_FRM_WIDTH number(4,0),
IND_RECAP_PG char(1) NOT NULL,
IND_CNFRM_PG char(1) NOT NULL,
IND_DSPL_CNFRM_NUM char(1) NOT NULL,
CNT_SUBM_MAX int,
TXT_CHCE_ADD_MSG varchar2(255),
TXT_CHCE_MOD_MSG varchar2(255),
TXT_WEB_HDR varchar2(4000),
TXT_WEB_FTR varchar2(4000),
TXT_WAIT_LIST_MSG varchar2(255),
FORMOBJECTHEIGHT int NOT NULL,
FORMOBJECTWIDTH int NOT NULL
ALTER TABLE web_frm ADD ( CONSTRAINT PK_web_frm PRIMARY KEY (ID_WEB_FRM));
ALTER TABLE web_frm ADD ( CONSTRAINT UK_web_frm UNIQUE (ID_WEB_SIT,CDE_LVL_1_FUNC,CDE_LVL_2_FUNC,NUM_WEB_FUNC_PG,NUM_WEB_PG_ID)) ;
Thanks,
MattThat's not quite right. From the javadocs:
next
public boolean next()
throws SQLException
Moves the cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.
If an input stream is open for the current row, a call to the method next will implicitly close it. A ResultSet object's warning chain is cleared when a new row is read.
Returns:
true if the new current row is valid; false if there are no more rows
Throws:
SQLException - if a database access error occurs -
JDBC Call returns no results, SQL*Plus returns 1 record, Please help!
Any help would be greatly appreciated.
Running 9.2.0.5.0, and using latest 9.2 JDBC 1.4_g drivers in thin mode.
Execute the following query from SQL*Plus and it returns one row, from JDBC using a PreparedStatement, I get no results. Here's the query, table def, record, etc.:
Query:
SELECT
ID_WEB_FRM,ID_WEB_SIT,CDE_LVL_1_FUNC,
CDE_LVL_2_FUNC,NUM_WEB_FUNC_PG,NUM_WEB_PG_ID
FROM
WEB_FRM
WHERE
ID_WEB_FRM = ' '
OR
(ID_WEB_SIT = 'test' AND CDE_LVL_1_FUNC = ' '
AND CDE_LVL_2_FUNC = 'u2T' AND NUM_WEB_FUNC_PG = 1
AND NUM_WEB_PG_ID = 0)
Record returned from SQL*Plus:
ID_WEB_FRM ID_WEB_SIT CDE CDE NUM_WEB_FUNC_PG NUM_WEB_PG_ID
NfRRmc5XZu test u2T 1 0
Both in the data returned and the query, there are no blanks, but they are a single space instead (hard to see in message here).
Java code:
int count = 1;
findDBNameStatement.setString(count++," ");
findDBNameStatement.setString(count++,form.getSiteID());
findDBNameStatement.setString(count++," ");
findDBNameStatement.setString(count++, form.getFunctionID());
findDBNameStatement.setInt(count++,form.getPageNumber());
findDBNameStatement.setInt(count++,form.getSectionNumber());
ResultSet resultSet = findDBNameStatement.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
resultSet.next() returns false
DB table:
CREATE TABLE web_frm (
ID_WEB_FRM varchar2(10) NOT NULL,
ID_WEB_SIT varchar2(20) NOT NULL,
NAM_WEB_FRM varchar2(40),
TXT_EMAIL_SUBJ varchar2(50),
CDE_LVL_1_FUNC char(3),
CDE_LVL_2_FUNC char(3) NOT NULL,
NUM_WEB_FUNC_PG int NOT NULL,
NUM_WEB_PG_ID smallint NOT NULL,
DTE_WEB_FRM_EFF date NOT NULL,
DTE_WEB_FRM_TRM date,
CDE_VLDT_RUL char(3),
DTE_LAST_EXPRT date,
TXT_CNFRMN_MSG varchar2(4000),
IND_UPDT_ALWD char(1) NOT NULL,
TXT_RECAP_HDR varchar2(4000),
TXT_RECAP_FTR varchar2(4000),
CDE_WEB_OBJ char(3),
NUM_MAX_FRM_WIDTH number(4,0),
IND_RECAP_PG char(1) NOT NULL,
IND_CNFRM_PG char(1) NOT NULL,
IND_DSPL_CNFRM_NUM char(1) NOT NULL,
CNT_SUBM_MAX int,
TXT_CHCE_ADD_MSG varchar2(255),
TXT_CHCE_MOD_MSG varchar2(255),
TXT_WEB_HDR varchar2(4000),
TXT_WEB_FTR varchar2(4000),
TXT_WAIT_LIST_MSG varchar2(255),
FORMOBJECTHEIGHT int NOT NULL,
FORMOBJECTWIDTH int NOT NULL
ALTER TABLE web_frm ADD ( CONSTRAINT PK_web_frm PRIMARY KEY (ID_WEB_FRM));
ALTER TABLE web_frm ADD ( CONSTRAINT UK_web_frm UNIQUE (ID_WEB_SIT,CDE_LVL_1_FUNC,CDE_LVL_2_FUNC,NUM_WEB_FUNC_PG,NUM_WEB_PG_ID)) ;
Thanks,
MattI have verified the parameters and such, and if I run as a Statement instead of a PreparedStatement, the query works fine. After some more troubleshooting, I narrowed the problem down, but not sure of the fix.
If I eliminate teh extra parameters and simplify things to:
SELECT ID_WEB_FRM FROM WEB_FRM WHERE ID_WEB_SIT = 'test' AND CDE_LVL_2_FUNC = 'u2T' AND NUM_WEB_FUNC_PG = 1 AND NUM_WEB_PG_ID = 0
The code works. But if I add the additional WHERE clause of CDE_LVL_1_FUNC = ' ' (has single space), it returns no data (record in the DB has single space in this new column. Query that does not work:
SELECT ID_WEB_FRM FROM WEB_FRM WHERE ID_WEB_SIT = 'test' AND CDE_LVL_1_FUNC = ' ' AND CDE_LVL_2_FUNC = 'u2T' AND NUM_WEB_FUNC_PG = 1 AND NUM_WEB_PG_ID = 0
It appears the JDBC Driver is trimming the parameter when it is a space when set through a PreparedStatement.setString(2," ") -
Global Temp Table, always return zero records
I call the procedure which uses glbal temp Table, after executing the Proc which populates the Global temp table, i then run select query retrieve the result, but it alway return zero record. I am using transaction in order to avoid deletion of records in global temp table.
whereas if i do the same thing in SQL navigator, it works
Cn.ConnectionString = Constr
Cn.Open()
If FGC Is Nothing Then
Multiple = True
'Search by desc
'packaging.pkg_msds.processavfg(null, ActiveInActive, BrandCode, Desc, Itemtype)
SQL = "BEGIN packaging.pkg_msds.processavfg(null,'" & _
ActiveInActive & "','" & _
BrandCode & "','" & _
Desc & "','" & _
Itemtype & "'); end;"
'Here it will return multiple FGC
'need to combine them
Else
'search by FGC
SQL = "BEGIN packaging.pkg_msds.processavfg('" & FGC & "','" & _
ActiveInActive & "','" & _
BrandCode & "',null,null); end;"
'will alway return one FGC
End If
' SQL = " DECLARE BEGIN rguo.pkg_msds.processAvedaFG('" & FGC & "'); end;"
Stepp = 1
Cmd.Connection = Cn
Cmd.CommandType = Data.CommandType.Text
Cmd.CommandText = SQL
Dim Trans As System.Data.OracleClient.OracleTransaction
Trans = Cn.BeginTransaction()
Cmd.Transaction = Trans
Dim Cnt As Integer
Cnt = Cmd.ExecuteNonQuery
'SQL = "SELECT rguo.pkg_msds.getPDSFGMass FROM dual"
SQL = "select * from packaging.aveda_mass_XML"
Cmd.CommandType = Data.CommandType.Text
Cmd.CommandText = SQL
Adp.SelectCommand = Cmd
Stepp = 2
Adp.Fill(Ds)
If Ds.Tables(0).Rows.Count = 0 Then
blError = True
BlComposeXml = True
Throw New Exception("No Record found for FGC(Finished Good Code=)" & FGC)
End If
'First Row, First Column contains Data as XML
Stepp = 0
Trans.Commit()Hi,
This forum is for Oracle's Data Provider and you're using Microsoft's, but I was curious so I went ahead and tried it. It works fine for me. Here's the complete code I used, could you point out what are you doing differently?
Cheers,
Greg
create global temporary table abc_tab(col1 varchar2(10));
create or replace procedure ins_abc_tab(v1 varchar2) as
begin
insert into abc_tab values(v1);
end;
using System;
using System.Data;
using System.Data.OracleClient;
class Program
static void Main(string[] args)
OracleConnection con = new OracleConnection("data source=orcl;user id=scott;password=tiger");
con.Open();
OracleTransaction txn = con.BeginTransaction();
OracleCommand cmd = new OracleCommand("begin ins_abc_tab('foo');end;", con);
cmd.Transaction = txn;
cmd.ExecuteNonQuery();
cmd.CommandText = "select * from abc_tab";
OracleDataAdapter da = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
Console.WriteLine("rows found: {0}", ds.Tables[0].Rows.Count);
// commit, cleanup, etc ommitted for clarity
} -
Multi-row sub query returns ORA-00904 :invalid identifier error
I am creating a report from two tables that I am not joining. I want a single line for every row in table1 that meets a date range. Table2 can contain none or many rows for each recored in table1. I want to get up to two fields from table2.
I was using a case statement to check if there was data and then an in-line query or subquery. Once again, the idea is to have a single line on the report for each table1 record.
I get this error with the code below. It seems the nested multi-row subquery can not see the a.cr_mas_cr_no identifier.
ORA-00904: "a"."cr_mas_cr_no": invalid identifier
Any help is greatly appreciated,
Sam
select
a.cr_mas_cr_no "CRNO", a.cr_mas_type "TYPE", a.cr_mas_status "CR Status",
a.cr_mas_date_logged "Logged date", a.CR_REL_REQ_APP_DATE "RTP approved",a.CR_REL_REQ_RTP_DATE "RTP Date",
a.cr_accepted_date "Complete", a.cr_mas_submitted_by "Requester",
select doc_user FROM crrm_cr_documents WHERE doc_cr_number =a.cr_mas_cr_no and rownum = 1 and DOC_TYPE = 'BD' ) "Bus Design",
(select doc_user FROM crrm_cr_documents WHERE doc_cr_number = a.cr_mas_cr_no and rownum = 1 and DOC_TYPE = 'TD' ) "Tech Design",
(select doc_user FROM crrm_cr_documents WHERE doc_cr_number = a.cr_mas_cr_no and rownum = 1 and DOC_TYPE = 'TE' ) "User acceptance test",
case
when (select count(appr_user) from crrm_cr_approvals where appr_cr_no = a.cr_mas_cr_no and appr_type = 'RTP') > 0
then (select appr_user from (select * from crrm_cr_approvals where appr_cr_no = a.cr_mas_cr_no and appr_type = 'RTP') where rownum = 1)
end
"RTP #1",
case
when (select count(appr_user) from crrm_cr_approvals where appr_cr_no = a.cr_mas_cr_no and appr_type = 'RTP') > 1
then (select appr_user from (select * from crrm_cr_approvals where appr_cr_no = a.cr_mas_cr_no and appr_type = 'RTP') where rownum = 2)
end
"RTP #2",
a.CR_REL_REQ_RTP_BY "Released by",
a.CR_ACCEPTED_BY "Post RTP User Acceptance",
a.cr_mas_title "Title", a.cr_mas_id "ID"
from
crrm_crmaster a
where
(a.CR_REL_REQ_RTP_DATE >= :P1109_BEGDATE and (a.CR_REL_REQ_RTP_DATE <= :P1109_ENDDATE) and
(a.cr_mas_status = 'Complete' or (a.cr_mas_status = 'Release Approved'and a.CR_REL_REQ_APP_DATE < :P1109_ENDDATE))
Message was edited by:
slavanawayIceman,
Thanks for the reply I will try your suggestion.
I will try and explain why I think two subqueries (an in-line query with a subquery?) are required. I will use the creation of the column RTP #1 as the example as the RTP #2 column is only different in the rownum selected.
Looking only at the lines that fail, here is my analysis. (If I rem out the two case lines the query runs, I just don't get two columns of data I need.) I will only examine the first case as the second is changed to extract the second approval via the rownum = 2 criteria. The first statement checks there is at least one RTP approval stored for the request and then gets the user who approved the request if the test is true.
case when
(select count(appr_user) from crrm_cr_approvals where appr_cr_no =a.cr_mas_cr_no and appr_type = 'RTP') > 0
then
The above part works fine and the correct count of approvals is returned.
(select appr_user from (select * from crrm_cr_approvals where appr_cr_no=a.cr_mas_cr_no and appr_type = 'RTP') where rownum = 1)
end
"RTP #1",
I moved the parenthesis to the correct location. There can be multiple approvals for a given parent record. Some parent records need one, some need two approvals. If I replace
(select appr_user from (select * from crrm_cr_approvals where appr_cr_no =a.cr_mas_cr_no and appr_type = 'RTP') where rownum = 1)
with
(select appr_user from approvals where appr_cr_no =a.cr_mas_cr_no and appr_type = 'RTP' and rownum = 1)
The correct result is returned because it returns exactly one row as rownum=1 limits the query. When rownum = 2 then the query returns null as the rownum never gets to two as the rownum column is built via the set created by the second subquery.
The subquery builds a set of approvals for a specific "cr_no" and appr_type of "RTP". the outer query then looks at the rownum of the second query
Here is where I got the rownum information from;
http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
So here is what I think is happening;
1. Main query From and Where are processed. This should provide the "set" for the query
2.The from subqueries for RTP #1 and RTP #2 should be able to access the a.cr_mas_cr_no field and build a set from the approvals table.
3.The RTP #1/2 subquery (inline maybe a better description?) would then get the correct row from the from subquery.
The error "invalid identifier" refers to the a.cr_mas_cr_no field. I assume it means it can not resolve the table alias inside the subquery.
So maybe your grouping would help, I will try.
Sam
Maybe you are looking for
-
How to find to which table the net payment is posted....
Hi all i am making payment to a vendor for 3 different invoices in a single payment run (F-58) with cash discount.Now i could like to know that in which tabe the net amount for the all the 3 invoices were posted . eg: Invoice No Amt
-
Unassign Server from a Corrupted Oracle VM Manage 3.1.1 instance
My problem is that the Oracle Database holding the metadata of the VM Manager that currently owns my VM Server died completely and I'm unable to log in to the VM Manager to manage the VMs living in the Server. I have no (explicit) backup from the Man
-
they show up that way on iTunes when connected to the Nano, (in numerical order) but on the Nano, they're out of order. The shake to shuttle is off.
-
Hello Gurus. I want to develop a query in Bex Query Designer and I`m not having success. What I want to do is develop a query where in the lines I have the 0PLANT and 0CALDAY objects, and in the columns I want 0CALMONTH and one key figure for Quantit
-
Dear all, I have a new EP 6.0 installation running ESS/MSS and BW reporting and implemented central SLD.The SLD server was the CEN Solution Manager system. Because of some issues with support pack application in the solution manager system, the solut