Skip to content
Advertisement

Understand and convert query to Oracle SQL

I am a little bit confusing and I am totally nOoB in PHP and I stuck in one query which made me problem.

 $sql = "UPDATE student SET Status = $stuStatus".($status === 'success-student' ? ', Marks = 2' : '')." WHERE StudentId = {$data['studentID']};";

If I would like transform this to Oracle SQL Is is something like this

UPDATE student SET Status = status (SELECT CASE WHEN status = 'success-student' THEN Mark = 2) WHERE StudentId = $studentId

Advertisement

Answer

Check the following:

$sql = "UPDATE student SET Status =". $stuStatus ." ,  Marks =" . ($status === 'success-student' ? '2' : '') . " WHERE StudentId = " . $data['studentID'] . ";";

It should produce an SQL query as follow, which will put the mark 2 if the student status equals success-student.

/*
 example: 
   $stuStatus = 'success'
   $status = 'success-student'
   $data['studentID'] = 1 
*/

UPDATE student SET Status = 'success', Marks = 2 WHERE StudentId = 1;
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement