gpt4 book ai didi

sql - 甲骨文 00932.00000 - "inconsistent datatypes: expected %s got %s"

转载 作者:行者123 更新时间:2023-12-04 20:56:39 26 4
gpt4 key购买 nike

好吧,我还是 oracle 的新手,我正在尝试使用子查询查询表..它看起来像这样

select id_user, count(*) as jumlah from (select * from users where username = 'usr' and pass = 'pwd' and company_id = 'PAN' and status = 1) 
group by id_user;

上面的代码有效。但是当我尝试将它放入存储过程时,出现了一些类似这样的错误

存储过程

create type login_obj is object(jumlah integer);
create type login_table is table of login_obj;
create or replace function startLogin(u varchar, p varchar, cid varchar)
return login_table
is
tabel login_table := login_table();
the_count integer;
the_sql varchar(200);
begin
the_sql := 'select id_user, count(*) as jumlah from (select * from users where username = ''' || u || ''' and pass = ''' || p || ''' and company_id = ''' || cid || ''' and status = 1) GROUP BY id_user';
execute immediate the_sql into the_count;

if the_count IS NOT NULL
then
begin
tabel.extend;
tabel(1) := login_obj(the_count);
end;
end if;
return tabel;
end;

然后执行

select * from table (startLogin('usr','pwd','PAN'));

这里是错误

SQL Error: ORA-00932: inconsistent datatypes: expected - got -
ORA-06512: at "LUKI.STARTLOGIN", line 14
00932. 00000 - "inconsistent datatypes: expected %s got %s"

有什么想法吗?

最佳答案

在该行下方再添加一个变量

the_sql varchar(200);

作为

yid_user users.id_user%TYPE;

并将您的立即执行更改为

execute immediate the_sql into yid_user, the_count;

还有一些在 Oracle 中使用变量类型的技巧:

1. VARCHAR is obsolete, use VARCHAR2 instead.
2. Instead of using INTEGER type, use NUMBER.

关于sql - 甲骨文 00932.00000 - "inconsistent datatypes: expected %s got %s",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30153645/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com