oracle查询一变量语句?

jackch88 2008-08-28 03:04:42
在sql server中查询一变量直接select a 就可以了。
如:declare @a as int;
set @a=1;
select @a;
而Oracle中的类似查询语句是啥?
...全文
319 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hyrongg 2008-08-29
  • 打赏
  • 举报
回复

SQL> create or replace function fntest
2 return nvarchar2
3 is
4 ename nvarchar2(30);
5 begin
6 select first_name into ename from hr.employees where rownum = 1;
7 return ename;
8 end;
9 /

Function created

SQL> set serveroutput on;
SQL>
SQL> declare
2 ename nvarchar2(30);
3 begin
4 select fntest into ename from dual;
5 dbms_output.put_line(ename);
6 end;
7 /

Steven

PL/SQL procedure successfully completed
jackch88 2008-08-28
  • 打赏
  • 举报
回复
那我掉用Oracle存储过程,返回值怎么取?
DECLARE re number;
BEGIN
re:=fun();
commit;
END;
--------------------
不要输出,直接取re值
hyrongg 2008-08-28
  • 打赏
  • 举报
回复
Oracle不支持存储过程里面直接返回查询类似SQL的

create procedure test
as
begin
select * from table
end

在oracle里面行不通。
用返回游标的方式?
jackch88 2008-08-28
  • 打赏
  • 举报
回复
楼上的,你那语句只是输出。我要查询
hyrongg 2008-08-28
  • 打赏
  • 举报
回复

SQL> set serveroutput on;
SQL>
SQL> declare
2 a int;
3 b int;
4 begin
5 a:=1;
6 dbms_output.put_line(a);
7 select a into b from dual;
8 dbms_output.put_line(b);
9 end;
10 /

1
1

PL/SQL procedure successfully completed



17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧