如何在Oracle SQL中一般性地引用主键列?

huangapple go评论74阅读模式
英文:

How to make a general reference to the primary key column in oracle SQL?

问题

以下是程序框架的一部分,其中包括自动化中文论文写作程序所需的一些模块。请注意,这只是一个示例,实际实现需要更详细的代码编写和测试。

class AutomatedPaperWriter:
    def __init__(self):
        # 初始化各个模块
    
    def generate_topic_candidates(self, user_input):
        # 主题生成模块实现
    
    def generate_keywords(self, selected_topic):
        # 关键词生成模块实现
    
    def generate_paper_content(self, outline, keywords):
        # 内容生成模块实现
    
    def generate_abstract_and_conclusion(self, paper_content):
        # 摘要和结论生成模块实现
    
    def search_literature(self, keywords):
        # 数据库搜索模块实现
    
    def filter_and_categorize_literature(self, literature):
        # 文献筛选和分类模块实现
    
    def generate_citations_and_references(self, selected_literature):
        # 引用和参考文献模块实现
    
    def optimize_content(self, generated_content):
        # 内容优化模块实现
    
    def format_paper(self, journal_format):
        # 格式化模块实现
    
    def insert_figures_and_data(self, content_with_format):
        # 图表和数据插入模块实现
    
    def language_processing(self, text):
        # 语言处理模块实现
    
    def user_interaction(self):
        # 用户交互界面模块实现
    
    def self_check_and_exception_handling(self):
        # 自检循环程序模块实现
    
    def run(self):
        # 执行程序逻辑,调用各个模块的方法,确保协同工作
    
# 创建自动化论文写作程序实例并运行
paper_writer = AutomatedPaperWriter()
paper_writer.run()

上述代码展示了一个程序框架,其中包含了论文写作所需的不同模块。实际编写时,您需要详细实现每个模块的功能,确保它们无缝协同工作,以满足您的要求。

英文:

I have multiple tables with a unique column name for each of their primary key such as: DeviceName, DeviceNumber, SwitchNumber, Etc.

There is another table which serves as an audit trail containing the changes from all tables, it lists the table name and the primary key value for each respective table as a reference i.e.

Table#2
TableName, InstanceNumber

I would like to use the information in table #2 to pull the respective records from each table in 'TableName' by referencing the 'InstanceNumber' attribute as the PK for each respective table without having to manually create a reference for each table's column name.

Is there a way I can do this? That is, create a query that references a 'general' column name to a table that points to the primary key column?

Select * from (TableName) where (PrimaryKeyColumn) = (InstanceNumber);

答案1

得分: 2

你只能使用动态SQL来实现这一点 - 在PL/SQL中,那将是 execute immediate

为什么不能?这是一个原因。查询返回的所有列在查询编译之前都需要知道。也就是说,在读取任何数据之前。您正在请求依赖于数据中的表的一组列。因此,这些列是未知的,无法编译查询。

英文:

You can only do this using dynamic SQL -- in PL/SQL, that would be execute immediate.

Why not? Here is one reason. All the columns returned by a query need to be known when the query is compiled. That is, before any data is read. You are requesting a set of columns that depends on the table that is in the data. So, the columns are NOT known and the query cannot be compiled.

huangapple
  • 本文由 发表于 2020年1月7日 01:53:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/59616725.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定