create or replace procedure pr
is
v_date date;
begin
select sysdate into v_date from dual;
DBMS_output.put_line(v_date);
end pr;
相关问题
- Can I skip certificate verification oracle utl_htt
- how to calculate sum time with data type char in o
- keeping one connection to DB or opening closing pe
- System.Data.OracleClient not working with 64 bit O
- How can I get rid of dynamic SQL
相关文章
- node连接远程oracle报错
- oracle 11g expdp导出作业调用失败,提示丢包。
- 执行一复杂的SQL语句效率高,还是执行多少简单的语句效率高
- Oracle equivalent of PostgreSQL INSERT…RETURNING *
- Difference between FOR UPDATE OF and FOR UPDATE
- Oracle USING clause best practice
- Is there a method in PL/SQL to convert/encode text
- PHP PDO installation on windows (xampp)
Procedure cannot be executed using select statement, you can use function if you would want to execute using select statement.
If you would want to execute procedure using select statement then one approach is wrap your procedure with a function and call function using select statement.
Now wrap the procedure with a function
And call the function using select statement
Procedures are not allowed in SQL statements because mixing declarative and imperative programming styles is confusing.
A SQL statement is a list of conditions - it's up to Oracle to decide how to produce the result set that matches those conditions. A PL/SQL stored procedure is a set of instructions that change things in a very predictable way.
In the below example, how many times should
pr
be executed? Is it executed before or afterid = 1
? If SQL statements had a pre-defined order then the optimizer would not be able to push predicates, merge subqueries, etc., and performance would be unacceptable.Even if a procedure were used in the
select
list, it may not make sense. For example, theselect
list inside anexists
is always ignored.But in reality SQL statements sometimes need to interact with the outside world, and some procedural logic is needed. Functions are allowed because they usually just calculate something and return a value. Functions normally do not depend on the program state and have a lot of side-effects. Your functions could use session variables, update tables (if it's set to
PRAGMA AUTONOMOUS TRANSACTION
), set a context, etc. Oracle can't stop you from doing those things, but disallowing procedures in SQL statements will at least discourage such code.