Если оба MYTABLE
и OTHER_TABLE
принадлежат одному и тому же пользователю, никаких привилегий не требуется:
SQL> show user
USER is "SCOTT"
SQL> create table other_table (other_Table_id number);
Table created.
SQL> create table mytable (mytable_id number);
Table created.
SQL> create or replace trigger prevent_invalid_id
2 before insert or update on mytable
3 for each row
4 declare
5 row_count number;
6 begin
7 select count(*) into row_count
8 from other_table where other_table_id = :new.mytable_id;
9
10 if row_count = 0 then
11 raise_application_error(-20101, 'The ID provided is invalid');
12 end if;
13 end;
14 /
Trigger created.
SQL>
Однако, если они принадлежат другому пользователю, то владелец OTHER_TABLE
должен предоставить SELECT
привилегию мне . Однако этого недостаточно - вы должны либо предшествовать OTHER_TABLE
имени его владельца (например, other_user.other_table
), либо создать синоним в моей собственной схеме, который указывает на другого пользователя OTHER_TABLE
. Например:
SQL> drop table other_table;
Table dropped.
SQL> connect mike/lion@xe
Connected.
SQL> create table other_table (other_Table_id number);
Table created.
SQL> grant select on other_table to scott;
Grant succeeded.
SQL> connect scott/tiger@xe
Connected.
SQL> create or replace trigger prevent_invalid_id
2 before insert or update on mytable
3 for each row
4 declare
5 row_count number;
6 begin
7 select count(*) into row_count
8 from MIKE.other_table where other_table_id = :new.mytable_id;
9
10 if row_count = 0 then
11 raise_application_error(-20101, 'The ID provided is invalid');
12 end if;
13 end;
14 /
Trigger created.
SQL>
Примечание: строка 8: MIKE.other_table
.
Просто чтобы показать, что произойдет, если вы пропустите / удалите имя владельца:
SQL> l8
8* from MIKE.other_table where other_table_id = :new.mytable_id;
SQL> c/mike.//
8* from other_table where other_table_id = :new.mytable_id;
SQL> l
1 create or replace trigger prevent_invalid_id
2 before insert or update on mytable
3 for each row
4 declare
5 row_count number;
6 begin
7 select count(*) into row_count
8 from other_table where other_table_id = :new.mytable_id;
9
10 if row_count = 0 then
11 raise_application_error(-20101, 'The ID provided is invalid');
12 end if;
13* end;
SQL> /
Warning: Trigger created with compilation errors.
SQL> show err
Errors for TRIGGER PREVENT_INVALID_ID:
LINE/COL ERROR
-------- -----------------------------------------------------------------
4/3 PL/SQL: SQL Statement ignored
5/8 PL/SQL: ORA-00942: table or view does not exist
SQL>
Видите? ОР-00942.
То, когда поток извлечет последний из 3 digist "1 2 3" состояние eof, будет установлено. Это не очищено ул. () участник, необходимо сделать это сами. Измените свой код на:
ss.clear();
ss.str(Tokens[0]);
Почему Вы читаете во временный файл string
переменная?
Можно просто читать из stringstream в интервал...
int main()
{
string Digits("1 2 3");
stringstream ss(Digits);
int Temp;
vector<int> Tokens;
while(ss >> Temp)
Tokens.push_back(Temp);
}
Необходимо сбросить все флаги состояния (eofbit) и принести поток в хорошее состояние (goodbit):
ss.clear(); // clear status flags
ss.str(Tokens[0]);
Причина состоит в том, что, если Вы продолжаете извлекать до конца, Вы поразите конец, и флаг eof будет установлен на том потоке. После этого операции чтения будут отменены, и необходимо убрать тот флаг снова. Так или иначе, после очистки и сброса строки, можно затем продолжить извлекать целые числа.
STL!:P
stringstream ss("1 2 3");
vector<int> Tokens;
copy(istream_iterator<int>(ss), istream_iterator<int>(), back_inserter(Tokens));