在不知道一个表的主健的情况下,如何从这个表里取得主健的值?请大家帮帮忙。需要用plsql。取得表的主健代码如下:select column_name
from user_cons_columns
where table_name = ''
and position is not null但是不知道主建的值怎么取得?table
from user_cons_columns
where table_name = ''
and position is not null但是不知道主建的值怎么取得?table
('SELECT (SELECT column_name
FROM user_cons_columns
WHERE table_name = ** *
AND position IS NOT NULL)
FROM ** *')
我这是在plsql中取得一个表的结果集,然后循环读取每一条记录,判断其中的列A(非主键)是否有错,
如果有错,需要出log,log中需要出这条记录中主键的内容。目前在出主键值得地方困扰住了。我的思路是检索出主键名然后与游标拼接起来出力,以为能够得到值,可惜不然,出力的只有游标.主键名,出不来主键的值。
检索出主键字段;
拼接一个'select 主键 from 表'的字符串
open 游标 for 字符串循环执行你要做的操作。
至于值取不出来,应该是结果集里没包含或者参数不对吧。
另外,我对你的sql改了下,只获取主键的信息,不过联合主键需要通过position来再次循环了。
select ucc.* from user_cons_columns ucc,user_constraints uc
where ucc.owner=uc.owner
and ucc.constraint_name=uc.constraint_name
and uc.constraint_type='P'
user_cons_columns 里面还有 owner?
没问题啊
SQL> desc user_cons_columns;
Name Type Nullable Default Comments
--------------- -------------- -------- ------- ------------------------------------------------------------------------------------------------
OWNER VARCHAR2(30) Owner of the constraint definition
CONSTRAINT_NAME VARCHAR2(30) Name associated with the constraint definition
TABLE_NAME VARCHAR2(30) Name associated with table with constraint definition
COLUMN_NAME VARCHAR2(4000) Y Name associated with column or attribute of object column specified in the constraint definition
POSITION NUMBER Y Original position of column or attribute in definition
SQL>
现在是拼接出来一直是个串儿,读不出来值,不知道大家是否能帮助一下。