“ Teradata SHOW TABLE <数据名>。<表名>;-第一行在点(。)处分割”

时间:2019-09-07 18:10:35

标签: python sql python-3.x stored-procedures teradata

当我尝试在Teradata中查询"SHOW PROCEDURE [<db-name>.]<stored-procedure-name> ;"时,该过程的第一行在点处拆分。当我在Teradata环境中运行相同的查询时,我得到的像是:

  

替换过程。(在P_AS_OF_DATE DATE)SQL安全调用程序

但是使用以下代码,它显示:

Row 1: [REPLACE PROCEDURE  <database>.]
Row 2: [<procnamae>]

SHOW TABLE <databaseanme>.<tablename>可以正常工作,但不能用于存储过程。

我希望对此有所帮助。预先谢谢你。

db = str(input('Enter Database Name: '))
table = str(input('Enter Table Name: '))

udaExec = teradata.UdaExec (appName='test', version='1.0',logConsole=False)
with udaExec.connect(method='odbc', system='xyz', Authentication='LDAP', username='user', password='password', driver='Teradata Database ODBC Driver 16.20') as session:
    getinput = input('TABLE(T) desc or PROC desc(P) : ')

    if getinput.upper() == 'T' :
        rows = session.execute("SHOW TABLE " + db +"."+table+";")

        whand = open(table+'.sql','w')
        for row in rows:
            for line in re.split('\r\n|\n\r|\n|\r', row[0]):
                lines+=line+'\n'
        print(lines)
        whand.write(lines)
        whand.close()

先前的代码可用于show table

if getinput.upper() == 'P' :
    spname = db +'.Sp'+table+';'
    whand = open('Sp'+table+'.sql','w')

    rows = session.execute('SHOW PROCEDURE '+  spname +';').fetchall()
    for row in rows:
        print(row)
  • 我正在尝试看到类似
    • REPLACE PROCEDURE <database>.<procname>(IN P_AS_OF_DATE DATE) SQL SECURITY INVOKER
  • 但是它正在打印Row 1: [REPLACE PROCEDURE <tablename>.]
            # continued from previous code cell
            for line in row: 
                print(row)
                lines+=line+'\n'
        whand.write(lines)
        whand.close()

实际结果:

    [<teradata.util.Row object at 0x0000029462664048>,
    <teradata.util.Row object at 0x0000029462664080>,
    <teradata.util.Row object at 0x00000294626640B8>,
    <teradata.util.Row object at 0x00000294626640F0>,
    <teradata.util.Row object at 0x0000029462664128>]

    Row 1: [REPLACE PROCEDURE  <DatabaseName>.]
    Row 1: [REPLACE PROCEDURE  <DatabaseName>.]
    Row 2: [<TableName>]
    Row 2: [<TableName>]
    #                                               001              2000-01-01                     xyz             Initial version of the proc
    #                                               002              2000-01-23                     abc             Changes as per the new DimAcct 

期望看到:

  • Row 1:[REPLACE PROCEDURE <database>.<procname>(IN P_AS_OF_DATE DATE) SQL SECURITY INVOKER]

0 个答案:

没有答案