根据条件插入多行

时间:2018-10-25 19:01:21

标签: sql oracle

我试图插入多行,每行具有相同的environment_id,但是,它具有不同的property_id。类似于以下内容:

INSERT INTO appserver_prop (environment_id, property_id)
VALUES (497, select property_id from prop_info where property_name like '%CPNIB%')

2 个答案:

答案 0 :(得分:3)

只需使用:

# define a translation table for the renaming schema
rename_dict = {
    ' (1)': '_5m',
    ' (2)': '_15m',
    ' (3)': '_1h',
    ' (4)': '_4h',
    ' (5)': '_1D',
    ' (6)': '_1W',
    ' (7)': '_1N',
}

for file in os.listdir(final_directory):
        fullpath = os.path.join(final_directory,file)
        #print(file)
        if "(" not in file:
            os.rename(fullpath, os.path.join(final_directory, file.replace('.csv', '_1m.csv')))
        else
            cond = os.path.splitext(file)[0][-4]
            file.replace(cond, rename_dict.get(cond))
            os.rename(fullpath, os.path.join(final_directory, file)

您不需要insert into appserver_prop(environment_id, property_id) select 497, property_id from prop_info where property_name like '%CPNIB%' 子句,因为您不是要在SQL中插入单个记录,而是在多个记录集中插入。

答案 1 :(得分:2)

我认为您想要for element_in_file1, element un file1 in zip(open(file1), open(file2)): #extract logic in function

insert . . . select