http://topic.csdn.net/u/20110117/16/13a97708-5e8a-4abc-a713-4ee1a13907c0.html
这是上一个帖子,csdners只是把T-SQL中的语句转化成PL-SQL中,但是输出结果不如意,都是输出一条string。T-SQL中的语句
DECLARE @DEPTCODE  CHAR(20)
DECLARE @DEPTNAME  NVARCHAR(30)
DECLARE @STOPFLAG  BIT
SELECT @DEPTCODE=DEPTCODE,@DEPTNAME=DEPTNAME,
  @STOPFLAG= STOPFLAG
 FROM PUB_DEPARTMENT
 WHERE DEPTCODE='062103' 
AND XSFLAG=1
IF @DEPTCODE IS NULL
 RAISERROR('此部门不存在!',16,1)
ELSE
 BEGIN
        IF @STOPFLAG=0
  SELECT @DEPTCODE AS DEPTCODE,@DEPTNAME AS DEPTNAME,1 AS STOPFLAG
 ELSE
  RAISERROR('此部门已停用!',16,1)
 END怎么转化PL-SQL后,输出结果也类似T-SQL中的那样列名  DEPTCODE    DEPTNAME    STOPFLAG
值:   062103       中国         0

解决方案 »

  1.   

    --你想要什么啊,之前他们给你写的就是那样做的
    declare 
      v_deptcode  varchar(20);
      v_deptname  nvarchar(30);
      v_stopflag  number;
    begin
         select deptcode,deptname,stopflag into v_deptcode,v_deptname,v_stopflag from pub_department
         where deptcode='062103' and xsflag=1;
         if v_stopflag=0 then
            dbms_output.put_line('此部门已停用!');
         end if;
    exception
      when no_data_found then
           dbms_output.put_line('此部门不存在!');
    end;--我们只是在PLSQL中给你按照写了下,至于你应用面是什么,要看你具体的应用了
      

  2.   

    --写死的方法
    declare
    v_deptcode pub_department.deptcode%type;
    v_deptname pub_department.deptname%type;
    v_stopflag pub_department.stopflag%type;
    begin
    select deptcode,deptname,stopflag
    into v_deptcode,v_deptname,v_stopflag 
    from pub_department
    where deptcode='062103' 
    and xsflag=1;
    if stopflag=0 then
    dbms_output.put_line(rpad('DEPTCODE',20,' ')||rpad('DEPTNAME',10,' ')||'STOPFLAG');
    dbms_output.put_line(rpad(v_deptcode,20,' ')||rpad(v_deptname,10,' ')||1);
    else dbms_output.put_line('此部门已停用!');
    end if;
    exception 
    when no_data_found then
    dbms_output.put_line('此部门不存在!');
    when others then
    dbms_output.put_line('查询出错!');
    end;
    --先创建一个表 把结果放到表里
    --然后查询这个表
    create table t_test(
    deptcode number,
    deptname varchar2(20),
    stopflag char(1))declare
    v_deptcode pub_department.deptcode%type;
    v_deptname pub_department.deptname%type;
    v_stopflag pub_department.stopflag%type;
    begin
    select deptcode,deptname,stopflag
    into v_deptcode,v_deptname,v_stopflag 
    from pub_department
    where deptcode='062103' 
    and xsflag=1;
    if stopflag=0 then
    execute immediate 'truncate table t_test';
    insert into t_test values(v_deptcode,v_deptname,'1');
    else dbms_output.put_line('此部门已停用!');
    end if;
    exception 
    when no_data_found then
    dbms_output.put_line('此部门不存在!');
    when others then
    dbms_output.put_line('查询出错!');
    end;
    /
      

  3.   

    返回游标吧,或者返回TABLE集
    然后再SELECT 
      

  4.   

    不好意思,对oracle相当菜就是想要类似这样的返回结果
    http://topic.csdn.net/u/20110119/09/ba37162c-7f62-486a-9523-9681968eb358.html?51752就是有列名和行值。
      

  5.   

    现在的问题是这样的 this.mySqlDataAdapter = new OracleDataAdapter(cmdText, this.myConnection);
                                this.mySqlDataAdapter.Fill(this.OutDataSet, strTableName);cmdText就是顶上sql转化后的PLSQL,数据库已经连接上,还有能查出仅有的一条数据,但是this.OutDataSet中确没有Table