SQL syntax Problem
let's say i want to get exactly the total service for an employee (how many years, how many months & how many days):
the Appointment date is : 11/17/1992
the Termination date is : 03/06/2001
by using months_between it will be like this:
select month_between(to_date('03/06/2001','MM/DD/YYYY'),to_date('11/17/1992','MM/DD/YYYY')) from dual;
it will give exactly : 99.6451613 ,then
we will divide it by 12 to get the years ,then we can truncate it to get the hole figure of the years, it will give exactly 8 years , my problem starts from here : how to get the months and the days?!!!!
null
Try this:
select trunc(m/12) "Years", trunc(m-trunc(m/12)*12) "Months", (m-trunc(m))*31 "Days" from (select months_between(to_date('03/06/2001','MM/DD/YYYY'),to_date('11/17/1992','MM/DD/YYYY')) as m from dual where rownum=1)
I did not check it (too many days to count :), but the results are reasonable.
Similar Messages
-
Ok, I'm sure this is a very simple problem but I'm confused.
Statement s = con.createStatement();
s.execute("SELECT COUNT (*) FROM table WHERE id = 6 AND somechar = 'N'");java.sql.SQLException: Syntax error or access violation message from server: "You have an error in y
our SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax
to use near '(*) FROM table WHERE id = 6 AND somechar = 'N'' at line 1"
This works fine when input into the phpMyAdmin database interface. Is there something blatantly wrong with my syntax, or...?Maybe it doesn't like the space between COUNT and (*)
%Yuck.
Yep, that was it. Thanks.
Weird, I'm accustomed to programs ignoring most whitespace as long as it doesn't create ambiguity. -
Oracle 9i Vs 10g Express Edition PL SQL syntax problem?
The following code works perfectly on Oracle 9i , but fails in 10g Express Edition. Please help me figure out what the problem is
product_master table exists and there is nothing wrong in there.The problem is a syntical one. Is there some 9i compatible mode? I'm using oracle express edition of 10 g. Login using the webbrowser. That itself is annoying.Why isnt there an SQL+ ide unlike 9i?
Code :
declare
pd_no varchar2(6);
cst number(8,2);
begin
pd_no:=&pd_no;
SELECT cost_price INTO cst
from product_master
where product_no=pd_no;
cst:=cst-200;
IF cst >= 3000 THEN
UPDATE product_master SET cost_price=cost_price-200
WHERE product_no=pd_no;
END IF;
END;
The error I get is
ORA-06550: line 5, column 14:
PLS-00103: Encountered the symbol "&" when expecting one of the following:
( - + case mod new not null
avg
count current exists max min prior sql stddev sum variance
execute forall merge time timestamp interval date
pipe
3. cst number(8,2);
4. begin
5. pd_no:=&pd_no;
6. SELECT cost_price INTO cst
7. from product_master
I changed & to : .The it asked for input but the following error came up
ORA-06550: line 16, column 2:
PLS-00103: Encountered the symbol ";"
1. declare
2. pd_no varchar2(6);
3. cst number(8,2);One, possibility of occuring this error(PLS-00103) is, if you leave input without entering anything this will occur.
Solution: Enter the value in quotation, like 'hello', below is one example which asks value for a, but i left it without entering any input, so the error occured.
Once check out this in your case.
SQL> @sample.sql
Enter value for a:
old 4: a:=&a;
new 4: a:=;
begin;
ERROR at line 3:
ORA-06550: line 3, column 6:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
( begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
SQL> spool off; -
This is a weird one!!!
I am using Dreamweaver/php/mysql and I am in the process of
developing the forms that edit articles that have been added to the
CMS. I have a page called edit.php which has the current list of
articles. Each article has a radio button next to it and have given
it an id of "id" (which is what I called it in the DB). On
selecting this article, and hitting submit, this should load up a
editnews2.php. On editnews2.php I have a filtered recordset that
filters on "id " so that it loads the article selected into the
editnews2 form. I have bound the fields in the form to the related
fields in the recordset.
When I test this out using the TEST button, in the recordset
pop-up window and enter an id, it retrieves the correct article
from the database. However, when I do it using the forms, I get an
error:
"You have an error in your SQL syntax; check the manual that
corresponds to your Mysql server version for the right syntax to
use near " at line 1"
This is really weird because the recordset works and
retreives the data no problems, which mean the connection file path
is correct and other parameters are correct. I have tried lots of
times to try and figure this out but I am now really stuck.
Could anyone shed some light on this one?
regards
orange22orange22 wrote:
> When I test this out using the TEST button, in the
recordset pop-up window and
> enter an id, it retrieves the correct article from the
database. However, when
> I do it using the forms, I get an error:
>
> "You have an error in your SQL syntax; check the manual
that corresponds to
> your Mysql server version for the right syntax to use
near " at line 1"
What that means is that the way Dreamweaver is building your
query
contains a mistake - probably an extra quotation mark or
something like
that.
Go into Code view and use echo to display the actual SQL
query being
sent to the database. That will give you a clue as to where
to start
troubleshooting the rest of the code.
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of
ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/ -
I'm trying to get onto a website i could normally get into but all it says is this
you have an error in your SQL syntax;check the manual that corresponds to your MySQL server version for the right syntax to use near') and adlx.'action' != 2' at line 1
I'm not good with computers and I've never heard of this i need some help, I may just be stupid but i seriously need some help here
preferably instructions for a hp computerThis looks to be an error with the web site you are visiting, not a problem with your PC. I suggest you contact the web site owner. The error suggests a problem with programming against a MySQL database, which is not a Microsoft technology.
Dan Guzman, SQL Server MVP, http://www.dbdelta.com -
SQL syntax error...
SQL Syntax:
select ename||'-'||job from emp
Initially, I was using the .Net Framework Data Provider for Oracle and had no problem bringing up the Query Builder in VS 2008. However, when I use the ODP .Net from Oracle, I get an error when bringing up the Query Builder:
Error in SELECT clause: expression near '|'.
Unable to parse query text.
It seems like when uing ODP .Net, it does not like the concatenation in the Select statment.
Any clue why?Is this consistently reproducible for you? Is it query builder specific? What version of ODP are you using? I just tried this with 11.1.6.20 ODP and it worked fine..
Cheers
Greg
using System;
using System.Data;
using Oracle.DataAccess.Client;
class Program
static void Main(string[] args)
using (OracleConnection con = new OracleConnection("data source=orcl;user id=scott;password=tiger"))
con.Open();
using (OracleCommand cmd = new OracleCommand("select ename||'-'||job from emp", con))
Console.WriteLine(cmd.ExecuteScalar().ToString());
} -
I am having a terrible time with the sql syntax INSIDE a java program. Is there somewhere online that has this information (in easy english!) For example I am trying to insert information in an access table. This is my sql query that works in access. How do I change the syntax to place it into java?
INSERT INTO reservations ( fromcity, tocity, fromdate, todate, air, hotel, rental, airticketamt, hotelamt, rentalamt, customerId )
VALUES ('Seattle', 'Phoenix', #1/1/2002#, #2/2/2002#, yes, yes, yes, 50, 50, 50, 'CUST001');
I also need to change the actual values (Seattle, etc) to the variables which is also a syntax problem!Here is a slightly smaller example of building the SQL. I didn't compile this so the syntax may not be 100%, but I think you can figure out the rest from this example.
// Seed the String values for the convenience of the example
String fromCity = "St. Paul";
String toCity = "Chicago";
String fromDate = "#1/1/2002#";
String toDate = "#2/2/2002#";
// Build the SQL using the String Values, the trick is to be
// sure you have the appropriate spaces in the SQL when done,
// and that you should use single tick marks to surround String
// values
String sql = "INSERT INTO reservations (fromCity, toCity, fromDate, toDate) " +
"VALUES ('" + fromCity + "', " +
"'"+ toCity + "', " +
"'"+ fromDate + "', " +
"'"+ toDate + "')";
// Take a look at what was generated
// to be sure it is what you want
System.out.println(sql); -
Error when making connection: You have an error in your SQL syntax;
I'm getting this error when trying to make a simple Database Connection:
SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '????????????????????????????????' at line 1
SQLState: 42000
VendorError: 1064
I tried a different driver and got the same error with more "?"s in the "use near....." part.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBTest{ public static void main(String[] args){ try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch(Exception e){ System.out.println(e); System.exit(0); } Connection conn = null; try { conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/testDB?" + "user=root&password=password"); conn.close(); } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } } }
MySQL Server Version:
Server version: 5.0.67-0ubuntu6 (Ubuntu)cotton.m wrote:
c0c0 wrote:
I've tried Drivers 5.1 , 5.0 and 3.1 now and I get the same problem every time. I've tried switching databases, users, etc but always get this same error:
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '????????????????' at line 1
I have the latest version of mysql from the Ubuntu repositories. Do I have to configure that a certain way? It isn't the URL which I supply that it does not like because I've tried multiple URLs and they all give me the same error when I supply the correct information.
Any help is greatly appreciated.This is.. very odd.
I have to ask are you really, really sure that your code is just as you posted? Are you sure you aren't running a query of some sort? My guess at this point would be some sort of rather bizarre encoding issue. I'm sorry but I can't reproduce your behaviour, I am connecting to different MySQL instances with no problem from Ubuntu..
Yes the code is exactly the same as what I posted (except hiding actual usernames and passwords)
I've even tried to connect to a remote mysql server and get the same behavior (If I type in the wrong database it alerts me there is no db of that name, if I lg in with the wrong password it alerts me cant login ____ @ ______, when I have all the correct information I get that same old error) , I'm somewhat convinced it's my driver now. I thought at first it was the way I had mysql configured but now I think it's my driver or the way I have everything installed. I simply put the driver location in the classpath and do the command:
export set CLASSPATH=/usr/share/tomcat5.5-webapps/ROOT/lib/mysql-connector-java-5.1.7-bin.jar
Was this the wrong way to go about doing it? I'm not currently running tomcat I simply put it there because a book said that's where it should go for tomcat, but I wanted to first try this not running tomcat with just a simple normal Java example. -
Hello,
I'm curious if there is any tool out there for checking the SQL syntax in the Java program itself. A tool to somehow validate the SQL before sending it thru the JDBC to execute the query on the database.
If so, can you please refer me to one.
ThanksI think the problem is different DBMS accepts different SQL. Even different version of DBMS.
There is no way to make sure 100% accurate of SQL.
The only way to make sure the SQL is accurate to any DBMS is running it and catch it in exception.
If you SQL is not produced on run time, you can simply check it by the batch utils. For example the sql plus. -
non riesco a ricevere acquisti fatti su itunes, mi da questo errore :erreu : you have an error in your sql syntax; checkthe manual that corresponds to your mysql server version for the right syntax to use near from news order by id desc at line. cosa devo fare? grazie
Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
* Don't make any changes on the Safe mode start window.
See:
* [[Troubleshooting extensions and themes]] -
NEED HELP IN SQL HOMEWORK PROBLEMS
I NEED HELP IN MY SQL HOMEWORK PROBLEMS....
I CAN SEND IT VIA EMAIL ATTACHMENT IN MSWORD....Try this:
SELECT SUBSTR( TN,
DECODE(LEVEL, 1, 1, INSTR(TN, '#', 1, LEVEL-1) + 1),
DECODE( INSTR(TN, '#', 1, LEVEL) , 0 ,
LENGTH(TN) + 1, INSTR(TN, '#', 1, LEVEL) )
- DECODE(LEVEL, 1, 1, INSTR(TN, '#', 1, LEVEL-1 ) + 1)
) xxx
FROM (
SELECT '234123#1254343#909823#908232#12345' TN FROM DUAL
CONNECT BY LEVEL <= LENGTH(TN) - LENGTH(REPLACE(TN,'#')) + 1
XXX
234123
1254343
909823
908232
12345
SELECT regexp_substr(tn, '[^#]+', 1, level) xx
FROM (
SELECT '234123#1254343#909823#908232#12345' TN FROM DUAL
CONNECT BY LEVEL <= LENGTH(TN) - LENGTH(REPLACE(TN,'#')) + 1
XX
234123
1254343
909823
908232
12345 -
SQL Developer 1.1.0.21: Issues with Data Grid and SQL syntax checking
In this new release of SQL Dev, when I execute a SQL in the SQL Worksheet and click in the Data Grid in the Results tab and try to navigate within a record using arrow keys, the grid cell enters into edit mode by default and so I cannot use the Left or Right arrow keys to navigate the grid. I am forced to use tab key to navigate. This is counter intuitive in my opinion.
Is there any option to change this behavior?
Another issue that I have come across is with SQL syntax checking. In some cases, when I press F9 to execute a SQL, it shows the SQL as executed i.e. shows something like 0.0134 seconds in the toolbar and no results displayed. In reality, the SQL had some syntax error which were NOT reported. This can be frustrating since now I have to fall back to SQL*Plus or TOAD just for syntax check.
I like the fact that SQLDev highlights the current SQL but it would be more useful if it just indicated the first line of the current sql instead of highlighting the whole sql.
Manish"In this new release of SQL Dev, when I execute a SQL in the SQL Worksheet and click in the Data Grid in the Results tab and try to navigate within a record using arrow keys, the grid cell enters into edit mode by default and so I cannot use the Left or Right arrow keys to navigate the grid. I am forced to use tab key to navigate. This is counter intuitive in my opinion."
In the "Results" tab, Click Ctrl & Tab keys (at the same time) or with mouse click on any cell other than the first column (a sequence or rownum), you will be able to navigate using the arrow keys.
"Another issue that I have come across is with SQL syntax checking. In some cases, when I press F9 to execute a SQL, it shows the SQL as executed i.e. shows something like 0.0134 seconds in the toolbar and no results displayed. In reality, the SQL had some syntax error which were NOT reported. This can be frustrating since now I have to fall back to SQL*Plus or TOAD just for syntax check."
The 0.0134 seconds could be the result of the most recently executed successful statement. Check the Script Output tab for errors. Use F5 (Run Script option) instead of F9.
"I like the fact that SQLDev highlights the current SQL but it would be more useful if it just indicated the first line of the current sql instead of highlighting the whole sql."
On the SQL statement (or code), Right Click -> Format SQL (or press Ctrl & B), proper formatting would help.
I use version 1.0.0.15.57 and seems to be working allright.
- Babu Rangasamy -
hi
How can we solve SQL injection problem in JDBC ?
this means if we have a form with text field and the user must enter a number say 4 , instead he entered "4 or true" this will concatenated with the SQL query and return all records because of "or true"....
is there any solutions ?
i tried PreparedStatment and it words but not alwayes
good lucki clearfied this in my first post
if u didnt got what i mean u can google it
http://www.google.com
thanksYou didn't gently provide keywords, like I always do, so I cannot learn from you.
Well, with a "reproduceable example" I mean that you have to post a short but complete working code snippet which reproduces the problem. So that we can copy'n'paste it in our environment here and test/debug it ourself and then eventually confirm the SQL injection. -
Some syntax problems (I guess)
Hi, I'm having problem with the first constructor in this simplified example code... I want to create a "default" Comparator. I'm not quite sure how to do this.
public class MyClass<E> {
private Comparator<E> comp;
public MyClass() {
MyClass(new ComparableComparatorBridge());
public Myclass(Comparator<E> comp) {
this.comp = comp;
private class ComparableComparatorBridge<E extends Comparable> implements Comparator<E> {
public int compare(E o1, E o2) {
return ((Comparable)o1).compareTo(o2);
}Event if you fix the syntax problems, following the advice of the other posters, you'll have a semantic problem:
MyClass<E> is parameterized with an unbounded type parameter.
You cannot assume that E implements Comparable<E>.
What you'd really need is a parameterizd constructor like this (won't compile):public <C extends E & Comparable<E>> MyClass() {
this(new ComparableComparatorBridge<C>());
}Unfortunately, this isn't valid Java. I see two possibilities:
1. Derive from MyClass and introduce the additional bound on the type parameter of the subclass. Then you can create a default-constructor using the ComparableComparatorBridge in that subclass.
2. Add a static factory function to MyClass, like this:
public class MyClass<E> {
private final Comparator<E> comp;
public MyClass(Comparator<E> comp) {
this.comp = comp;
public static <E extends Comparable<E>> MyClass<E> defaultComparable() {
return new MyClass<E>(new ComparableComparatorBridge<E>());
private static class ComparableComparatorBridge<E extends Comparable<E>> implements Comparator<E> {
public int compare(E o1, E o2) {
return o1.compareTo(o2);
} -
Hey All!
Im trying ot use a a bean to select data from a table where email != ''
The funny thing is my code works in one couple of jsp/bean but not in another, even though it's the exact same code.
This works
The Bean:
String sql = "SELECT applicantid, firstname, lastname, dob, " +
"homestreet, homestate, homecity, homezip, " +
"email, college, major, standing, " +
"graddate, schstreet, schcity, schstate, " +
"schzip, schphone, resOne, resTwo, " +
"resThree, waiver, bioletter, password, " +
"homephone " +
"FROM apptest " +
"WHERE " + filter + " " +
"ORDER BY " + orderBy;
The filter is the String "email != ''" and orderBy ="lastname"
Works perfectly!
But when I use similar code for another table
Code:
String sql = "SELECT providerid, applicantid, pin, title, " +
"company, firstname, lastname, phone, " +
"email, recletter " +
"FROM provtest " +
"WHERE " + filter + " " +
"ORDER BY " + orderBy;
with filter as "email != '' " and orderBy = "lastname"
I get the following error:
Error in findRecords ProviderUtility(Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1")
Keep in mind that email != '' (these are single quotes)
I am really baffled.
Ike"The funny thing is my code works in one couple of jsp/bean but not in another, even though it's the exact same code."
If it's EXACTLY the same code, what did you need another bean for?
If you needed a new bean, then it's not exactly the same.
Why aren't you using PreparedStatement to escape strings and dates for you?
Believe the engine when it tells you there's a mistake.
%
Maybe you are looking for
-
Custom Report taking more time to complete Normat
Hi All, Custom report(Aging Report) in oracle is taking more time to complete Normal. In one instance, the same report is taking 5 min and the other instance this is taking 40-50 min to complete. We have enabled the trace and checked the trace file,
-
Itunes will not open and I have tried fixing it!!
i double click on the icon and it comes up with this The itunes application could not be opnened. An unknown error occured (0x666D743F) Thanks
-
How do I force Firefox to remember and use my username and password for a site ?
-
Third party software for transferring music content to new laptop
Help! My laptop died and I need help finding a third party software to copy my music files and transfer them from my Iphone to my new laptop's Itunes. Apple tech support helped me set up Itunes and transfer my purchased content, but I have 1,000 song
-
I have a late 2011 macbook pro running OSX Lion, and it wont update the firmware to 2.7, it downloads the update then says its installing it but when i go back to software update it keeps coming up saying it needs to be updated. Im wondering what can