SAP HANA SQLScript
Imperative SQLScript: Variables, Flow & Cursors
23 flashcards · answers and spaced-repetition review in the KnowCard app
In SQLScript, why is a declarative SELECT usually faster than an imperative loop that produces the same result?
Reading :tv.title[99] when the table variable has only 10 rows — error, or something else? And writing to [99]?
With the table operator :tv.INSERT((…), <position>) (SPS 01+), what does supplying a position do versus omitting it?
A table variable has 3 rows, then :ot.UPDATE(('Update 4'), 4) runs. What is the result?
What does the OUTER block see for var1?
```
DECLARE var1 VARCHAR(10)='Outer';
BEGIN
DECLARE var1 VARCHAR(10);
var1 = 'Inner';
END;
-- outer: SELECT :var1
```
You move an IF EXISTS (SELECT …) check inside a WHILE loop that runs 10,000 times. What happens to runtime versus the same EXISTS in a declarative query?
Migrating ABAP to SQLScript, you hit a reading LOOP AT itab. What's the recommended translation?
Does DECLARE lv_x INT NOT NULL; give the variable a starting value?
Rewrite this row-by-row cursor as one declarative statement:
```
FOR ls AS c_titles DO
v = :v || ' - ' || ls.title;
END FOR;
```
What does lv_sum hold after this runs?
```
DECLARE lv_sum INT;
FOR i IN 1..10 DO
lv_sum = :lv_sum + 10;
END FOR;
```
Name the four ways to call .DELETE() on a table variable.
What does :lt.SEARCH((status, assignee), (3,3)) return, and where can't you use it?
You built :lt_x with .INSERT(...) table operators. Can you now also run INSERT INTO :lt_x (SELECT …) on it?
How do you count the rows of a table variable, and how do you test whether it's empty, inside imperative code?
How do you assign two scalar variables at once from a single call, without writing two statements?
What happens if a SELECT … INTO lv_x FROM tasks WHERE … matches zero rows? What about three rows?
Since SAP HANA 2.0 SPS 03 you can add DEFAULT -1 to a SELECT … INTO. Which failure does it actually rescue?
Which of these are NOT allowed in an imperative IF condition: ALL, IS NULL, ANY, EXISTS, SOME, IN?
During development you're unsure a loop terminates. Why start with a FOR loop rather than WHILE?
Inside a loop, what's the difference between BREAK and CONTINUE?
What does FOR row AS my_cursor DO … END FOR give you that explicit OPEN/FETCH/CLOSE does not?
In FETCH c INTO v; IF c::NOTFOUND THEN BREAK;, when is c::NOTFOUND TRUE?
How do you UPDATE the exact row a cursor is currently sitting on (SPS 03+)?
Start learning today
Free to start — download the app or use it in your browser.
