如何在 Insert 语句中使用 PL SQL 常量
我是 PL SQL 代码新手,需要帮助编写插入查询语句。 例如:我想在员工表中插入员工,其中只有员工姓名发生变化,但城市不变。
DECLARE
emp_var_prefix varchar2(12) := 'QATEST';
emp_var_temp varchar2(12) := '';
city constant varchar(30) := 'dallas'
begin
DBMS_OUTPUT.ENABLE;
for i in 1..2 loop
emp_var_temp := emp_var_prefix;
emp_var_temp := emp_var_prefix ||i;
INSERT INTO EMPLOYEE TABLE ('EMPLOYEE_NAME', 'CITY') values ('emp_var_temp', '<what should I put here for constant dallas for city name>');
DBMS_OUTPUT.PUT_LINE(emp_var_temp);
end loop;
END;
I am new to PL SQL Code and need help writing Insert query statement .
eg: I want to insert Employee in Employees table where only employee name changes but the city is constant.
DECLARE
emp_var_prefix varchar2(12) := 'QATEST';
emp_var_temp varchar2(12) := '';
city constant varchar(30) := 'dallas'
begin
DBMS_OUTPUT.ENABLE;
for i in 1..2 loop
emp_var_temp := emp_var_prefix;
emp_var_temp := emp_var_prefix ||i;
INSERT INTO EMPLOYEE TABLE ('EMPLOYEE_NAME', 'CITY') values ('emp_var_temp', '<what should I put here for constant dallas for city name>');
DBMS_OUTPUT.PUT_LINE(emp_var_temp);
end loop;
END;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来你会想要类似的东西,
一般来说,使用同时也是列名的变量名是一个坏主意——这使得你很可能会遇到范围错误,当你打算引用一个变量和编译器无意中假定您要引用该列。这些调试起来相当麻烦。采用一些约定会更容易,例如在局部变量前添加
l_
前缀,以将它们与可以使用p_
前缀的列名或参数区分开来。It appears that you would want something like
It is a bad idea in general to use variable names that are also column names-- that makes it exceedingly likely that you're going to encounter scope bugs where you intend to refer to a variable and the compiler inadvertently assumes that you meant to refer to the column. Those are rather nasty to debug. It's easier to adopt some convention like prefixing local variables with
l_
to differentiate them from column names or parameters that can be prefixed withp_
.