2
let $query_a := (for $st in $student
            where
                (some $t in $transcript
                satisfies ($t.ssn = $st.ssn and $t.dcode = "CS" and $t.cno = 530))
return {ssn: $st.ssn, name: $st.name, major: $st.major, status: $st.status}
)

Here the table student table is empty, its returning query_a as null. how to write a code if the table is empty i.e student[].

Stefan Wuebbe
  • 2,109
  • 5
  • 17
  • 28
Sandhya
  • 21
  • 1

1 Answers1

0

I think the issue in the query is that the return clause corresponding to the let clause is missing. The query has a FLWOR expression (for $st...) nested in another FLWOR expression (let $query_a...) and there must be two return clauses.

Here is a fixed query, with the indentation set to facilitate readability (it is assuming that $student and $transcript are properly bound to sequences of student objects resp. of transcript objects):

let $query_a :=
  for $st in $student
  where (
    some $t in $transcript
    satisfies ($t.ssn = $st.ssn and $t.dcode = "CS" and $t.cno = 530)
  )
  return {
    ssn: $st.ssn,
    name: $st.name,
    major: $st.major,
    status: $st.status
  }
return $query_a

Note that $query_a cannot be the "null" value (which is a sequence of one atomic item, the null item): if no item in the sequence $student passes the predicate filter, then $query_a will be the empty sequence of items.

You can then test if a sequence is empty or not with the function empty:

if(empty($sequence))
then ...
else ...
Ghislain Fourny
  • 6,971
  • 1
  • 30
  • 37