今天有一段代码,先是用程序实现。

闲来无聊,又用存储过程实现了一次。

程序中实现。

        /// <summary>
/// 根据区域和用户名获取可访问的国家
/// </summary>
public DataTable GetCountry(string area,string user)
{
try
{
NHibernate.Engine.ISessionImplementor FactoryImpl = FrameWork.Repository.NHb.SessionBuilder.CreateSession().GetSessionImplementation();
OracleCommand cmd = new OracleCommand(); string strWhere1 = "1=1 ";
string strWhere2 = "1=1 "; if (!String.IsNullOrEmpty(user))
{
strWhere1 += String.Format( "and vrs.u_logname = '{0}'",user);
} if (!String.IsNullOrEmpty(area))
{
strWhere2 += String.Format("and cc.sales_area = '{0}'", area);
}
string sqlstr =String.Format( @"select distinct scg.customer_country,cc.sales_area,cc.countrye,cc.countryc
from ifce.vw_rsh_user vru,
ele_bill.sap_customer_general scg,
shipuser.countryce cc
where vru.sap_cust_no = scg.customer_number
and scg.customer_country = cc.short_e
and vru.u_loginid in
(select column_value countryId
from table(splitstr_fun((select vrs.u_loginid || ',' ||
vrs.agent_user_id
from ifce.vw_rsh_user vrs
where {0}),
',')))
and {1}", strWhere1, strWhere2); cmd.Parameters.Clear(); OracleConnection conn = (OracleConnection)FactoryImpl.Connection;
cmd.Connection = conn;
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = sqlstr;
cmd.ExecuteNonQuery(); OracleDataAdapter da = new OracleDataAdapter(cmd);
System.Data.DataSet ds = new System.Data.DataSet();
da.Fill(ds);
return ds.Tables[];
}
catch (Exception e)
{
throw new FrameWork.THrException("Fail!", e);
}
}

存储过程中实现。

  /*******************************************************/
/* 根据区域和用户名获取可访问的国家 */
/* create bby wufei 2013 11 26 */
/*******************************************************/
procedure Query_Country(p_area varchar2,
p_user varchar2,
x_cur out cur_forlog) is
strWhere1 varchar2(100);
strWhere2 varchar2(100);
sqlstr varchar2(1000);
begin strWhere1 := '1=1 ';
strWhere2 := '1=1 '; if (p_user is not null) then
strWhere1 := strWhere1 || ' and vrs.u_logname = ''''||''' || p_user || '''||''''';
end if; /* if p_area is not null then
strWhere2 := strWhere2 || 'and cc.sales_area =''' || p_area '''';
end if;*/ sqlstr:='select distinct scg.customer_country,
cc.sales_area,
cc.countrye,
cc.countryc
from ifce.vw_rsh_user vru,
ele_bill.sap_customer_general scg,
shipuser.countryce cc
where vru.sap_cust_no = scg.customer_number
and scg.customer_country = cc.short_e
and vru.u_loginid in (select column_value countryId
from table(splitstr_fun((select vrs.u_loginid || '','' ||
vrs.agent_user_id
from ifce.vw_rsh_user vrs
where ' || strWhere1 ||'),
'','')))
and '|| strWhere2 ;
dbms_output.put_line(sqlstr);
open x_cur for
sqlstr; exception
when others then
null;
end Query_Country;

其中存储过程中还是有一些亮点的,比如将将查询table化,比如splitstr_fun。

数据库编程与C#编程互译的更多相关文章

  1. R语言读入数据库的中英名词互译测试并计分脚本(考试用)

    1. 分子生物学中英文.csv,输入文件,两列,以tab键分隔的txt文本,没有列名 2. 错误的名解.csv, 如果在测试中拼写错误,会写出到这个文件,可用这个容易犯错的名词进行新的测试 3. 注意 ...

  2. SQL Server数据库的基础脚本编程

    数据库脚本的基础编程 Go批量处理语句 用于同时处理多条语句 use指定数据库或表 use master --创建数据库 go use Student --创建表(Student)表示数据库 go 创 ...

  3. python 闯关之路四(下)(并发编程与数据库编程) 并发编程重点

    python 闯关之路四(下)(并发编程与数据库编程)   并发编程重点: 1 2 3 4 5 6 7 并发编程:线程.进程.队列.IO多路模型   操作系统工作原理介绍.线程.进程演化史.特点.区别 ...

  4. 物联网网络编程、Web编程综述

    本文是基于嵌入式物联网研发工程师的视觉对网络编程和web编程进行阐述.对于专注J2EE后端服务开发的童鞋们来说,这篇文章可能稍显简单.但是网络编程和web编程对于绝大部分嵌入式物联网工程师来说是一块真 ...

  5. RPC 编程 使用 RPC 编程是在客户机和服务器实体之间进行可靠通信的最强大、最高效的方法之一。它为在分布式计算环境中运行的几乎所有应用程序提供基础。

    RPC 编程 使用 RPC 编程是在客户机和服务器实体之间进行可靠通信的最强大.最高效的方法之一.它为在分布式计算环境中运行的几乎所有应用程序提供基础.本文介绍 RPC 客户机和服务器之间基本的事件流 ...

  6. 【憩园】C#并发编程之异步编程(一)

    写在前面 C#5.0中,对异步编程进行了一次革命性的重构,引入了async和await这两个关键字,使得开发人员在不需要深刻了解异步编程的底层原理,就可以写出十分优美而又代码量极少的代码.如果使用得当 ...

  7. C#复习笔记(5)--C#5:简化的异步编程(异步编程的基础知识)

    异步编程的基础知识 C#5推出的async和await关键字使异步编程从表面上来说变得简单了许多,我们只需要了解不多的知识就可以编写出有效的异步代码. 在介绍async和await之前,先介绍一些基础 ...

  8. C#并发编程之异步编程2

    C#并发编程之异步编程(二)   写在前面 前面一篇文章介绍了异步编程的基本内容,同时也简要说明了async和await的一些用法.本篇文章将对async和await这两个关键字进行深入探讨,研究其中 ...

  9. 物联网网络编程和web编程

    本文是基于嵌入式物联网研发project师的视觉对网络编程和web编程进行阐述. 对于专注J2EE后端服务开发的同学来说,这篇文章可能略微简单.可是网络编程和web编程对于绝大部分嵌入式物联网proj ...

  10. 老师的blog整理 .网络编程部分 .网络编程部分 前端部分 django基础部分

    老师的blog整理 .网络编程部分 .网络编程部分 前端部分 django基础部分   老师的blog整理 python基础部分: 宝哥blog: https://www.cnblogs.com/gu ...

随机推荐

  1. C# 浅谈委托----温故而知新

    先看看委托的概述: •委托类似于 C++ 函数指针,但它们是类型安全的. • 委托允许将方法作为参数进行传递. • 委托可用于定义回调方法. • 委托可以链接在一起:例如,可以对一个事件调用多个方法. ...

  2. EntityFrame6在本地可以正常使用,部署到IIS后报异常(Additional information: The underlying provider failed on Open.)

    异常详细:An exception of type 'System.Data.Entity.Core.EntityException' occurred in EntityFramework.SqlS ...

  3. 输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的。

    // test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  4. WCF 之 OperationContract

    这里主要说的是同名异常: [ServiceContract] public interface IUserInfo { [OperationContract] string ShowName(stri ...

  5. Lua 简单的IO交互 和迷宫代码

    function room1 () print("in room1") local move = io.read() if move == "south" th ...

  6. java.util.ResourceBundle

    转载自: http://lavasoft.blog.51cto.com/62575/184605 这个类提供软件国际化的捷径.通过此类,可以使您所编写的程序可以:          轻松地本地化或翻译 ...

  7. Mac OS X 快捷键(完整篇) 转载

    转载自:http://www.nooidea.com/2011/01/mac-os-x-keyboard-shortcuts.html 快捷键是通过按下键盘上的组合键来调用 Mac OS X 功能的一 ...

  8. Interface Comparator

    int compare(T o1, T o2) Compares its two arguments for order. Returns a negative integer, zero, or a ...

  9. SNAT

    http://blog.chinaunix.net/uid-2628744-id-2454879.html

  10. 架构探险——从零开始写Java Web框架》第二章照作

    沉下来慢慢看实现了. 越来越觉得可以和DJANGO作对比. package org.smart4j.chapter2.model; /** * Created by sahara on 2016/3/ ...