In Oracle Sql developer 11g, how do I generate a random integer and assign it to a variable? This is what I\'ve tried so far:
S_TB := SELECT dbms_random.value(1,
Variables require PL/SQL; it's not clear from your question whether your code is a proper PL/SQL block. In PL/SQL variables are populated from queries using the INTO syntax rather than the assignment syntax you're using.
declare
txt varchar2(128);
n pls_integer;
begin
-- this is how to assign a literal
txt := 'your message here';
-- how to assign the output from a query
SELECT dbms_random.value(1,10) num
into n
FROM dual;
end;
Although, you don't need to use the query syntax. This is valid, and better practice:
declare
n pls_integer;
begin
n := dbms_random.value(1,10);
end;