create or replace procedure pro_test
is
begin
select * from t_test;
end pro_test;
这个正确吗?
昨天因为这个,耽误了好久(在一个存储过程中用了select语句,但既没有用游标也没有用into).
在存储过程(oracle)中如果用了select语句,要么使用"select into 变量"语句要么使用游标,oracle不支持单独的select语句(如表述有误请指出).
select into 比较简单,但是如果返回的是一个结果集就无法满足要求了.
游标分cursor型游标和sys_refcursor型游标两种
cursor型游标--不能用于参数传递
create or replace procedure pro_test() is
cusor_1 cursor is select 字段名 from 表名 where 条件;
(或者
select class_name into cursor_2 from class where ...;
cursor的另一种用法,需要写在begin和end之间)
begin
select class_name into cursor_2 from class where ...;
可以使用
for xxx in cursor
loop
....
end loop; --对cursor进行遍历
end pro_test;
sys_refcursor型游标
create or replace procedure pro_test(rscursor out sys_refcursor) is
cursor sys_refcursor;
name varhcar(20);
begin
open cursor for
select name from student where ...; --使用open来打开进行赋值
--遍历
loop
fetch cursor into name --fetch into来打开遍历的每条数据
exit when cursor%notfound; --未找到记录信息
dbms_output.putline(xxxx);
end loop;
rscursor := cursor;
end pro_test;
如何在存储过程中调用其他的存储过程(这些都是带参数的)
一个带参数的存储过程。
sql> create or replace procedure helloworld1 (
2 p_user_name varchar2
3 ) as
4 begin
5 dbms_output.put_line('hello ' || p_user_name || '!');
6 end helloworld1;
7 /procedure created.
sql> create or replace procedure callhelloworld1 (
2 p_user varchar2
3 ) as
4 begin
5 -- 调用存储过程的 存储过程
6 helloworld1(p_user);
7 end callhelloworld1;
8 /procedure created.
执行
sql> set serveroutput on
sql> exec callhelloworld1( 'tom' );
hello tom!pl/sql procedure successfully completed.

方法:1、利用“select*from user_indexes where table_name=表名”语句查询表中索引;2、利用“select*from all_indexes where table_name=表名”语句查询所有索引。

oracle asm指的是“自动存储管理”,是一种卷管理器,可自动管理磁盘组并提供有效的数据冗余功能;它是做为单独的Oracle实例实施和部署。asm的优势:1、配置简单、可最大化推动数据库合并的存储资源利用;2、支持BIGFILE文件等。

在Oracle中,可利用lsnrctl命令查询端口号,该命令是Oracle的监听命令;在启动、关闭或重启oracle监听器之前可使用该命令检查oracle监听器的状态,语法为“lsnrctl status”,结果PORT后的内容就是端口号。

在oracle中,可以利用“TO_SINGLE_BYTE(String)”将全角转换为半角;“TO_SINGLE_BYTE”函数可以将参数中所有多字节字符都替换为等价的单字节字符,只有当数据库字符集同时包含多字节和单字节字符的时候有效。

方法:1、利用“LOWER(字段值)”将字段转为小写,或者利用“UPPER(字段值)”将字段转为大写;2、利用“REGEXP_LIKE(字符串,正则表达式,'i')”,当参数设置为“i”时,说明进行匹配不区分大小写。

在oracle中,可以利用“drop sequence sequence名”来删除sequence;sequence是自动增加数字序列的意思,也就是序列号,序列号自动增加不能重置,因此需要利用drop sequence语句来删除序列。

在oracle中,可以利用“select ... From all_tab_columns where table_name=upper('表名') AND owner=upper('数据库登录用户名');”语句查询数据库表的数据类型。

方法:1、利用“alter system set sessions=修改后的数值 scope=spfile”语句修改session参数;2、修改参数之后利用“shutdown immediate – startup”语句重启服务器即可生效。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

Dreamweaver CS6
視覺化網頁開發工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

WebStorm Mac版
好用的JavaScript開發工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。