oracle的select utc.column_name,hdw.questionid from user_tab_columns utc,question hdw where table_name = 'QUESTION' and hdw.questionid = 100925这样查出来是两列,一列是question表的字段,一列是id(100925),一样的。
我现在想一列是question表的字段,一列是对应字段再question表中的值。请问这个如何实现,谢谢!
我现在想一列是question表的字段,一列是对应字段再question表中的值。请问这个如何实现,谢谢!
解决方案 »
- 新手求助:VC中读取Oracle数据库的值
- 求救。。。。11g 和 jdk问题
- SQL*Loader-500:
- oracle函数返回数据集的效果,怎么用存储过程来实现?先谢谢啦!
- Oralce中取得某时间段内每季度、每月、每星期规定天数的日期
- 当参数数null的时候,to_date和to_char的时候会报错误
- ORACLEserviceSID可以启动但是ORACLE监听程序无法启动
- SQL
- oracle的备注字段是什么?是VARCHAR2吗?
- 怎样不修改程序,只需在Oracle8i中修改配置就可以使在查询语句中不区分大小写
- 请教在sql语句执行时,如何跳过错误,继续执行
- SQLPLUS登录的问题
假定question表为:
----------------------
columnt_namequetionid
name
content
answer
---------------------
现在我想实现如下显示:
----------------------
column_name valuequetionid 100925
name Q1
content is this a question?
answer yes!
---------------------
type cur is ref cursor;
c_emp cur;
cn varchar2(100);
sqlstr varchar2(1000);
Ftable_name varchar2(100);
begin
sqlstr:='';
Ftable_name:='bm';--table name
open c_emp for select COLUMN_Name from user_tab_columns where table_name=upper(Ftable_name);
loop
fetch c_emp into cn;
exit when c_emp%notfound;
sqlstr:=sqlstr||' select '''||cn||''' as columnname,'||cn||' as columnvalue from bm union all';
end loop;
sqlstr:=substr(sqlstr,0,length(sqlstr)-10);
--sqlstr:=sqlstr+' where id=100925';//查询条件
dbms_output.put_line( sqlstr );
--查询结果sql
close c_emp;
end;
type cur is ref cursor;
c_emp cur;
cn varchar2(100);
sqlstr varchar2(1000);
Ftable_name varchar2(100);
begin
sqlstr:='';
Ftable_name:='question';--table name
open c_emp for select COLUMN_Name from user_tab_columns where table_name=upper(Ftable_name);
loop
fetch c_emp into cn;
exit when c_emp%notfound;
sqlstr:=sqlstr||' select '''||cn||''' c1,'||cn||' c2 from '||Ftable_name||' union all';
end loop;
sqlstr:=substr(sqlstr,0,length(sqlstr)-10);
dbms_output.put_line( sqlstr );
--查询结果sql
close c_emp;
end;
///查询结果sql select 'QUETIONID' c1,QUETIONID c2 from question union all select 'NAME' c1,NAME c2 from question union all select 'CONTENT' c1,CONTENT c2 from question union all select 'ANSWER' c1,ANSWER c2 from question///
QUETIONID 1
NAME Q1
CONTENT is this a question?
ANSWER yes!