Where clause fails
In my project I do a query using the folloqinf statement :
vPastiCDC totpasticdc_tab3_riga =
db.vPastiCDC.Where(
x =>
x.CDC == Cdc_considerato && x.Anno ==
Anno_considerato && x.Mese == Mese_considerato && x.Tipo == 3).FirstOrDefault();
but the results are not filtered correctly by the tipo Field.
What can be the problem?
Thanks in advance,
Simone
Hello Simone,
>>but the results are not filtered correctly by the tipo Field.
Since we do not know the exact result and your passed value, we do not know what happens in your LINQ query. For this issue, if it is possible, please share the vPastiCDC table and some sample data.
Or since you are using LINQ2SQL, you could use the SQL Server Profiler to track the executed T-SQL, for details, you could refer to this link:
http://msdn.microsoft.com/en-us/library/ms181091.aspx
If you do not have access to the server which installs the database, you could print the T-SQL in you application as:
using (DataClasses1DataContext db = new DataClasses1DataContext())
db.Log = Console.Out;
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.
Similar Messages
-
Dynamic where clause, user/row security
I haev two tables:
create table table1(
First_name varchar2(12),
Last_Name varchar2(17),
Middle_name varchar2(1),
Cabinet varchar2(2),
Department varchar2(3),
Division varchar2(2),
branch varchar2(2),
section varchar2(2),
unit varchar2(2),
serial varchar2(3),
job_title varchar2(13),
other fields......
create table security(
USERname VARCHAR2(14),
FIRST_NAME VARCHAR2(20),
PER_CABINET VARCHAR2(2),
PER_DEPT VARCHAR2(3),
PER_DIVISION VARCHAR2(2),
PER_BRANCH VARCHAR2(2),
PER_SECTION VARCHAR2(2),
PER_UNIT VARCHAR2(2),
PER_SERIAL VARCHAR2(2),
other fields....
****security table sample data****
username first_name cabinet dept division branch section unit serial
username1 firstname1 10 785 05 01 02
username2 firstname2 32 527 02 03
username3 firstname3 32 527 02 01
username4 firstname4 46 546 22 06 05
username5 firstname5 46 546 27 15 01
username6 firstname6 10 005 01 01 01 01
username7 firstname7 10 005 01 01 01 01
username8 firstname8 10
username9 firstname9 10 005
username10 firstname10 10 005 01
What I would like to do is, based on the values assigned to user in security table, the records from table1 should be fetched.
For example: (lets say there are 1000 records in table 1 for cabinet 10)
username8 should be able to see all records pertaining to cabinet 10. (record count=1000)
Username9 should be able to see all records pertaining to cabinet 10 and dept 005 (record count=800)
username10 should be able to see all records pertaining to cabinet 10 and dept 005 and division 01 (record count=600)
username1 should be able to see all records pertaining to cabinet 10 and dept 785 and division 05 and branch 01 and unit 02 (record count=10)
....and so on
To summarize I have to narrow down the number of records a user can see.
I tried to implement this using set_context each for cabinet, department etc... the problem is some users may not have all the values. so my where clause fails and returns 0 rows.
example:
select count(1) from table1 where cabinet=(select per_cabinet from security where username='username1') and department=(select per_dept from security where username='username1') and division=(select per_division from security where username='username1') and branch=(select per_branch from security where username='username1') and section=(select per_section from security where username='username1') and unit=(select per_unit from security where username='username1');
I would get 0 rwos because username1 does not have any value for section.
I point to keep in mind is that not all users have same values.
Any thoughts or ideas on how to resolve my problem? Thanks.By set_context, I hope you mean you are using sys_context and VPD/RLS for this filtering. For the filter condition, how about modifying each part in the form:
unit = nvl((select per_unit from security where username = :username), unit)or
unit = (select nvl(per_unit, unit) from security where username = :username) -
Query for Find Mode Fails-AutoGenerated WHERE clause missing quotation mark
Using Oracle JDev 10.1.3.2. In 'Find Mode' the query execution fails.
The error shown below is caused by the WHERE clause statement. The column name is quoted in the database but the code generated by the ADF framework does not use quotes. As a result the column name is illegal. Is there a way to hint to the ADF framework to ALWAYS use quotation marks?
(oracle.jbo.SQLStmtException) JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (SELECT "PLATE","WROW","WCOL","WFIELD","AVGNUC.NUC_CELL_INTENSITY","MEDNUC.NUC_CELL_INTENSITY","AVGORG.INCLUSION_BCKG_INTE","MEDORG.INCLUSION_BCKG_INTE","MEDORG.COUNT","MEDORG.SPACING","MEDORG.NEIGHBOR_COUNT" FROM ICSUMSTAS_1888_295) QRSLT WHERE ( ( (MEDORG.COUNT >0) ) )It is true that these are not the most column 'friendly' names, but they are what they are. In the database these columns are quoted and they must be so in order for the query to work correctly.
The suggestion of directly manipulating the View Criteria is a good one and I have implemented a solution based on it but it's cumbersome. Here is how it works:
First, use the default query mode UI to add new View Criteria. If you were to execute the query at this point it would fail due to the columns names not being quoted. So, instead, implemented my own execute query button that first uses the View Criteria to create a properly quoted WhereClause for the ViewObject.
I then reset the ViewCriteria (or they will interfere with the WhereClause), set the custom constructed WhereClause on the ViewObject, and re-execute the query. The cumbersome part is that I have to create my own parser for user input to write a valid WhereClause. And when the user uses query mode again the previously set ViewCriteria have been reset (which is annoying, and not the typical query mode behavior which might confuse the user)
below are some of my code snippets:
* This action is triggered by clicking the FIND button on the UI.
* It uses a combination of the ViewCriteria default UI and custom code that processes
* user input into a whereClause for the ViewObject
private void jbFind_actionPerformed(ActionEvent e) {
jbAddRow.setEnabled(false);
//reset old where clause
System.out.println("OLD WHERE:"+myView.getWhereClause());
myView.setWhereClause(null);
String customWhere=getCustomWhere();
/* The case for null and blank View Criteria is tested below
* when there are blank ViewCriteria the sequence (--) is generated from getCustomWhere
* Note the use of contains instead of equals
* The use of equalIgnoreCase etc for unexplained reasons seem to fail to detect when customWhere is (--)
if(customWhere==null||customWhere.contains("(--)")){
return;
}else{
/*remove ViewCriteria because they can not handle special Column names
* That's why we go into the trouble of creating our own find function
myView.getViewCriteria().removeAllElements();
myView.setWhereClause(customWhere);
myView.executeQuery();
jUNavigationBar1.doAction(JUNavigationBar.BUTTON_EXECUTE);
jTable1.revalidate();
private String getCustomWhere(){
StringBuffer custom=new StringBuffer();
ApplicationModule am = (ApplicationModule) panelBinding.getApplication().getDataProvider();
DCJboDataControl jbodc = new DCJboDataControl(am);
JUIteratorBinding iterBinding = new JUIteratorBinding(jbodc,myView );
int criteriaCount=iterBinding.getViewCriteria().getRowCount();
//Validation when no ViewCriteria are defined
if (criteriaCount==0){
System.out.println("ViewCriteria Count: "+criteriaCount);
return null;
}else{
System.out.println("ViewCriteria Count: "+criteriaCount);
int attr=iterBinding.getViewCriteria().getCurrentRow().getAttributeCount();
int criteriaRows=iterBinding.getViewCriteria().getAllRowsInRange().length;
String[] attrNames=iterBinding.getViewCriteria().getCurrentRow().getAttributeNames();
for (int r=0;r<criteriaRows;r++)
{custom.append("(");
for (int k=0;k<attr;k++){
if(iterBinding.getViewCriteria().getRowAtRangeIndex(r).getAttribute(k)!=null){
custom.append("(\""+attrNames[k]+"\"");// LIKE '"+(String)iterBinding.getViewCriteria().getRowAtRangeIndex(r).getAttribute(k)+"') AND ");
//trim white space
String attrK=((String)iterBinding.getViewCriteria().getRowAtRangeIndex(r).getAttribute(k)).trim();
String qual=attrK.substring(0,1);
if(qual.equalsIgnoreCase(">")||qual.equalsIgnoreCase("<")||qual.equalsIgnoreCase("=")||qual.equalsIgnoreCase("!")){
custom.append(" "+qual+"'"+attrK.substring(1)+"') AND " );
}else{
custom.append(" LIKE '"+(String)iterBinding.getViewCriteria().getRowAtRangeIndex(r).getAttribute(k)+"') AND ");
}custom.append("--");
custom.append(")");
custom.append(" OR ");
}//end criteria rows
custom.append("--");
//now need to remove terminal AND and OR tagged with --
String cleanWhere=custom.toString().replaceAll("AND --","").replaceAll("OR --","");
System.out.println("NEW CUSTOM WHERE: "+cleanWhere);
return cleanWhere;
} -
Hi All,
I have a column like lastdate with varchar datatype. now I want to work with lastdate column in where clause with getdate().
Ex: where
getdate() - lastdate < 1
when I use above one I got error like
Error = Conversion failed when converting date and/or
time from character string.
I knew the datatypes for lastdate and getdate() are different...
how can I use...
Thanks,
rupYou need to convert the string date to datetime or date. See conversion examples here:
http://www.sqlusa.com/bestpractices/datetimeconversion/
Example for the where clause:
WHERE DATEDIFF(DD, convert(datetime, lastdate, 101), getdate() ) < 1
Can you post sample string dates?
Are you looking for today's records? Another option (depends on lastdate format):
WHERE lastdate = convert(char(8), getdate(), 112)
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
OA Framework LOV – How to add where clause dynamically at runtime
Hi All,
Following is my page design:
MainAM (This is root Application module) Package is: mycompany.oracle.apps.<product>.<project>.server
MainPageVO (This is the View Object associated to Main AM)
LovAM (This Application module is for LOVs) Package is: mycompany.oracle.apps.<product>.<project>.lov.server
FileNameLovVO (This is the View Object is for "File Name" LOV. It is associated LovAM)
I my main page is attached to the "Main AM". In the main page, I have a custom search region and in that there is a messageLovInput type of field based on "FileNameLovVO". The field name is File Name.
Use Case:
When a user opens the page, I determine user type. If the use is a clerk (not a superuser) then I need to restrict values in my File Name LOV by setting where clause dynamically.
Issue1:
====
In the main page controller when I do following, OA Framework is not able to access the "FileNameLovVo".
1. Following code is from the main page's controller:
String userId = 100;
LovAMImpl lovAm = new LovAMImpl();
Serializable[] lovParameters = {userId};
Class[] lovParamTypes = { String.class };
lovAm.invokeMethod("initLovQuery", lovParameters, lovParamTypes);
2. In LovAMImpl class I have created following method:
public void initLovQuery(String useId)
FileNameLovVOImpl fileNameLovVo = getFileNameLovVO1(); // ******This returns NULL*******
if (fileNameLovVo == null)
MessageToken[] errTokens = { new MessageToken("OBJECT_NAME", "getFileNameLovVO1")};
throw new OAException("AK", "FWK_TBX_OBJECT_NOT_FOUND", errTokens);
fileNameLovVo.initQuery(userId);
In the above code "FileNameLovVOImpl fileNameLovVo = getFileNameLovVO1();" is returning NULL.
Please let me know what am I missing here.
I resolved above issue with following work around:
1. Attached "FileNameLovVO" to "MainAM"
2. Moved initLovQuery(String useId) method to "MainAMImpl" class.
Is that the correct way? I would prefer NOT to attach "FileNameLovVO" to "MainAM". Any suggestions?
Issue2:
====
After using above work around I tried to set WHERE clause dynamically:
FileNameLovVO is based on following SQL query:
SELECT DISTINCT file_name FROM <table> WHERE USER_ID like :1
I need to pass value for USER_ID if the user is a clerk and I need to pass '%' if the user is a supper user. I'm passing value in "LovVo.initQuery(userId)" method using following code:
public void initQuery(String userId)
StringBuffer whereClause = new StringBuffer(1000);
Vector parameters = new Vector(1);
int bindCount = 0;
setWhereClauseParams(null);
if ((userId != null) && (!("".equals(userId.trim()))))
parameters.addElement(servicerId);
whereClause.append(++bindCount);
if (bindCount > 0)
Object[] params = new Object[bindCount];
parameters.copyInto(params);
setWhereClauseParams(params);
executeQuery();
When I select LOV at runtime in the page, it fails with following error:
oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (SELECT DISTINCT file_name FROM <table> WHERE user_id LIKE :1) QRSLT WHERE (( UPPER(FILE_NAME) like :1 AND (FILE_NAME like :2 OR FILE_NAME like :3 OR FILE_NAME like :4 OR FILE_NAME like :5))) ORDER BY file_name desc
OA Framework tries to create following statement:
SELECT *
FROM (SELECT DISTINCT file_name
FROM <table>
WHERE user_id LIKE :1) qrslt
WHERE (( UPPER (file_name) LIKE :1
AND ( file_name LIKE :2
OR file_name LIKE :3
OR file_name LIKE :4
OR file_name LIKE :5
ORDER BY file_name DESC
Any help is greatly appreciated.
Thanks for your help guys.
MiteshI have a lovinput item which has an external LOV attached to it - the VO uses the below sql query. I want to display the addresses of the customer accounts belonging to the customer name or account entered. I have a PPR event in the account number field which is calling the onAccountNumber method in my AM - the method is getting triggered when you enter the account number and the vo returns the rowcount as 3 exactly but if you click the lovinput item - it brings back all the addresses available instead bringing back addresses beloning to the account number.
public void OnAccountNumber(String accountNumber,String partyName,
Boolean executeQuery)
System.out.println("Im here on account number" + accountNumber + " PartyName:" + partyName);
AddressVOImpl Addrvo= getAddressVO1();
Vector parameters = new Vector(2);
StringBuffer whereClause = new StringBuffer(100);
int clauseCount = 0;
int bindCount = 0;
Addrvo.setWhereClauseParams(null); // Always reset
if ((accountNumber != null) && (!("".equals(accountNumber.trim()))))
whereClause.append(" Account_Number = :");
whereClause.append(++bindCount);
parameters.addElement(accountNumber);
clauseCount++;
if ((partyName != null) && (!("".equals(partyName.trim()))))
if (clauseCount >0){
whereClause.append(" AND ");
whereClause.append(" Party_Name like :");
whereClause.append(++bindCount);
parameters.addElement(partyName);
clauseCount++;
Addrvo.setWhereClause(whereClause.toString());
if (bindCount >0)
Object[] params=new Object[bindCount];
parameters.copyInto(params);
Addrvo.setWhereClauseParams(params);
System.out.println("AddressVO:" + Addrvo.getQuery() );
//Addrvo.executeQuery();
System.out.println("Addr Cnt:" + Addrvo.getRowCount());
SQL used in VO
=========
SELECT hl.address1
|| ' '
|| hl.address2
|| ' '
|| hl.address3
|| ' '
|| hl.city
|| ' '
|| hl.postal_code
|| ' '
|| hl.state
|| ' '
|| hl.country address,
hca.account_number,hp.party_name
FROM hz_cust_accounts hca,
hz_cust_site_uses_all hcsu,
hz_cust_acct_sites_all hcs,
hz_party_sites hps,
hz_locations hl,
hz_parties hp
WHERE hcsu.cust_acct_site_id = hcs.cust_acct_site_id
AND hcs.party_site_id = hps.party_site_id
AND hps.location_id = hl.location_id
AND hca.cust_account_id = hcs.cust_account_id
AND hcsu.site_use_code = 'SHIP_TO'
AND hcsu.status = 'A'
AND hp.party_id = hps.party_id
AND hp.party_id = hca.party_id
-- AND account_number=6028
Can someone please tell me how to restrict the addresses lov to an entered account number or customer name?? -
SQL Strings in Where Clause - single quotes issue
All,
Im having issues related to SQL String literals when trying to deploy to flash. The complication works fine but I then get a message (see below) stating that a ; is missing. The SQL query and the iview runs fine when we use numeric values or do not apply a where clause on the table.
I am using Visual Composer that has been packaged with NW2004sSP7_Preview
VC & Flex Version: 645.7.0.3
The Error message is get is;
Error in executing a process for Flex compilation, Error 1033: ';' expected
(C:usrsapJ2EJC01j2eeclusterserver0GUIMachine_Business_Packagestest_48731FLEX_COMPILATION_FOLEDRAADCN.mxml:269)
Error 1205: The statement 'Test' is incomplete.
(C:usrsapJ2EJC01j2eeclusterserver0GUIMachine_Business_Packagestest_48731FLEX_COMPILATION_FOLEDRAADCN.mxml:269)
Failed to compile AADCN.mxml
When I goto the deployment file it has the below line;
<i>'<Request type="EXECUTE_RELATIONAL" system="BI_JDBC" system_type="SAP_BI_JDBC" maxrows="500" templateid="BIR_SQL"><Objects type="INPUT" shape="OBJ" role="INPUT"><Object type="INPUT_FIELD" id="SQL_STATEMENT" appName="SQL" mapped="0" value=""/></Objects><Objects type="OUTPUT" shape="SET" role="OUTPUT"><Object type="OUTPUT_FIELD" id="name" appName="name"/></Objects><Objects id="1" type="TEMPLATE_PARAMETER"><Object id="2" type="SQL" value="select name from pub.srcompany where name ='Test Company'"/></Objects></Request>';</i>
It seems that the parser for the flash deployment is prematurely finishing the parse when it hits the single quotation in the SQL string!
We had a similar error where if we had a carriage return in the SQL (e.g. between the from & the where clause) then the deployment parser was stating that the line finished prematurely. In the deployment file the carriage return forced a new line thus making the message incomplete. Removing the carriage return resolve that issue
The SQL Preview in the SQL Editor within VC works fine with the string literals in the where clause.
The functionality compiles & deploys in web dynpro however it does not return the results to the table
Questions
1:> Has anyone successfully used flash with string literals in the SQL where clause or had seen this issue in the past?
2:> Is there a setting to get the SQL working on Web dynpro for the information to be returned that I may have missed?
Any assistance would be greatly appreciated.
Best Regards,
Ian.Hey,
I have worked with SQL Editor a lot. Here's a how to guide I put together on it:
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/6339e7d4-0a01-0010-1c98-db00e52e989a
Let me know if that helps...
Prakash -
Error while using REMAP_TABLE and WHERE clause together in IMPDP
I am trying to move some records from a very large table to another small table.
I am facing trouble while using REMAP_TABLE and WHERE clause together in IMPDP.
Problem is data filter is not getting applied and all records are getting imported.
here is how I have simulated this. please advice.
CREATE TABLE TSHARRHB.TMP1
A NUMBER,
B NUMBER
begin
Insert into TSHARRHB.TMP1
(A, B)
Values
(1, 1);
Insert into TSHARRHB.TMP1
(A, B)
Values
(2, 2);
COMMIT;
end;
expdp system/password TABLES=tsharrhb.TMP1 DIRECTORY=GRDP_EXP_DIR DUMPFILE=TMP1.dmp REUSE_DUMPFILES=YES LOGFILE=EXP.log PARALLEL=8
impdp system/password DIRECTORY=GRDP_EXP_DIR DUMPFILE=TMP1.dmp LOGFILE=imp.log PARALLEL=8 QUERY='TSHARRHB.TMP1:"WHERE TMP1.A = 2"' REMAP_TABLE=TSHARRHB.TMP1:TMP3 CONTENT=DATA_ONLY
Import: Release 11.2.0.1.0 - Production on Fri Dec 13 05:13:30 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/********@GRD6.RBSG DIRECTORY=GRDP_EXP_DIR DUMPFILE=TMP1.dmp LOGFILE=SSD_93_TABLES_FULL_EXP.log PARALLEL=8 QUERY=TSHARRHB.TMP1:"WHERE TMP1.A = 2" REMAP_TABLE=TSHARRHB.TMP1:TMP3 CONTENT=DATA_ONLY
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "TSHARRHB"."TMP3" 5.421 KB 2 rows
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at 05:13:33
here I am expecting only 1 record to get imported but both the records are getting imported. please advice.The strange thing compared to your output is that I get an error when I have table prefix in the query block:
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/******** DUMPFILE=TMP1.dmp LOGFILE=imp.log PARALLEL=8 QUERY=SYSADM.TMP1:"WHERE TMP1.A = 2" REMAP_TABLE=SYSADM.TMP1:TMP3 CONTENT=DATA_ONLY
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
ORA-31693: Table data object "SYSADM"."TMP3" failed to load/unload and is being skipped due to error:
ORA-38500: Unsupported operation: Oracle XML DB not present
Job "SYSTEM"."SYS_IMPORT_FULL_01" completed with 1 error(s) at Fri Dec 13 10:39:11 2013 elapsed 0 00:00:03
And if I remove it, it works:
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/******** DUMPFILE=TMP1.dmp LOGFILE=imp.log PARALLEL=8 QUERY=SYSADM.TMP1:"WHERE A = 2" REMAP_TABLE=SYSADM.TMP1:TMP3 CONTENT=DATA_ONLY
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SYSADM"."TMP3" 5.406 KB 1 out of 2 rows
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at Fri Dec 13 10:36:50 2013 elapsed 0 00:00:01
Nicolas.
PS: as you can see, I'm on 11.2.0.4, I do not have 11.2.0.1 that you seem to use. -
To_Date function in the Where Clause
Hello All,
I'm having an issue using the to_date function that has me quite perplexed.
I have two varchar2 fields, one with a date value in the format Mon, DD YYYY, the other has a time value in the format HH:MI PM.
When I run my query one of the columns I retrieve looks like this TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM'). The two fields are concatenated together and converted to a date. This works fine.
My problem occurs when I attempt to apply the same logic to the where clause of the aforementioned query. e.g. when I add the following criteria to my query and TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM') <= sysdate I get an ORA-01843: not a valid month error.
To further illustrate my problem here are the two queries:
Select d4.adate, e4.atime, TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM')
from ....
where ....
The above query works.
Select d4.adate, e4.atime, TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM')
from ....
where ....
and TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM') <= sysdate
The second query does not work.
The tables used and the limiting criteria are identical, except for the last one.
Does anyone have any ideas why this could be happening.
erHello,
Check this out. It does work. Do cut n paste sample
data from your tables.
SQL> desc test
Name Null? Type
ID NUMBER
DDATE VARCHAR2(20)
DTIME VARCHAR2(20)
SQL> select * from test;
ID DDATE DTIME
1 Jan, 10 2006 12:32 PM
2 Mar, 11 2005 07:10 AM
3 Apr, 13 2006 03:12 AM
4 Nov, 15 2003 11:22 PM
5 Dec, 20 2005 09:12 AM
6 Oct, 30 2006 10:00 AM
7 Jan, 10 2006 12:32 PM
8 Apr, 11 2005 07:10 AM
9 May, 13 2006 03:12 AM
10 Sep, 15 2003 11:22 PM
11 Oct, 20 2005 09:12 AM
12 Dec, 30 2006 10:00 AM
12 rows selected.
SQL> select id, ddate, dtime,
2 to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM') AA,
A,
3 to_char(to_date(ddate||dtime,'Mon, DD YYYYHH:MI
MI PM'),'Mon, DD YYYYHH:MI PM') BB
4 from test;
ID DDATE DTIME
DTIME AA BB
1 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06 Jan, 10 200612:32 PM
2 Mar, 11 2005 07:10 AM
07:10 AM 11-MAR-05 Mar, 11 200507:10 AM
3 Apr, 13 2006 03:12 AM
03:12 AM 13-APR-06 Apr, 13 200603:12 AM
4 Nov, 15 2003 11:22 PM
11:22 PM 15-NOV-03 Nov, 15 200311:22 PM
5 Dec, 20 2005 09:12 AM
09:12 AM 20-DEC-05 Dec, 20 200509:12 AM
6 Oct, 30 2006 10:00 AM
10:00 AM 30-OCT-06 Oct, 30 200610:00 AM
7 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06 Jan, 10 200612:32 PM
8 Apr, 11 2005 07:10 AM
07:10 AM 11-APR-05 Apr, 11 200507:10 AM
9 May, 13 2006 03:12 AM
03:12 AM 13-MAY-06 May, 13 200603:12 AM
10 Sep, 15 2003 11:22 PM
11:22 PM 15-SEP-03 Sep, 15 200311:22 PM
11 Oct, 20 2005 09:12 AM
09:12 AM 20-OCT-05 Oct, 20 200509:12 AM
12 Dec, 30 2006 10:00 AM
10:00 AM 30-DEC-06 Dec, 30 200610:00 AM
12 rows selected.
SQL> select id, ddate, dtime,
to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
2 from test
3 where id > 3
4 and to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
') <= trunc(sysdate);
ID DDATE DTIME
DTIME TO_DATE(D
4 Nov, 15 2003 11:22 PM
11:22 PM 15-NOV-03
5 Dec, 20 2005 09:12 AM
09:12 AM 20-DEC-05
7 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06
8 Apr, 11 2005 07:10 AM
07:10 AM 11-APR-05
10 Sep, 15 2003 11:22 PM
11:22 PM 15-SEP-03
11 Oct, 20 2005 09:12 AM
09:12 AM 20-OCT-05
6 rows selected.
SQL> select id, ddate, dtime,
to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
2 from test
3 where id > 3
4 and to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
') <= sysdate;
ID DDATE DTIME
DTIME TO_DATE(D
4 Nov, 15 2003 11:22 PM
11:22 PM 15-NOV-03
5 Dec, 20 2005 09:12 AM
09:12 AM 20-DEC-05
7 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06
8 Apr, 11 2005 07:10 AM
07:10 AM 11-APR-05
10 Sep, 15 2003 11:22 PM
11:22 PM 15-SEP-03
11 Oct, 20 2005 09:12 AM
09:12 AM 20-OCT-05
6 rows selected.
-SriSorry Sri, but I fail to see what you mean. How is what you're doing any different than what I'm doing? -
Issue in select query with where clause
Hi guys,
I'm facing an issue while using select query with the where clause. When I'm selecting all the data from the table it returns the correct result. But when I'm using the where clause to get the specific rows from the table it returns no rows. But the data I'm trying to fetch using the where condition exists in the table.
Here is my query which causing the issue,
select * from mytable where myfield = 'myvalue'
But if I use the following query it returns the result correctly.
select * from mytable
Also the myfield value 'myvalue' exists in the table.
I have tried by running this query in both SQL Developer and SQL Plus. I have tried this query in mssql as well. It works perfectly and returns correct result sets for both the queries I have mentioned above. I'm unable to predict the issue as I'm new to ORACLE. Please help.
Thanks,
Ram.Hi Ram,
I experienced an issue similar to this with a varchar2 field. Some of our records had a hidden newline character at the end of them, which was making queries like the one below fail:
select * from employees
where email = '[email protected]'The best way I found to detect this was to use
select 'XX'||email||'XX' from employeesTo make sure that there were no newlines. But that is just a guess. If you could provide some example table data and the outputs of your selects, it would be helpful.
Jeff -
Using decode in where clause with user defined function
Hi,
I have a below query which is failing as the function in the decode taking all cust_account_id as input parameter instead of the one which satisfies the condition in the inner query.So please provide a solution how can i pass only the selected one.
SELECT hca.cust_account_id
FROM hz_cust_accounts hca
WHERE hca.org_id=FND_PROFILE.value('ORG_ID')
AND hca.cust_account_id = (SELECT DISTINCT hcasa.cust_account_id
FROM hz_cust_acct_sites_all hcasa
WHERE hcasa.cust_account_id =hca.cust_account_id
AND hca.org_id = hcasa.org_id)
AND DECODE (hca.status , 'A', xx_ar_cust_audit_pkg.get_ship_to_order_type(hca.cust_account_id)) IS NOT NULL
Thanks,
AbhilashI'm having to guess without access to your tables, but I think changing the IN to a join should produce the same results. The JOIN should be evaluated before applying the WHERE clause, so this may resolve your problem.
SELECT hca.cust_account_id
FROM hz_cust_accounts hca
INNER JOIN hz_cust_acct_sites_all hcasa
ON hcasa.cust_account_id = hca.cust_account_id
AND hca.org_id = hcasa.org_id
WHERE hca.org_id = FND_PROFILE.value('ORG_ID')
AND DECODE (hca.status , 'A', xx_ar_cust_audit_pkg.get_ship_to_order_type(hca.cust_account_id)) IS NOT NULLAlternately, you could next part of the query and break the DECODE into the parent so it is evaluated after the inner query. This is likely uglier from a performance standpoint, though:
SELECT cust_account_id
FROM
SELECT hca.cust_account_id, hca.status
FROM hz_cust_accounts hca
WHERE hca.org_id=FND_PROFILE.value('ORG_ID')
AND hca.cust_account_id = (SELECT DISTINCT hcasa.cust_account_id
FROM hz_cust_acct_sites_all hcasa
WHERE hcasa.cust_account_id =hca.cust_account_id
AND hca.org_id = hcasa.org_id)
WHERE DECODE (status , 'A', xx_ar_cust_audit_pkg.get_ship_to_order_type(cust_account_id)) IS NOT NULL; -
Query in the where clause is not allowed
Hi all,
I have a table m_vehicle that stores 1 or more than 1 rows of data for each person. But the partner's schema requires that 0 or 1 vehicle license plate data be sent with the xml file. I have the following nested select statement inside a bigger one and it does not work,
select xmlelement("VehicleLicensePlate",
(case when mv.lic_plate_state is not null then
xmlelement("PlateState", mv.lic_plate_state)
end), -- end of plate state
(case when mv.lic_plate_no is not null then
xmlelement("PlateNumber", xmlelement("ID", mv.lic_plate_no))
end),
(case when mv.lic_plate_year is not null then
xmlelement("PlateExpiryYear", mv.lic_plate_year)
end)
).extract('/*')
from m_vehicle mv where mv.mni_id = 1083650
and mv.seq_no = (select max(mv2.seq_no) from m_vehicle mv2
where mv2.mni_id = mv.mni_id) and mv.lic_plate_no is not null
But it works when I run it alone and gets the latest row for the person. It does not work either if I join this table with other tables. My root element select is from dual because I have to supply lots of SOAP and other artifacts in the xml. Is it because I have this root select from dual that the query in the where clause does not work? How do I make it work so that I get 0 or one row only from the table? My solution was to write a function that returns each part of the license plate data using dymanic sql and call it in the xmlelement function. It works but I would like to use plain sql instead.
Thanks.
BenBy the way, the error I get is this,
ERROR:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00216: invalid character 3 (0x3)
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 111
Ben -
Dynamic where clause in select query
Hi
I'm trying for a dynamic query and in the dynamic where clause i'm checking a field for constant.....for instance if i wanna to use WERKS EQ '0478' how to declare it in dync where clause. i tried for the following:
SELECT (TAB_FIELD) INTO TABLE DITAB UP TO 10 ROWS FROM (TAB_NAME) WHERE (CONDI).
heree CONDI = 'werks eq 0287' . in this case the query fails as the werks shud be equal to '0287' and not just 0287. How to handle this? i tried for the following
CONDI = 'werks eq " '0287' " ' but no luck as it is not a valid stmt as i knew.hi prabhu,
this is how u select dynamically...
DATA: COND(72) TYPE C,
ITAB LIKE TABLE OF COND.
PARAMETERS: CITY1(10) TYPE C, CITY2(10) TYPE C.
DATA WA TYPE SPFLI-CITYFROM.
CONCATENATE 'CITYFROM = ''' CITY1 '''' INTO COND.
APPEND COND TO ITAB.
CONCATENATE 'OR CITYFROM = ''' CITY2 '''' INTO COND.
APPEND COND TO ITAB.
CONCATENATE 'OR CITYFROM = ''' 'BERLIN' '''' INTO COND.
APPEND COND TO ITAB.
LOOP AT ITAB INTO COND.
WRITE COND.
ENDLOOP.
SKIP.
SELECT CITYFROM
INTO WA
FROM SPFLI
WHERE (ITAB).
WRITE / WA.
ENDSELECT.
regards,
sohi -
Using Parameters in SQL-Query not only in where clauses
Hi,
I try to use Publisher parameters in the SQL Query from a Data Set.
All of them have default values.
So far, this is no problem, unless I try to use such a parameter value as an ordinary attribute value:
>
select
case when (:pv_Group = 'no') then "DM15D_BETRIEBSTEIL"."BETR_TEIL"
else :pv_some_Text end as Betr_Teil,
case when (:pv_Group = 'no') then "DM15D_BETRIEBSTEIL"."SUVA_NR_FORM"
else :pv_some_Text end as Suva_Nr,
case when (:pv_Group = 'no') then "DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH"
else sum("DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") end as Vollbesch
from "GDWH05"
where
"DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in (:pv_nim100)
fetch first 65001 rows ONLY
>
The parameters 'pv_Group' and 'pv_nim100' are working fine. (when or where clauses)
The parameter 'pv_some_Text' unfortunately not. (simple literals)
When I try to validate the above SQL, I get the following Error:
<font color="red">
java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 46033] Datatype: 25 is not supported.
</font>
After use a cast function:
>
else CAST(:pv_some_Text AS CHARACTER)
>
I get this ERROR:
<font color="red">
java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 19002] Incorrect use of parameters. The parameters used in CAST cannot be resolved without ambiguity.
</font>
We use OBIEE 11.1.1.6.4 on a Win64-System.
Thank's for any help.Hi Alex,
let's leave away any unnecessary details.
This is the SQL, inserted in the window 'Edit Data Set' of BIP Data Model:
>
select
'--1' as Betr_Teil,
'--2' as Suva_Nr,
sum("GDWH05"."DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") as Vollbesch
from "GDWH05"
where
"DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in ('122-4.4')
fetch first 65001 rows ONLY
>
Everything is fine when I click OK, the script goes back to the metadata.
Let's try this script with bind values in ORACLE SQL Developer.
This SQL is the physical part, found in the OBIEE-Log (Log level 5), except the bind values. Therefore we find, in the where clause, the join. In the logical sql, we don't have to join, because it's handled in the Common Enterprise Information Model (CEIM)
>
with
sawith0 as
select
sum(t39617.ris_vollbesch) as c1
from
dm15d_betriebsteil t39455,
dm15k_ris_fakten_pro_btt_jhr t39617
where
t39455.id_betriebsteil = t39617.id_betriebsteil
and t39455.suva_nr_form = '122-4.4'
select
d1.c1 as c1,
d1.c2 as c2,
d1.c3 as c3
from
select
:pv_some_text as c1,
:pv_some_text as c2,
sum(d1.c1) as c3
from
sawith0 d1
d1
where
rownum <= 65001
>
This SQL works fine, even with bind values for 'pv_some_text'.
But, when using the following SQL in the BIP Data Model:
>
select
:pv_Text as Betr_Teil,
:pv_Text as Suva_Nr,
sum("GDWH05"."DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") as Vollbesch
from "GDWH05"
where
"DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in ('122-4.4')
fetch first 65001 rows ONLY
>
The following ERROR occurs:
<font color="red">java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 46008] Internal error: File server\Query\Optimizer\ServiceInterfaceMgr\Utility\Src\SQOIUTypeVisitor.cpp, line 643.</font>
In my opinion, either I use a wrong syntax, or BIP has a problem with parsing the script.
Thank you for your most welcome help. -
Export (expdp) with where clause
Hello Gurus,
I am trying to export with where clause. I am getting below error.
Here is my export command.
expdp "'/ as sysdba'" tables = USER1.TABLE1 directory=DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= “USER1.TABLE1:where auditdate>'01-JAN-10'” Here is error
[keeth]DB1 /oracle/data_15/db1> DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= USER1.TABLE1:where auditdate>'01-JAN-10' <
Export: Release 11.2.0.3.0 - Production on Tue Mar 26 03:03:26 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TABLE_03": "/******** AS SYSDBA" tables=USER1.TABLE1 directory=DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= USER1.TABLE1:where auditdate
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 386 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/TRIGGER
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
ORA-31693: Table data object "USER1"."TABLE1" failed to load/unload and is being skipped due to error:
ORA-00933: SQL command not properly ended
Master table "SYS"."SYS_EXPORT_TABLE_03" successfully loaded/unloaded
Dump file set for SYS.SYS_EXPORT_TABLE_03 is:
/oracle/data_15/db1/TABLE1.dmp
Job "SYS"."SYS_EXPORT_TABLE_03" completed with 1 error(s) at 03:03:58Version
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - ProductionHello,
You should use parameter file.Another question i can see you are using 11g.Why don't you use data pump?.
Data Pump is faster and have more features and enhancement than regular imp and exp.
You can do the following:
sqlplus / as sysdba
Create directory DPUMP_DIR3 for 'Type here your os path that you want to export to';then touch a file:
touch par.txt
In this file type the following the following :
tables=schema.table_name
dumpfile=yourdump.dmp
DIRECTORY=DPUMP_DIR3
logfile=Your_logfile.log
QUERY =abs.texp:"where hiredate>'01-JAN-13' "then do the following
expdp username/password parfile='par.txt'
If you will import from Oracle 11g to version 10g then you have to addthe parameter "version=10" to the parameter file above
BR
Mohamed ELAzab
http://mohamedelazab.blogspot.com/ -
Filter not being generated into where clause
Hi,
I have a simple mapping that has a source table, a filter, and a target table that is set to DELETE. The source table has many rows, but the filter would narrow down these rows by a lot. When I generate the code, the cursor that gets created SELECTs the whole table then there is an IF statement that is applied to each row with the filter condition. A lot less processing would be required if the filter was implemented as a WHERE clause in the cursor, but I can't get it to generate this way. I realize that deletes automatically generate row-based code but it would still be row-based if the WHERE clause was in the cursor.
Is there any way to get it to generate the filter as a WHERE clause in the cursor?Hi,
In general, Warehouse Builder gives you a number of different operating modes:
- set-based: which does everything in (one) SQL statement. This method is most performant, but has some limitations. Warehouse Builder today does not support set-based deletes (arguably, deletes are not the most common operation in a data warehouse).
- row-based: which is optimal for debugging. In row-based mode, you get as many records as possible and all operations/transformations take place in PL/SQL. This option gives you most debugging capabilities.
- row-based bulk: which is the previous method fetching rows in bulk (e.g. 100 by 100). Bulk processing speeds up the overall processing.
- row-based target only: in this mode we push as many of the operations/transformations as possible into the query (cursor). I.e. your filter (in your case) would be implemented as a restriction on the filter.
- row-based target only in bulk: see previous.
Warehouse Builder's default operation is set-based fail over to row-based. I.e. because we do not support set-based delete statements, I suspect you fall back to the row-based method of execution, which is not ideal in your case. I suggest you use the row-based target only option in order to get optimal performance for your scenario.
Note that for the deletes that are common in DW scenarios the row-based bulk deletes that we generate are often faster than set-based deletes. Also note that if you perform a complete delete (or even truncate) followed by an insert that Warehouse Builder does issue one statement for emptying the table.
Thanks,
Mark.
Maybe you are looking for
-
No longer boots since update [kinit & call trace troubles]
Hi all, Recently I did a full system upgrade on a completely working system (running I assume was a 2.6.28 kernel26) that upgraded it to 2.6.29. It then stopped booting correctly. I left this for a while since I didn't have the time for messing aroun
-
My itunes won't open after switching to lion
My itunes won't open after switching to lion
-
Set 9i as default Database over 10g
I have installed Oracle 9i and 10g both in same machine, running well but from other programs, 10g is connecting by default and if want to connect with 9i I have to select 9i. Is there any method to make 9i as default database
-
URGENT SUPPORT NOTIFICATION FROM HP regarding Pavilion p6640f mother board
Can you tell me if this notification is, indeed from HP or is it a scam? Thanks, MKeyes HP has discovered that some P66xx and S56xx and HPE-4xx Desktop Models built in the June / July 2010 time frame have system boards with a slightly higher than exp
-
How to colour cells in table ui element
hi, i have to colour the cells in table ui element with diiferent colour according to the condition... kindly suggest the same . any help will be appreciated. thanks and regards, sahai.s