我很困惑,因为我向内看并试图解决问题。我有PHP正在运行的应用程序Oracle DB,到目前为止,一些表达式是在 MySQL 中编写的,现在我想将这些查询迁移到Oracle SQL函数并调用函数,而不是直接将查询写入模型。情况如下我有功能线
public function getAtaNumber($data) {
if( $data["Type"] == 1 ) {
$sql = "SELECT SUM(NextNumber) + 1 AS NextNumber
FROM (
SELECT COUNT(a1.ATAID) AS NextNumber
FROM ata AS a1
WHERE a1.ProjectID = '".$data["project"]["id"]."'
AND a1.Ata = 1
AND a1.ParentAta = 0
AND a1.TYPE = 1
AND a1.BecomeExternalAtaFromInternal = 0
UNION ALL
SELECT COUNT(a2.ATAID) AS NextNumber
FROM ata AS a2
WHERE a2.ProjectID = '".$data["project"]["id"]."'
AND a2.Ata = 1
AND a2.ParentAta = 0
AND a2.BecomeExternalAtaFromInternal = 1 ) AS A";
} else {
$sql = "SELECT COUNT(ata.ATAID) + 1 AS NextNumber
FROM ata
WHERE ProjectID = '".$data["project"]["id"]."'
AND Ata = 1
AND ParentAta = 0
AND Type = 0
ORDER BY ATAID DESC
LIMIT 1;";
if (!$result = $conn->query($sql)) {
error_log($conn->error);
return false;
}
}
}
这让我很困惑,我不知道如何编写这段安静的代码。因为我运行了它们两个的 SELECT 语句并且它返回了正确的结果,但我不知道该怎么办,IF 因为这是二维数组,我不知道如何在PLSQL Oracle SQL 运行第一个 SELECT 语句时写入它
暮色呼如