HIVE SQL中引用参数的使用

在一些脚本中,参数的使用可以使得语句更加灵活,易于维护和修改。

场景一:
step1:定义参数

set hivevar:col_name=amt;

step2:在SQL语句中引用参数

select ${
    
    hivevar:col_name} from table_name;

场景二:
step1:定义参数

set hivevar:report_year=2023;

step2:在SQL语句中引用参数

select * from table_name
where report_year=${
    
    hivevar:report_year};

场景三:
step1:定义参数

set hivevar:tb_name=amt;

step2:在SQL语句中引用参数

drop table if exists db_name.test_${
    
    hivevar:tb_name};
create table db_name.test_${
    
    hivevar:tb_name} as
select ${
    
    hivevar:tb_name} from table_name;

;

猜你喜欢

转载自blog.csdn.net/p1306252/article/details/131766787