我在oracle数据库中存储了过程,我想在NestJs中调用它。 如何在NestJs中调用存储过程?
这是我的存储过程
PROCEDURE pipeline_critical (
i_main_company IN NUMBER,
o_value OUT NUMBER
) AS
BEGIN
SELECT COUNT(A.PIPELINE_ID) AS IGNORED_PIPELINE
INTO o_value
FROM T_PIPELINE A
LEFT JOIN T_PIPELINE_PRODUCT P ON P.PIPELINE_ID = A.PIPELINE_ID
WHERE
1 = ( CASE WHEN
i_main_company <> 3
AND A.MAIN_COMPANY_ID = i_main_company
AND TO_CHAR(A.EST_DELIVERY,'YYYY') >= TO_CHAR(SYSDATE,'YYYY') - 1
AND A.PIPELINE_STATUS_ID IN (1,2,3)
AND TO_CHAR(ADD_MONTHS(A.UPDATE_DATE,3),'YYYYMM') < TO_CHAR(SYSDATE,'YYYYMM')
AND P.PAID_DATE IS NULL THEN 1
WHEN
i_main_company = 3
AND TO_CHAR(A.EST_DELIVERY,'YYYY') >= TO_CHAR(SYSDATE,'YYYY') - 1
AND A.PIPELINE_STATUS_ID IN (1,2,3)
AND TO_CHAR(ADD_MONTHS(A.UPDATE_DATE,3),'YYYYMM') < TO_CHAR(SYSDATE,'YYYYMM')
AND P.PAID_DATE IS NULL THEN 1
END
);
END pipeline_critical;
答案 0 :(得分:1)
我正在迁移Javascript /隔离后端,并且正在测试我的需求。 这是一个对我有用的简单示例:
这是存储过程
CREATE PROCEDURE sp_prueba
@email varchar(100)
AS
BEGIN
SET NOCOUNT ON;
select * from tbusua where emai_usua=@email
END
在NESTJS-控制器中
import { Controller, Get, Param } from '@nestjs/common';
import { UsuariosService } from './usuarios.service';
import { async } from 'rxjs/internal/scheduler/async';
import { Usuario } from './usuarios.entity';
@Controller('Usuarios')
export class UsuariosController {
constructor(private readonly UsuariosService: UsuariosService) { }
@Get('/:email')
async find(@Param('email') email): Promise <Usuario[]>{
return await this.UsuariosService.find(email);
}
}
在NESTJS中-服务中的TypeORM后端
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Usuario } from './usuarios.entity';
import { Repository, Db, EntityManager } from 'typeorm';
@Injectable()
export class UsuariosService {
constructor(
@InjectRepository(Usuario)
private readonly usuariosRepository: Repository<Usuario>) { }
async find(email: string): Promise<Usuario[]>{
return await this.usuariosRepository.query("sp_prueba @email='"+email +"'");
}
}
这对我有用