MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
ikaros
V2EX  ›  MySQL

遍历多个表名的问题

  •  
  •   ikaros · Apr 21, 2015 · 3123 views
    This topic created in 4059 days ago, the information mentioned may be changed or developed.

    cursor.execute("""select column_name, data_type, data_length, nullable from user_tab_columns where table_name=('%s')""", tab_name)

    一直提示ORA-01036错误,数据库是Oracle,原因好像是%s旁边的两个引号? 这种情况要怎样把表名传进去呢?

    7 replies    2015-04-21 17:23:14 +08:00
    ikaros
        1
    ikaros  
    OP
       Apr 21, 2015
    转义了 ' 也不行
    MasterYoda
        2
    MasterYoda  
       Apr 21, 2015   ❤️ 1
    % tab_name
    fxxkgw
        3
    fxxkgw  
       Apr 21, 2015   ❤️ 1
    name=(%s) 而且也不需要加这么多""" """ ,直接用" "就可以了吧
    是用MySQLdb么?
    ikaros
        4
    ikaros  
    OP
       Apr 21, 2015
    @MasterYoda 这个我试过,invalid syntax = =


    @fxxkgw Oracle,%s两边那两个单引号好像是必需的,直接用一个具体的表名是可以查到表结构的 ...
    fxxkgw
        5
    fxxkgw  
       Apr 21, 2015
    @ikaros oracle没用过,只用过mysql,你tab_name是元组么?
    ikaros
        6
    ikaros  
    OP
       Apr 21, 2015
    @fxxkgw
    @MasterYoda 我错了,Oraclel里面的占位符不是%s Oracle里面是:1 :2这样的
    ikaros
        7
    ikaros  
    OP
       Apr 21, 2015
    @fxxkgw
    嗯 改成这样就好了
    cursor.execute("""select column_name, data_type, data_length, nullable from user_tab_columns where table_name=:1""", (tab_names[index],))
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   991 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 5414617a · 51ms · UTC 22:15 · PVG 06:15 · LAX 15:15 · JFK 18:15
    ♥ Do have faith in what you're doing.