sql语句:
select 'insert into temp values ('||hostname|| ','||'百度'||')' from url_templet sql拼接,结果就是
insert into temp values (www.52yeyou.com,百度)
insert into temp values (game4.191pk.com,百度)
insert into temp values (88.198game.net,百度)
insert into temp values (www.xxp001.com,百度)
insert into temp values (vda.uuzu.com,百度)
insert into temp values (game.luokelai.com.cn,百度)
insert into temp values (act.woniu.com,百度)
insert into temp values (bto.youxiya.com,百度)
要怎么执行这些语句,只能用sql执行,不能导数据执行oraclesql执行sql

解决方案 »

  1.   

    用匿名代码块吧
    declare
    var_hostname varchar2(64);
    cursor cur_hostname is
    select hostname from url_templete;
    begin
    var_hostname := '';
    for cur in var_hostname loop
     insert into temp values (cur.hostname|| ','||'百度');
    end loop;
    commit;
    end;
      

  2.   

    我突然想起来,这个用一个SQL就能完成了
    INSERT INTO temp(hostname) SELECT hostname||','||'百度' FROM url_templete;
      

  3.   


    我也知道这个sql.老大说不可以呀
      

  4.   

    按如下模式写,已测试通过。
    SQL> create table url_templet(hostname varchar2(100));
     
    Table created
    SQL> insert into url_templet values('www.52yeyou.com');
     
    1 row inserted
    SQL> insert into url_templet values('game4.191pk.com');
     
    1 row inserted
    SQL> insert into url_templet values('88.198game.net');
     
    1 row inserted
    SQL> insert into url_templet values('www.xxp001.com');
     
    1 row inserted
    SQL> insert into url_templet values('vda.uuzu.com');
     
    1 row inserted
    SQL> insert into url_templet values('game.luokelai.com.cn');
     
    1 row inserted
    SQL> insert into url_templet values('act.woniu.com');
     
    1 row inserted
    SQL> insert into url_templet values('bto.youxiya.com');
     
    1 row inserted
    SQL> select 'insert into temp values ('''||hostname|| ''',百度)' from url_templet;
     
    'INSERTINTOTEMPVALUES('''||HOS
    --------------------------------------------------------------------------------
    insert into temp values ('www.52yeyou.com',百度)
    insert into temp values ('game4.191pk.com',百度)
    insert into temp values ('88.198game.net',百度)
    insert into temp values ('www.xxp001.com',百度)
    insert into temp values ('vda.uuzu.com',百度)
    insert into temp values ('game.luokelai.com.cn',百度)
    insert into temp values ('act.woniu.com',百度)
    insert into temp values ('bto.youxiya.com',百度)
      

  5.   

    SQL> select 'insert into temp values ('''||hostname|| ''',''百度'')' from url_templet;
     
    'INSERTINTOTEMPVALUES('''||HOS
    --------------------------------------------------------------------------------
    insert into temp values ('www.52yeyou.com','百度')
    insert into temp values ('game4.191pk.com','百度')
    insert into temp values ('88.198game.net','百度')
    insert into temp values ('www.xxp001.com','百度')
    insert into temp values ('vda.uuzu.com','百度')
    insert into temp values ('game.luokelai.com.cn','百度')
    insert into temp values ('act.woniu.com','百度')
    insert into temp values ('bto.youxiya.com','百度')
     
    8 rows selected
     
    SQL> 
      

  6.   

    写错了,把那个var_hostname 改成cur_hostname
      

  7.   

    写错了,把那个var_hostname 改成cur_hostnamedeclare
    var_hostname varchar2(64);
    cursor cur_hostname is
    select username from temp;
    begin
    var_hostname := '';
    for cur in cur_hostname loop
     insert into white_url_info values (WHITE_GROUP_ID.NEXTVAL,''||cur.username||'',1,'百度2',1,sysdate,'',0,'','');
    end loop;
    commit;
    end;
    我想把其中的‘百度2’ 换成一个变量该怎么改?
      

  8.   

    写错了,把那个var_hostname 改成cur_hostnamedeclare
    var_hostname varchar2(64);
    cursor cur_hostname is
    select username from temp;
    begin
    var_hostname := '';
    for cur in cur_hostname loop
     insert into white_url_info values (WHITE_GROUP_ID.NEXTVAL,''||cur.username||'',1,'百度2',1,sysdate,'',0,'','');
    end loop;
    commit;
    end;
    我想把其中的‘百度2’ 换成一个变量该怎么改?
    那个var_hostname是一个变量,你可以通过:=给它赋值,也可以通过 select colum into var_hostname from....赋值。如果还需要其他类型的参数,自己定义就行了