Valid Sql Syntax....

Hi ,
Is the following sql statement format valid...????
select col1 , col2 , col3 , (select col5 , col6
                                      from x
                                      where col5='value') s
where col1=s.col5when i execute a query having the above format , i get the error :
ORA-00913:too many columns
When i execute individually each sql statement , i get one row only with a matching data value for one column as the above general sql format displays....
How should i write the above sql statement in order to be valid..????
Thanks , a lot
Simon

Use two subSELECTs like here.
If you put the same where clause the fetched row will be the same and you would get what you want.
Processing ...
select dummy,dummy
from dual
Query finished, retrieving results...
   DUMMY     DUMMY_1 
X          X         
1 row(s) retrieved
Processing ...
select (
          select dummy,dummy
          from dual
from dual;
ORA-00913: too many values
Processing ...
select (
          select dummy
          from dual
          select dummy
          from dual
from dual
Query finished, retrieving results...
(SELECTDUMMYFROMDUAL) (SELECTDUMMYFROMDUAL)_1
X                     X                      
1 row(s) retrievedBye Alessandro
Message was edited by:
alessandro.miami

Similar Messages

  • Ejb3 entity bean not generating valid sql for postgres 8.1

    Hello,
    I originally posted this on the jboss seam board as I ran across this error on a seam test example, but it seems it's more generally applicable to ejb3 entity beans not generating sql that postgres can understand. I'll post my message below, all replies are appreciated.
    I'm going through the hello world example from the seam book, and I'm getting an error I cannot resolve, that with an auto generated sql statement, that's not valid for postgres 8.1, the database I'm on. Here's my error:
    17:40:31,370 INFO [STDOUT] Hibernate: select next value for person_id_seq from dual_person_id_seq
    17:40:31,394 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 42601
    17:40:31,394 ERROR [JDBCExceptionReporter] ERROR: syntax error at or near "value"
    17:40:31,396 FATAL [application] javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not get next sequence value
    javax.faces.el.EvaluationException: javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not get next sequence value
    Here's the table definition
    - create table Person (id bigint not null, name varchar(255), primary key (id))
    - create table dual_person_id_seq (zero integer)
    - create sequence person_id_seq start with 1 increment by 1
    and here's the entity bean:
    @Entity
    @Name("person")
    @Table(name="person")
    @SequenceGenerator(name="person_sequence", sequenceName="person_id_seq")
    public class Person implements Serializable {
    private long id;
    private String name;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="person_sequence")
    public long getId() { return id;}
    public void setId(long id) { this.id = id; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    How do I get it to generate a valid sql statement for postgres?

    I think you should try putting the sequence generator annotation over the primary key field. Try it and be sure it works.
    regards,
    Michael

  • SQL syntax error when creating record insertion form

    Good day,
    I was hoping someone could help me.  I am trying to create a record insertion form on a website to insert data into a database table.  When attempting to create the form, I am getting the following 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 ' Organization, Office, Department, Phone, EmailAddress, JobTitle, `OfficialMaili' at line 1
    Not sure what is going on.  I am running windows 8 and DW cs5 w/ MYSQL.  I am testing on a local server prior to pushing to the remote server.
    Thank you for your assistance and please advise any code you would like me to send.

    Here is all the code from this particular webpage.  I apologize, I am too stupid to realize which parts are SQL vice PHP vice HTML:
    <?php require_once('Connections/group4.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
       if (PHP_VERSION < 6) {
         $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
      switch ($theType) {
         case "text":
           $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
           break;   
         case "long":
         case "int":
           $theValue = ($theValue != "") ? intval($theValue) : "NULL";
           break;
         case "double":
           $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
           break;
         case "date":
           $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
           break;
         case "defined":
           $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
           break;
       return $theValue;
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
       $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
       $insertSQL = sprintf("INSERT INTO individual (Grade, LastName, FirstName, M.I., Organization, Office, Department, Phone, EmailAddress, JobTitle, `OfficialMailing Address`, Citizenship, Designation, IATrainingComplete, IADate) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                            GetSQLValueString($_POST['Grade'], "text"),
                            GetSQLValueString($_POST['LastName'], "text"),
                            GetSQLValueString($_POST['FirstName'], "text"),
                            GetSQLValueString($_POST['MI'], "text"),
                            GetSQLValueString($_POST['Organization'], "text"),
                            GetSQLValueString($_POST['Office'], "text"),
                            GetSQLValueString($_POST['Department'], "text"),
                            GetSQLValueString($_POST['Phone'], "double"),
                            GetSQLValueString($_POST['EmailAddress'], "text"),
                            GetSQLValueString($_POST['JobTitle'], "text"),
                            GetSQLValueString($_POST['OfficialMailing_Address'], "text"),
                            GetSQLValueString($_POST['Citizenship'], "text"),
                            GetSQLValueString($_POST['Designation'], "text"),
                            GetSQLValueString($_POST['IATrainingComplete'], "text"),
                            GetSQLValueString($_POST['IADate'], "text"));
      mysql_select_db($database_group4, $group4);
       $Result1 = mysql_query($insertSQL, $group4) or die(mysql_error());
      $insertGoTo = "index.php";
       if (isset($_SERVER['QUERY_STRING'])) {
         $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
         $insertGoTo .= $_SERVER['QUERY_STRING'];
       header(sprintf("Location: %s", $insertGoTo));
    mysql_select_db($database_group4, $group4);
    $query_rsIndividual = "SELECT * FROM individual ORDER BY IndividualNumber ASC";
    $rsIndividual = mysql_query($query_rsIndividual, $group4) or die(mysql_error());
    $row_rsIndividual = mysql_fetch_assoc($rsIndividual);
    $totalRows_rsIndividual = mysql_num_rows($rsIndividual);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Contact Us</title>
    <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
    <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    .header {
      font-size: 36px;
      text-decoration: underline;
    .quote {
      font-size: 18px;
      font-style: italic;
    .tablethisone {
      margin: 5px;
      padding: 25px;
      border: medium none #000;
      text-align: center;
    </style>
    </head>
    <body>
    <p><img src="Images/EGA.png" width="227" height="222" alt="EGA" /><span class="header">SAAR Tracking System
    </span></p>
    <ul id="MenuBar1" class="MenuBarHorizontal">
       <li><a href="index.php">Home</a>  </li>
       <li><a href="search.php">Search</a></li>
       <li><a href="contact.php">Contact Us</a>  </li>
    </ul>
    <p> </p>
    <p>PRIVACY ACT STATEMENT</p>
    <p>Executive Order 10450, 9397; and Public Law 99-474, the Computer Fraud and Abuse Act.
       To record names, signatures, and other identifiers for the purpose of validating the trustworthiness of individuals requesting
       access to Department of Defense (DoD) systems and information. NOTE: Records may be maintained in both electronic
       and/or paper form.</p>
    <p> </p>
    <p> </p>
    <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
       <table align="center">
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">Grade:</td>
           <td><input type="text" name="Grade" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">LastName:</td>
           <td><input type="text" name="LastName" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">FirstName:</td>
           <td><input type="text" name="FirstName" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">M.I.:</td>
           <td><input type="text" name="MI" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">Organization:</td>
           <td><input type="text" name="Organization" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">Office:</td>
           <td><input type="text" name="Office" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">Department:</td>
           <td><input type="text" name="Department" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">Phone:</td>
           <td><input type="text" name="Phone" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">EmailAddress:</td>
           <td><input type="text" name="EmailAddress" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">JobTitle:</td>
           <td><input type="text" name="JobTitle" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">OfficialMailing Address:</td>
           <td><input type="text" name="OfficialMailing_Address" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">Citizenship:</td>
           <td><input type="text" name="Citizenship" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">Designation:</td>
           <td><input type="text" name="Designation" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">IATrainingComplete:</td>
           <td><input type="text" name="IATrainingComplete" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right">IADate:</td>
           <td><input type="text" name="IADate" value="" size="32" /></td>
         </tr>
         <tr valign="baseline">
           <td nowrap="nowrap" align="right"> </td>
           <td><input type="submit" value="Insert record" /></td>
         </tr>
       </table>
       <input type="hidden" name="MM_insert" value="form1" />
    </form>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p>Disclosure of this information is voluntary; however, failure to provide the requested information may impede, delay or
    prevent further processing of this request.</p>
    <p class="quote">&quot;Be polite, be professional, but have a plan to kill everybody you meet&quot; General James Mattis</p>
    <p> </p>
    <script type="text/javascript">
    var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
    </script>
    </body>
    </html>
    <?php
    mysql_free_result($rsIndividual);
    ?>

  • You have an error in your SQL syntax;

    i have a checkout page that i am trying to send to a payment centre but and getting the following 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 '16)' at line 1
    can someone help and tell me what this means does it mean "conflict with columns definitions"
    if so what can i do to solve the issue? do you need to see the page code?
    thanks

    <?php require_once('Connections/wibbles.php'); ?>
    <?php
    // do not cache
    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");                      // Date in the past
    header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
    header ("Cache-Control: no-cache, must-revalidate");                    // /1.1
    header ("Pragma: no-cache");                                            // /1.0
    // *** Restrict Access To Page: Grant or deny access to this page
    $FX_authorizedUsers=" ";
    $FX_authFailedURL="login.php";
    $FX_grantAccess=0;
    if (!session_id()) session_start();
    if (isset($_SESSION["MM_Username"])) {
      if (true || !(isset($_SESSION["MM_UserAuthorization"])) || $_SESSION["MM_UserAuthorization"]=="" || strpos($FX_authorizedUsers, $_SESSION["MM_UserAuthorization"])) {
        $FX_grantAccess = 1;
    if (!$FX_grantAccess) {
      $FX_qsChar = "?";
      if (strpos($FX_authFailedURL, "?")) $FX_qsChar = "&";
      $FX_referrer = "Restricted Area";
      $FX_authFailedURL = $FX_authFailedURL . $FX_qsChar . "accessdenied=" . urlencode($FX_referrer);
      header("Location: $FX_authFailedURL");
      exit;
    // *** Retrieve X ID ***
    if (!session_id()) session_start();
    $XC_OrderIdSessionVar = "OrderID";
    if (!isset($_SESSION[$XC_OrderIdSessionVar])) {
      // Get a unique OrderID number and save to session.
      $XC_tableName = "wibble_nextorder";
      $XC_fieldName = "NextOrderID";
      mysql_select_db($database_wibbles, $wibbles);
      $XC_IdSource = "select " . $XC_fieldName . " from " .  $XC_tableName;
      $XC_rsId = mysql_query($XC_IdSource, $wibbles) or die(mysql_error());
      $row_XC_rsId = mysql_fetch_assoc($XC_rsId);
      $_SESSION[$XC_OrderIdSessionVar] = $row_XC_rsId[$XC_fieldName];
      $$XC_OrderIdSessionVar = $_SESSION[$XC_OrderIdSessionVar];
      session_register($XC_OrderIdSessionVar);
      $XC_next = $_SESSION[$XC_OrderIdSessionVar] + 1;
      $XC_upd = "update " . $XC_tableName . " set " . $XC_fieldName . " = " . $XC_next;
      $XC_rsId = mysql_query($XC_upd, $wibbles) or die(mysql_error());
      $XC_rsId = null;
    // x limit validation
    if (isset($_POST["XC_Limit"]) && $_POST["XC_Limit"] != "") {
      $XC_limErr = stripslashes($_POST["XC_Limit"]);
      if (isset($_GET['XC_SaveCartToTable'])) unset($_GET['XC_SaveCartToTable']);
      unset($HTTP_POST_VARS);
      unset($_POST);
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;   
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      return $theValue;
    // x limit validation
    if (isset($_POST["XC_Limit"]) && $_POST["XC_Limit"] != "") {
      $XC_limErr = stripslashes($_POST["XC_Limit"]);
      if (isset($_GET['XC_SaveCartToTable'])) unset($_GET['XC_SaveCartToTable']);
      unset($_POST);
      unset($_POST);
    // Validate X amount
    if (isset($_POST["XC_Amount"]) && $_POST["XC_Amount"] < 10) {
        if (isset($_GET['XC_SaveCartToTable'])) unset($_GET['XC_SaveCartToTable']);
        unset($_POST);
        unset($_POST);
        $XC_amErr = "The amount doesn't reach the allowed minimum of &euro; 100.";
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;   
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      return $theValue;
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
      $insertSQL = sprintf("INSERT INTO wibble_orders (OrderID, CustomerID, OrderDate, Shipping, Discount, Tax, Total) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                           GetSQLValueString($_POST['OrderID'], "int"),
                           GetSQLValueString($_POST['CustomerID'], "int"),
                           GetSQLValueString($_POST['OrderDate'], "date"),
                           GetSQLValueString($_POST['Shipping'], "double"),
                           GetSQLValueString($_POST['Discount'], "double"),
                           GetSQLValueString($_POST['Tax'], "double"),
                           GetSQLValueString($_POST['XC_Amount'], "double"));
      mysql_select_db($database_wibbles, $wibbles);
      $Result1 = mysql_query($insertSQL, $wibbles) or die(mysql_error());
    // *** X Shopping Cart ***
    $useSessions = true;
    $XCName = "wibbleJakeCart";
    $XCTimeout = 30;
    $XC_ColNames=array("ProductID","Quantity","Name","Color","Price","MinQty","Discount","Stoc k","Total");
    $XC_ComputedCols=array("","","","","","","","","Price");
    require_once('XCInc/XCart.inc');
    $colname_rsCustomer = "1";
    if (isset($_SESSION['MM_UserAuthorization'])) {
      $colname_rsCustomer = $_SESSION['MM_UserAuthorization'];
    mysql_select_db($database_wibbles, $wibbles);
    $query_rsCustomer = sprintf("SELECT * FROM wibble_customers WHERE CustomerID = %s", GetSQLValueString($colname_rsCustomer, "int"));
    $rsCustomer = mysql_query($query_rsCustomer, $wibbles) or die(mysql_error());
    $row_rsCustomer = mysql_fetch_assoc($rsCustomer);
    $totalRows_rsCustomer = mysql_num_rows($rsCustomer);
    // *** Redirect if XCart is Empty ***
    $XC_RedirectIfEmpty = "shopping-cart.php";
    if (isset($_SERVER["QUERY_STRING"])) {
      $XC_RedirectIfEmpty .= "?" . htmlentities($_SERVER["QUERY_STRING"]);
    if (isset(${$XCName}["contents"]) && (sizeof(${$XCName}["contents"][0]) == 0)) header("Location: " . $XC_RedirectIfEmpty);
    // *** Repeat XCart region *** (do not remove this label)
    // validate x limit
    $XC_invalidItems = "";
    $XC_lim = "";
    $iCol = array_search("Quantity",${$XCName}["ColNames"]);
    $iSrc = array_search("Stock",${$XCName}["ColNames"]);
    for ($iVal=0; $iVal<sizeof(${$XCName}["contents"][0]); $iVal++) {
      if (${$XCName}["contents"][$iCol][$iVal] > ${$XCName}["contents"][$iSrc][$iVal]) {
        if ($XC_invalidItems != "") $XC_invalidItems .= "-";
        $XC_invalidItems .= (string) ($iVal+1);
        if ($XC_lim != "") $XC_lim .= "-";
        $XC_lim .= (string) ${$XCName}["contents"][$iSrc][$iVal];
    if ($XC_invalidItems != "") {
      $XC_invalidItems = "(".$XC_invalidItems.")";
      $XC_lim = "(".$XC_lim.")";
      $x_limErr = "The item(s) $XC_invalidItems exceed the available stock of $XC_lim";
    // *** Add shipping based on Range
    mysql_select_db($database_wibbles, $wibbles);
    $XC_sourceVal = $XCart_sumTotal;
    $XC_ShipSource = "SELECT Shipping FROM wibble_shipbyprice WHERE MinPurchase < " . $XC_sourceVal . " AND MaxPurchase >= " . $XC_sourceVal;
    $XC_rsShip = mysql_query($XC_ShipSource, $wibbles) or die(mysql_error());
    $row_XC_rsShip = mysql_fetch_assoc($XC_rsShip);
    $XC_Shipping = $row_XC_rsShip['Shipping'];
    $XC_rsShip = null;
    // *** Add Referenced Sales Tax
    mysql_select_db($database_wibbles, $wibbles);
    $XC_taxSource = "SELECT Tax FROM wibble_tax WHERE Country = '" . $row_rsCustomer['Country'] . "'";
    $XC_rsTax = mysql_query($XC_taxSource, $wibbles) or die(mysql_error());
    $row_XC_rsTax = mysql_fetch_assoc($XC_rsTax);
    $XC_Tax = $row_XC_rsTax['Tax'];
    $XC_rsTax = null;
    $XC_SalesTax = $XC_Tax*($XCart_sumTotal+$XC_Shipping-$XC_Discount);
    // *** Compute Grand Total
    $XC_GranTotal = $XCart_sumTotal+$XC_SalesTax+$XC_Shipping-$XC_Discount;
    // *** Format table as Europe style
    if (!session_id()) session_start();
    // set header 
    $XC_header = "<style type=\"text/css\">\n<!--\n";
    $XC_header .= "table {font-family: Arial, Helvetica, sans-serif; font-size: 13px;}\n";
    $XC_header .= "-->\n</style>\n";
    $XC_header .= "<table width=\"520\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
    $XC_header .= "  <tr>\n    <td>\n";
    $XC_header .= "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\">\n";
    $XC_header .= "  <tr>\n    <td> </td>\n    <td align=\"right\"> </td>\n  </tr>\n";
    $XC_header .= "  <tr>\n    <td>Order n. <b>" . $_SESSION["OrderID"] . "</b></td>\n    <td align=\"right\"> " . date("d/m/Y") . "</td>\n  </tr>\n";
    $XC_header .= "  <tr>\n    <td> </td>\n    <td> </td>\n  </tr>\n";
    $XC_header .= "  <tr>\n    <td colspan=\"2\" align=\"Left\">";
    $XC_header .= $row_rsCustomer["FirstName"] . " ";
    $XC_header .= $row_rsCustomer["LastName"] . " <br>";
    $XC_header .= $row_rsCustomer["Address"] . " <br>";
    $XC_header .= $row_rsCustomer["ZIP"] . " ";
    $XC_header .= $row_rsCustomer["City"] . " ";
    $XC_header .= $row_rsCustomer["State"] . " <br>";
    $XC_header .= $row_rsCustomer["Country"] . " <br>";
    $XC_header .= "</td>\n  </tr>\n</table>\n";
    $XC_header .= "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">\n";
    $XC_header .= "  <tr>\n    <td colspan=\"5\"> </td>\n  </tr>\n";
    $XC_header .= "  <tr>\n    <td colspan=\"5\">Cart contents: </td>\n  </tr>\n";
    // set cart data 
    $XCartData = "  <tr>\n";
    $XCartData .= "    <th width=\"30\" bgcolor=\"#CC6600\"><font color=\"white\">Qty</font></th>\n";
    $XCartData .= "    <th width=\"310\" bgcolor=\"#CC6600\"><font color=\"white\">Description</font></th>\n";
    $XCartData .= "    <th width=\"60\" bgcolor=\"#CC6600\"><font color=\"white\">Price</font></th>\n";
    $XCartData .= "    <th width=\"40\" bgcolor=\"#CC6600\"><font color=\"white\">Disc</font></th>\n";
    $XCartData .= "    <th width=\"80\" bgcolor=\"#CC6600\"><font color=\"white\">Total</font></th>\n";
    $XCartData .= "  </tr>\n";
    for ($jRow=0; $jRow<sizeof(${$XCName}["contents"][0]); $jRow++) {
      require('XCInc/RepeatXMailRegion.inc');
      $XCartData .= "  <tr>\n";
      $XCartData .= "    <td align=\"Center\" bgcolor=\"#FFFF99\">" . ${$XCName}["contents"][1][$jRow] . "</td>\n";
      $XCartData .= "    <td align=\"Left\" bgcolor=\"#FFFF99\">" . ${$XCName}["contents"][2][$jRow] . "</td>\n";
      $XCartData .= "    <td align=\"Right\" bgcolor=\"#FFFF99\">&euro; " . number_format(${$XCName}["contents"][4][$jRow], 2, ',', '.') . "</td>\n";
      $XCartData .= "    <td align=\"Center\" bgcolor=\"#FFFF99\">" . ${$XCName}["contents"][6][$jRow] . "</td>\n";
      $XCartData .= "    <td align=\"Right\" bgcolor=\"#FFFF99\">&euro; " . number_format(${$XCName}["contents"][8][$jRow], 2, ',', '.') . "</td>\n";
      $XCartData .= "  </tr>\n";
    // set footer
    $XC_footer = "  <tr>\n    <td colspan=\"4\" align=\"right\"><b> SubTotal </b></td>\n    <td align=\"right\" bgcolor=\"#FFFF99\"><b> &euro; " . number_format($XCart_sumTotal, 2, ',', '.') . "</b></td>\n  </tr>\n";
    $XC_footer .= "  <tr>\n    <td colspan=\"4\" align=\"right\"> Shipping </td>\n    <td align=\"right\" bgcolor=\"#FFFF99\"> &euro; " . number_format($XC_Shipping, 2, ',', '.') . "</td>\n  </tr>\n";
    $XC_footer .= "  <tr>\n    <td colspan=\"4\" align=\"right\">  </td>\n    <td align=\"right\" bgcolor=\"#FFFF99\"> </td>\n  </tr>\n";
    $XC_footer .= "  <tr>\n    <td colspan=\"4\" align=\"right\"> Sales Tax </td>\n    <td align=\"right\" bgcolor=\"#FFFF99\"> &euro; " . number_format($XC_SalesTax, 2, ',', '.') . "</td>\n  </tr>\n";
    $XC_footer .= "  <tr>\n    <td colspan=\"4\" align=\"right\"><b> Grand Total </b></td>\n    <td align=\"right\" bgcolor=\"#FFFF99\"><b> &euro; " . number_format($XC_GranTotal, 2, ',', '.') . "</b></td>\n  </tr>\n";
    $XC_footer .= "  <tr>\n    <td colspan=\"5\"> </td>\n  </tr>\n";
    $XC_footer .= "</table>\n    </td>\n  </tr>\n</table>\n";
    // join all
    if (isset($_SESSION["XC_CartMail"])) session_unregister("XC_CartMail");
    $XC_CartMail = $XC_header . $XCartData . $XC_footer;
    $_SESSION["XC_CartMail"] = $XC_CartMail;
    session_register("XC_CartMail");
    // *** Save XCart contents to table ***
    require_once('XCInc/XCsaveAction.inc');
    if (isset($_GET['XC_SaveCartToTable']) && ($_GET['XC_SaveCartToTable'] == "1")) {
      $XC_destColName = array("ProductID","Quantity","","Color","UnitPrice","","Discount","","Total");
      $XC_destColType = array("str","num","str","str","num","num","num","num","num");
      $XC_orderId = $_SESSION['OrderID'];
      $XC_tableName = "wibble_orderdetails";
      $XC_OrderIDCol = "OrderID";
      $XC_OrderIDType = "num";
      $XC_AddToTableRedirect = "thanks.php";
      $XC_conName = "wibbles";
      require_once('XCInc/SaveXCartToTable.inc');
    // clone a session
    if (!session_id()) session_start();
    if (isset($_SESSION["OrderNum"])) session_unregister("OrderNum");
    if (isset($_SESSION["OrderID"])) {
      $OrderNum = $_SESSION["OrderID"];
      $_SESSION["OrderNum"] = $OrderNum;
      session_register("OrderNum");
    function DoFormatCurrency($theObject,$NumDigitsAfterDecimal,$DecimalSeparator,$GroupDigits,$Curren cySymbol) {
              $currencyFormat=$CurrencySymbol.number_format($theObject,$NumDigitsAfterDecimal,$Dec imalSeparator,$GroupDigits);
              return ($currencyFormat);
    function DoFormatPercent($theObject,$NumDigitsAfterDecimal,$DecimalSeparator,$GroupDigits) {
              $currencyFormat=number_format($theObject*100,$NumDigitsAfterDecimal,$DecimalSeparato r,$GroupDigits).'%';
              return ($currencyFormat);
    ?>

  • SQL Syntax check

    Hello all,
    Is there a way to check sql syntax against the dataabse/table without acctually running against the table ?? If you are familar with RMAN...it has a rman syntax check cmd.. ( RMAN> rman checksyntax )....which will tell you if its a valid statment or not...
    is there anything similar for sqlplus ??? i am on 10.2.0.3 on Solrais....Something where i can run select * from emp; but not actually execute the statment against the database ??

    For SQLPLUS you can do this.
    SQL> set autotrace traceonly ;
    SQL> select * from dual ;
    Execution Plan
    Plan hash value: 272002086
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |     1 |     2 |     2   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 |
    Statistics
             24  recursive calls
              0  db block gets
              6  consistent gets
              4  physical reads
              0  redo size
            407  bytes sent via SQL*Net to client
            380  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    SQL> select * fromm dual ;
    select * fromm dual
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expectedSS

  • 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

  • Sql syntax in jsp

    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.
    %

  • SQL Syntax Issue

    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
    orange22

    orange22 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/

  • Validating SQL expressions

    Hello,
    Am researching a way for validating SQL expressions.
    Say I have expressions substr(<tname.coumn_name>,1,2), I want to parse this expression for completeness, meaning whether the expression can be used in a case, decode or a normal select statement as a where clause.
    Is there any functionality available within oracle to achieve this or any pointer to some sample PL/SQL code to achieve this is welcome.
    TIA,
    Prakash. T

    If all we want to do is parsing, without creating a plan_table of any kind and without writing to it, we can use dbms_sql.
    SQL> var s varchar2(100)
    SQL> exec :s := 'select substr(dummy,1,1) from dual'
    PL/SQL procedure successfully completed.
    SQL> declare
      2    l_c pls_integer;
      3  begin
      4    l_c := dbms_sql.open_cursor;
      5    dbms_sql.parse(l_c, :s, dbms_sql.native);
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    SQL> exec :s := 'select substrx(dummy,1,1) from dual'
    PL/SQL procedure successfully completed.
    SQL> /
    declare
    ERROR at line 1:
    ORA-00904: "SUBSTRX": invalid identifier
    ORA-06512: at "SYS.DBMS_SYS_SQL", line 826
    ORA-06512: at "SYS.DBMS_SQL", line 39
    ORA-06512: at line 5It is after all only one additional variable declaration and an extra line of code.

  • Error in SQL syntax

    Hi all,
    I have an SQL database which up untli about 20 minutes ago was fine.  I have a complex contact form whic is (was) all finished.  I have added a couple more tables to the database (now totalling 4), in order to create a registration / login page.
    (Is it okay to have 4 tables in 1 database?)
    Anyway.  I have just finished with the login stuff and all works fine.  I decided to have a quick look around the site and make sure everything is okay - but for some reason when I navigate to the "complex contact form" - I get this message:
    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 'ASCE LIMIT 0, 150' at line 1
    The registration wizard and login pages still work, and in general the site is browseable.  But this page will not work and I have no idea why?
    Does anyone have any suggestion?  All I have done since it worked is add 2 other tables as I said....
    Thank you / please help!
    NJ

    There was a typo in my previous post. There should be only one $ in $query_recordsetName. I should also have added that "recordsetName" is the name of your recordset. I would have thought it was obvious, but I see you're limiting the number of results, so the name is slightly different.
    The other thing is that you have not put it where I told you. Apart from that...
    $query_rscontacts1 = "SELECT contacts.Logo, contacts.Industries,
    contacts.coverage, contacts.misc, contacts.id, contacts.email,
    contacts.website FROM contacts WHERE {$NXTFilter_rscontacts1} ORDER BY
    {$NXTSort_rscontacts1}";
    $query_limit_rscontacts1 = sprintf("%s LIMIT %d, %d", $query_rscontacts1, $startRow_rscontacts1, $maxRows_rscontacts1);
    echo $query_limit_rscontacts1 . '<br />';
    $rscontacts1 = mysql_query($query_limit_rscontacts1, $Contacts) or die(mysql_error());

  • Error with SQL syntax

    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 computer

    This 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

  • ANSI SQL Syntax - What belongs to join-clause and what to where-clause

    Hello,
    we currently have a discussion about the ANSI SQL Syntax where we do not agree what belongs to the join clause and what belongs to the where clause in an ANSI Sytnax SQL Query.
    Lets say there is a query like this:
    +SELECT *+
    FROM employees emp, departments dept
    WHERE emp.dept_country = dept.dept_country
    AND emp.dept_name = dept.dept_name
    AND dept.dept_type = 'HQ'
    AND emp.emp_lastname = 'Smith'
    Primary key of the departments table is on the columns dept_country, dept_name and dept_type. We have a Oracle database 10g.
    Now I have rewritten the query to Ansi Syntax:
    +SELECT *+
    FROM employees emp
    JOIN departments dept
    ON emp.dept_country = dept.dept_country AND emp.dept_name = dept.dept_name
    WHERE dept.dept_type = 'HQ'
    AND emp.emp_lastname = 'Smith'
    Another developer says that this is not completely correct, every filter on a column that belongs to the primary-key of the joined table has to be in the join clause, like this:
    +SELECT *+
    FROM employees emp
    JOIN departments dept
    +ON emp.dept_country = dept.dept_country AND emp.dept_name = dept.dept_name AND dept.dept_type = 'HQ'
    WHERE emp.emp_lastname = 'Smith'
    Can somebody tell me which on is correct?
    Is there any definition for that? I couldn't find it in the Oracle Database definition.
    I just found out the names of the ANSI documents here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/ap_standard_sql001.htm#i11939
    I had a look at the ANSI webstore but there you have to buy the PDF files. In my case thats exaggerated because both of the Queries work and i am just interessted if there is one correct way.
    Thank you in advance
    Marco

    Hi,
    As i guideline i would say, answer the question: should the result of the join be filtered or should only filtered rows be joined from a particular table?
    This is helpful in the case of outer joins also, for inner joins it doesnt matters as said already be former posters, where there may be hughe semantical differences depending of where the predicates are placed.
    From performance view, if we talk about oracle, take a look a the execution plans. You will see that there is (probably) no difference in case of inner joins. Even in case of outer joins the optimizer pushes the predicate as a filter towards the table if it semantically possible.
    Regards

  • 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());
    }

  • CR2011 - SQL Syntax Error

    After updating our ODBC driver to match our current Unidata database version (7.1), we now get the following message from Crystal Reports 2011 on many of our existing reports:
    "Failed to retrieve data from the database. Details: 37000:[Rocket U2][U2ODBC][1401249]Error ID: 21 Severity: ERROR Facility: DBCAPERR - SQL Syntax error. [Database Vendor Code: 5365440]
    The generated SQL statement follows:
    SELECT "INVCDETH_NF"."ITEM_NBR", "ITEMMAST_NF"."ITEM_DESC", "INVCDETH_NF"."SHIPPED_QUANTITY", "INVCDETH_NF"."Z_INV_DATE", "INVCDETH_NF"."Z_COMPANY", "INVCHDRH_NF"."INVOICE_TYPE", "INVCDETH_NF"."EXTENDED_PRICE", "INVCDETH_NF"."COST_OF_SALES", "INVCDETH_NF"."Z_PCC_CODE", "INVCDETH_NF"."DISCOUNT_AMOUNT", "INVCDETH_NF"."WAREHOUSE", "ITEMMAST_NF"."PRICE_CODE", "INVCHDRH_NF"."INVOICE_NBR", "INVCHDRH_NF"."REFERENCE_NBR"
    FROM   ("Administrators"."ITEMMAST_NF" "ITEMMAST_NF" INNER JOIN "Administrators"."INVCDETH_NF" "INVCDETH_NF" ON "ITEMMAST_NF"."ITEM_NBR"="INVCDETH_NF"."ITEM_NBR") INNER JOIN "Administrators"."INVCHDRH_NF" "INVCHDRH_NF" ON ((("INVCDETH_NF"."INVOICE_NBR"="INVCHDRH_NF"."INVOICE_NBR") AND ("INVCDETH_NF"."INV_HEADER_ID"="INVCHDRH_NF"."INV_HEADER_ID")) AND ("INVCDETH_NF"."REFERENCE_NBR"="INVCHDRH_NF"."REFERENCE_NBR")) AND ("INVCDETH_NF"."RELEASE_NBR"="INVCHDRH_NF"."RELEASE_NBR")
    WHERE  "INVCDETH_NF"."Z_COMPANY"='01' AND "INVCDETH_NF"."WAREHOUSE"='086' AND ("INVCDETH_NF"."Z_INV_DATE">={d '2013-12-08'} AND "INVCDETH_NF"."Z_INV_DATE"<={d '2013-12-26'})
    ORDER BY "INVCDETH_NF"."WAREHOUSE"
    I downloaded the trial version of CR2013 and get the same result. Can anyone shed any light? Thanks!

    Yes, in that the query is what Crystal generated from the report being built in the designer. I simply copied it from the Database > Show SQL Query screen. Since the error I'm receiving is a SQL Syntax Error, I thought it would be appropriate to show it.
    The bottom line is that because I am not very knowledgeable in SQL, I can't look at the query and identify the error. However, I am responsible for supporting CR in-house. Naturally, I have reported this to Rocket (the makers of the ODBC driver) but haven't received their reply yet.

  • Parse sql syntax

    I have temp table inside my stored procedure:
    CREATE TABLE #tmpOrders(product_id VARCHAR(20))
    SELECT * FROM #tmpOrders o INNER JOIN dbo.products p ON o.productID=p.productID
    o.productID column doesn't exists. The join should be:
    ON o.product_id=p.productID
    But when I create procedure, parser doesn't raise an error. The error is raised at run time.
    Is there some option to check the SQL syntax before run time - to parse also temp table names?
    Thanks,
    Simon

    Hi Simon
    See my latest replay... I create a temporary table and then run CREATE PROCEDURE script to get the error, that was a mistake
    CREATE TABLE #t (c int)
    CREATE PROCEDURE sp1
    AS
    CREATE TABLE #t (c int)
    SELECT * FROM #t JOIN sys.objects o on #t.c1=o.object_id
    Msg 207, Level 16, State 1, Procedure sp1, Line 6
    Invalid column name 'c1'.
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

Maybe you are looking for