【问题标题】:ORA-01722 error messageORA-01722 错误消息
【发布时间】:2015-05-03 19:19:37
【问题描述】:

我正在尝试将一些数据输入到 oracle 表中,并且收到错误代码 ORA-01722。我相信这是因为 Trader ID 是一个数字,但它说它不能将字符串转换为数字。代码如下。

表格

<form method="post" action="recipesql.php" >
      <table align="center">
<tr>
            <td align="right">Recipe Name:</td>
            <td align="left"><input type="text" name="RecipeName"></td>
         </tr>
         <tr>
            <td align="right">Media Type:</td>
            <td align="left"><input type="text" name="MediaType"></td>
         </tr>
         <tr>
            <td align="right">Recipe:</td>
            <td align="left"><input type="text" name="Recipe" /></td>
         </tr>
         <tr>
            <td align="right">Video Link (e.g /embed/12345):</td>
            <td align="left"><input type="text" name="Link"></td>
         </tr>
         <tr>
            <td align="right">Trader ID:</td>
            <td align="left"><input type="number" name="TraderID"></td>
         </tr>
      </table>
      <input type="submit" value="Submit" name="Submit">

   </form>

PHP

//include connection
include ('PHP/connection.php');
//has form been submitted?
if(isset($_POST['Submit'])){
    $RecipeName=$_POST['Name'];
    $MediaType=$_POST['MediaType'];
    $Recipe=$_POST['Recipe'];
    $Link=$_POST['Video_Link'];
    $TraderID=$_POST['Trader_ID'];
//Insert data
$query = "INSERT INTO MEDIA
(Media_Id, Name, MediaType, Recipe, Video_Link, Trader_ID)
VALUES
('MEDIA_seq.nextval','$RecipeName','$MediaType','$Recipe','$Link','$TraderID')";

$runquery = oci_parse($connection,$query);
oci_execute($runquery);
} 
//to check if the if statement is working
else
{
    echo "Error";
}

错误代码警告:oci_execute() [function.oci-execute]:ORA-01722:recipesql.php 第 19 行中的数字无效

【问题讨论】:

    标签: php oracle


    【解决方案1】:

    认为应该是:

    $query = "INSERT INTO MEDIA (Media_Id, Name, MediaType, Recipe, Video_Link, Trader_ID) 
    VALUES (MEDIA_seq.nextval,'$RecipeName','$MediaType','$Recipe','$Link','$TraderID')";
    

    MEDIA_seq.nextval 未包含在 '' 中。否则,它会被解释为VARCHAR2,并将其插入NUMBER 列会导致ORA-01722

    【讨论】:

      猜你喜欢
      • 2018-02-14
      • 2015-04-06
      • 2012-09-14
      • 1970-01-01
      • 1970-01-01
      • 2021-05-03
      • 2020-08-23
      • 2019-08-20
      相关资源
      最近更新 更多