我在列上有两个不同维度的表

时间:2015-08-06 06:14:38

标签: sql oracle

我在一列上有两个不同维度的表格,如下所示:

create procedure TakeSysname
    @Sysname sysname
as
    --does nothing;
go

--This works.
exec TakeSysname JohnDoe;
print N'Worked';
go

--This works.
exec TakeSysname 'John.Doe';
print N'Worked'
go

--This does not.
exec TakeSysname John.Doe;
print N'Worked';
go

在我要插入的表格中

name varchar2(256 char)

当我编译下一个代码时:

lastname varchar2(50 byte)

我有下一个错误:

INSERT INTO TCPD_PERSONEL_COPY
            ( FIRSTNAME,LASTNAME, EMAIL1) 
SELECT NAME,GIVEN_NAME, MAIL

FROM   glob 
WHERE  ( NOT EXISTS (SELECT EMAIL1 
                     FROM   tlp 
                     WHERE  GLOB.mail = TLP.email1 ) 
         AND GLOB.mail IS NOT NULL ) 
        OR ( NOT EXISTS (SELECT userid
                         FROM   TLP 
                         WHERE GLOB.LOGIN = TLP.userid ) 
             AND GLOB.mail IS NULL )
  AND GLOB.COUNTRY='France'; 

我的问题是:如果我没有使用ALTER修改列结构的权限,请记住这个事实,我怎么能这样插入呢。

1 个答案:

答案 0 :(得分:0)

嗯,显然你不能在50个字符的字段中插入256个字符。如果您无法更改表并愿意承担数据丢失,则可以使用substr截断列的值:

INSERT INTO TCPD_PERSONEL_COPY
            ( FIRSTNAME,LASTNAME, DEPARTMENT, TELEPHONE1, EMAIL1, USERID, DATECREATED) 
SELECT SUBSTR(NAME, 1, 50), GIVEN_NAME, DEPARTMENT, PHONE, MAIL, LOGIN, SYSDATE 
FROM   gal 
WHERE  ( NOT EXISTS (SELECT EMAIL1 
                     FROM   TCPD_PERSONEL_COPY 
                     WHERE  GAL.mail = TCPD_PERSONEL_COPY.email1 ) 
         AND GAL.mail IS NOT NULL ) 
        OR ( NOT EXISTS (SELECT userid
                         FROM   TCPD_PERSONEL_COPY 
                         WHERE  gAL.LOGIN = TCPD_PERSONEL_COPY.userid ) 
             AND GAL.mail IS NULL )
  AND GAL.COUNTRY='France';