基本的Oracle问题
我是甲骨文新手。当我使用以下命令创建存储过程时:
CREATE OR REPLACE PROCEDURE PROCEDURE1
AS
BEGIN
SELECT FIRSTNAME,
LASTNAME
INTO FirstName,LastName
FROM EMPLOYEE;
END PROCEDURE1;
出现以下错误:
PL/SQL 语句被忽略 必须声明标识符 FIRSTNAME ORA-00904 无效标识符
I am new to oracle. When I create a stored procedure using:
CREATE OR REPLACE PROCEDURE PROCEDURE1
AS
BEGIN
SELECT FIRSTNAME,
LASTNAME
INTO FirstName,LastName
FROM EMPLOYEE;
END PROCEDURE1;
i get the following errors:
PL/SQL Statement Ignored
Identifier FIRSTNAME must be declared
ORA-00904 Invalid identifier
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要在尝试填充变量之前声明它们:
%TYPE 表示法是与列数据类型匹配的数据类型声明的简写。如果该数据类型发生变化,您无需更新过程。
You need to declare variables before you attempt to populate them:
The %TYPE notation is shorthand for data type declaration that matches the column data type. If that data type ever changes, you don't need to update the procedure.
您需要声明变量。
回复您的评论,PL/SQL 块中的 SQL 语句只能获取 1 条记录。如果需要获取多条记录,则需要将记录存储在游标中并对其进行处理。
解释一下:
EMP_CUR
保存要执行的 SQL 语句。EMP_CUR_REC
保存将由 SQL 语句获取的记录。%ROWTYPE
表示记录将与保存数据的行具有相同的数据类型FOR LOOP
将获取每条记录,您可以执行任何需要的处理待完成。You need to declare the variables.
In reply to your comment, SQL statements in PL/SQL block can fetch only 1 record. If you need to fetch multiple records, you will need to store the records in a cursor and process them.
To explain:
EMP_CUR
holds the SQL statement to be executed.EMP_CUR_REC
holds the records that will be fetched by the SQL statement.%ROWTYPE
indicates that the Record will be of the same data type as the row which holds the dataThe
FOR LOOP
will fetch each record, and you can do whatever processing that needs to be done.我认为“AS”关键字不起作用。如果不起作用,请使用“IS”。
休息很好,而且有很好的建议。
如果您需要有关 PL/SQL 的任何帮助,可以查看此链接。它非常简单易懂;
http://plsql-tutorial.com/
这是我对您遇到的错误的解决方案;
您还可以在循环内使用
DBMS_OUTPUT.PUT_LINE(V_FIRSTNAME || ','|| V_LASTNAME)
来显示输出。但为了做到这一点,您首先需要执行命令服务器输出
I think the "AS" keyword won't work. If it doesn't work, then use "IS".
Rest are fine and very good tips.
If you need any help regarding PL/SQL, then you can have a look at this link. It is very simple and easy to understand;
http://plsql-tutorial.com/
This is my solution to the error which you are getting;
You can also use
DBMS_OUTPUT.PUT_LINE(V_FIRSTNAME || ','|| V_LASTNAME)
, inside the loop to display the output. but in order to do that, you first need to execute the commandserver output on
在对上面 @Sathya 的回答的回应中,@kayak 询问“我可以有类似 Select * from Tablename 或 select firstname,lastname from tablename 的东西吗,就像我们在 sql server 中一样”。
是的,您可以这样做,但您需要包含 WHERE 子句或使用游标。如果您包含一个将结果限制为单行的 WHERE 子句,您可以编写类似的内容
另一方面,如果您没有 WHERE 子句,因为您希望处理表中的所有行,或者您有一个 WHERE子句不将结果限制为单行,您可以按以下方式使用游标:
共享并享受。
In a response to @Sathya's answer above @kayak asked "Can i have something like Select * from Tablename or select firstname,lastname from tablename , like we have in sql server".
Yes, you can do that, but you'll either need to include a WHERE clause or use a cursor. If you include a WHERE clause which limits your results to a single row you could write something like
On the other hand, if you either don't have a WHERE clause because you wish to process all rows in the table, or you have a WHERE clause which doesn't limit your results to a single row you could use a cursor in the following manner:
Share and enjoy.