Оценка МН логических переменных / логических переменных SQL в Формах Oracle

Если можно изменить строку:

// Note: This function returns a pointer to a substring of the original string.
// If the given string was allocated dynamically, the caller must not overwrite
// that pointer with the returned value, since the original pointer must be
// deallocated using the same allocator with which it was allocated.  The return
// value must NOT be deallocated using free() etc.
char *trimwhitespace(char *str)
{
  char *end;

  // Trim leading space
  while(isspace((unsigned char)*str)) str++;

  if(*str == 0)  // All spaces?
    return str;

  // Trim trailing space
  end = str + strlen(str) - 1;
  while(end > str && isspace((unsigned char)*end)) end--;

  // Write new null terminator character
  end[1] = '\0';

  return str;
}

, Если Вы не можете изменить строку, тогда можно использовать в основном тот же метод:

// Stores the trimmed input string into the given output buffer, which must be
// large enough to store the result.  If it is too small, the output is
// truncated.
size_t trimwhitespace(char *out, size_t len, const char *str)
{
  if(len == 0)
    return 0;

  const char *end;
  size_t out_size;

  // Trim leading space
  while(isspace((unsigned char)*str)) str++;

  if(*str == 0)  // All spaces?
  {
    *out = 0;
    return 1;
  }

  // Trim trailing space
  end = str + strlen(str) - 1;
  while(end > str && isspace((unsigned char)*end)) end--;
  end++;

  // Set output size to minimum of trimmed string length and buffer size minus 1
  out_size = (end - str) < len-1 ? (end - str) : len-1;

  // Copy trimmed string and add null terminator
  memcpy(out, str, out_size);
  out[out_size] = 0;

  return out_size;
}
12
задан ShoeLace 15 February 2010 в 23:09
поделиться

5 ответов

Какое значение устанавливается переменной? Следует понимать, что если значение равно нулю, блок никогда не будет выполнен. Я не уверен, что это ваша проблема, но вот пример:

DECLARE
is_viewable BOOLEAN;
BEGIN
  IF NOT is_viewable
  THEN
      /* this won't execute */
      dbms_output.put_line('nope');
  END IF;
  IF is_viewable
  THEN
      /* neither will this */
      dbms_output.put_line('nope');
  END IF;
END;

Конечно, я не знаю, как Oracle Forms будет делать это по-другому, но, может быть, он каким-то образом устанавливает для переменной значение null?

4
ответ дан 2 December 2019 в 05:41
поделиться

НЕ is_viewable оценивается как ИСТИНА тогда и только тогда, когда is_viewable равно ЛОЖЬ .

В вашем случае для is_viewable , вероятно, установлено значение NULL ; возможно, отладчик Forms покажет вам "ЛОЖЬ" в этом сценарии, вызывая путаницу.

Попробуйте вместо этого использовать этот код:

IF NOT is_viewable THEN 
   raise_my_error();
ELSIF is_viewable IS NULL THEN
   raise_another_error();
END IF;
4
ответ дан 2 December 2019 в 05:41
поделиться

Try this to see if it changes anything:

IF is_viewable THEN
    NULL;
ELSE
    raise_my_error();
END IF;
1
ответ дан 2 December 2019 в 05:41
поделиться

Мы можем проверить это в SQLPlus, чтобы увидеть, что происходит в каждой из 3 ситуаций (true, false, null):

set serveroutput on

declare
  true_value boolean := true;
  false_value boolean := false;
  null_value boolean;
begin

    if not true_value then  --Should not pass
      dbms_output.put_line('True Value');
    end if;

    if not false_value then --Should pass
      dbms_output.put_line('False Value');
    end if;

    if null_value is null then --Just to make sure it is null
      dbms_output.put_line('Null Value is Null');
    end if;

    if not null_value then --Should not pass
      dbms_output.put_line('Null Value');
    end if;
end;
/

Что приводит:

SQL> set serveroutput on
SQL>
SQL> declare
  2    true_value boolean := true;
  3    false_value boolean := false;
  4    null_value boolean;
  5  begin
  6
  7      if not true_value then  --Should not pass
  8        dbms_output.put_line('True Value');
  9      end if;
 10
 11      if not false_value then --Should pass
 12        dbms_output.put_line('False Value');
 13      end if;
 14
 15      if null_value is null then --Just to make sure it is null
 16        dbms_output.put_line('Null Value is Null');
 17      end if;
 18
 19      if not null_value then --Should not pass
 20        dbms_output.put_line('Null Value');
 21      end if;
 22  end;
 23  /
False Value
Null Value is Null

PL/SQL procedure successfully completed.

SQL>

Таким образом, единственный возможный кодовый путь, который может создать ожидаемый выход, если значение, переходящее в условный является false. Если это не то, что вы видите или ожидаете, то что-то еще должно произойти в вашей процедуре или как побочный эффект.

15
ответ дан 2 December 2019 в 05:41
поделиться

Какая версия Forms?
Я только что попробовал выполнить следующий код в Forms Builder 6i, и он работает должным образом

DECLARE
    bTest BOOLEAN;
BEGIN
   bTest := FALSE;
    IF NOT bTest THEN
        MESSAGE('NOT FALSE passed'); 
        PAUSE;
    END IF;

    bTest := TRUE;
    IF bTest THEN
        MESSAGE('TRUE passed'); 
        PAUSE;
    END IF;

    bTest := NULL;
    IF bTest OR (NOT bTest) THEN
        MESSAGE('You will never see this message'); 
        PAUSE;
    END IF;
END;

Работает ли это в вашей среде?

Правка добавила null в пример.

1
ответ дан 2 December 2019 в 05:41
поделиться
Другие вопросы по тегам:

Похожие вопросы: